SHARE
TWEET

Untitled

a guest May 24th, 2019 60 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. # Практ 11 цикл loop
  2.  
  3.  
  4. drop procedure pract11;
  5. create procedure pract11()
  6. begin
  7.     declare i int default 0;
  8.     set @out = 0;
  9.     za: loop
  10.         select @out := @out + cost * amount from pract11 order by id limit i,1;
  11.         set i = i + 1;
  12.         if i > 2 then leave za; end if;
  13.     end loop za;
  14.     select @out;
  15. end;
  16.  
  17. call pract11()
  18.  
  19. # Практ 11 цикл while
  20.  
  21. drop procedure pract11;
  22. create procedure pract11()
  23. begin
  24.     declare i int default 0;
  25.     set @out = 0;
  26.     za: while i < 3 do
  27.         select @out := @out + cost * amount from pract11 order by id limit i,1;
  28.         set i = i + 1;
  29.     end while;
  30.     select @out;
  31. end;
  32.  
  33. call pract11()
  34.  
  35.  
  36. # Практ 11 цикл repeat
  37.  
  38. drop procedure pract11;
  39. create procedure pract11()
  40. begin
  41.     declare i int default 0;
  42.     set @out = 0;
  43.     repeat
  44.         select @out := @out + cost * amount from pract11 order by id limit i,1;
  45.         set i = i + 1;
  46.     until i > 2 end repeat;
  47.     select @out;
  48. end;
  49.  
  50. call pract11()
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top