Advertisement
Guest User

Untitled

a guest
Dec 13th, 2019
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.04 KB | None | 0 0
  1. DELIMITER $$
  2. CREATE DEFINER=`root`@`localhost` PROCEDURE `kurzorZkroz`(
  3. OUT izlaz VARCHAR(100)
  4. )
  5. BEGIN
  6. DECLARE a varchar(50);
  7. DECLARE b varchar(5);
  8. DECLARE maxA varchar(50);
  9. DECLARE maxU int default 0;
  10. DECLARE u int default 0;
  11. DECLARE e int default 0;
  12. DECLARE c cursor for SELECT country.Code,country.Name from country;
  13. DECLARE continue handler for not found set e = 1;
  14. BLOCK1: begin
  15. DECLARE broj int;
  16. OPEN c;
  17. REPEAT
  18. SET u = 0;
  19. fetch c into b,a;
  20. BLOCK2: begin
  21. DECLARE pop int;
  22. DECLARE ee int default 0;
  23. DECLARE k cursor for SELECT city.Population from city WHERE CountryCode = b;
  24. DECLARE continue handler for not found set ee = 1;
  25. OPEN k;
  26. REPEAT
  27. fetch k into pop;
  28. SET u = u + pop;
  29. UNTIL ee END REPEAT;
  30. END BLOCK2;
  31. IF(u > maxU) THEN
  32. SET maxA = a;
  33. SET maxU = u;
  34. END IF;
  35. UNTIL e END REPEAT;
  36. END BLOCK1;
  37. CLOSE c;
  38. SELECT maxA as Drzava,maxU as Populacija;
  39. SET izlaz = CONCAT(maxA,' - ',maxU);
  40. END$$
  41. DELIMITER ;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement