Advertisement
Guest User

Untitled

a guest
Sep 19th, 2019
123
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.36 KB | None | 0 0
  1. # haha WHILE ... END WHILE haha
  2. # haha REPEAT ... END REPEAT haha
  3. # haha LOOP ... END LOOP haha
  4.  
  5. # 1) Vypocitajte sucet prvych N prirodzenych cisel (napr. N=100)
  6. create database if not exists dbmaz;
  7. use dbmaz;
  8. drop procedure if exists sucetWHILE;
  9. delimiter #
  10. create procedure sucetWHILE(n int)
  11. begin
  12. declare i int;
  13. declare s int;
  14. set i=0;
  15. set s=0;
  16. haha: while i<n do
  17. SET i=i+1;
  18. SEt s=s+i;
  19. END while haha;
  20. SELECT i, s;
  21. END;
  22. #
  23. CALL sucetWHILE(100);
  24.  
  25.  
  26.  
  27. # 2) Od 1 po N vypiste iba neparne cisla!
  28.  
  29. drop procedure if exists neparneSLEEP;
  30.  
  31. delimiter #
  32.  
  33. create procedure neparneSLEEP(n int)
  34.  
  35. BEGIN
  36.  
  37. declare i int;
  38.  
  39. set i=0;
  40.  
  41. haha: LOOP
  42.  
  43. SET i=i+1;
  44.  
  45. IF mod(i,2)=1 THEN
  46.  
  47. SELECT CONCAT(i,'je neparne')ii, SLEEP(1);
  48.  
  49. END IF;
  50.  
  51. IF i=n then LEAVE haha;
  52.  
  53. END IF;
  54.  
  55. END LOOP haha;
  56.  
  57. END;
  58.  
  59. #
  60.  
  61. CALL neparneSLEEP(10);
  62.  
  63.  
  64. drop procedure if exists neparneSleep2;
  65.  
  66. delimiter #
  67.  
  68. create procedure neparneSleep2(n int)
  69. begin
  70.  
  71. declare i int;
  72.  
  73. set i=0;
  74.  
  75. haha: LOOP
  76.  
  77. SET i=i+1;
  78.  
  79. IF i=n then LEAVE haha;
  80.  
  81. ELSEIF mod(i,2)=1 THEN
  82.  
  83. SELECT CONCAT(i,'je neparne') ii, SLEEP(1);
  84.  
  85. END IF;
  86.  
  87. END LOOP haha;
  88.  
  89. END;
  90.  
  91. #
  92.  
  93. CALL neparneSleep2(10);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement