Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- DELIMITER $$
- CREATE DEFINER=`root`@`localhost` PROCEDURE `kurzorZkroz`(
- OUT izlaz VARCHAR(100)
- )
- BEGIN
- DECLARE a varchar(50);
- DECLARE b varchar(5);
- DECLARE maxA varchar(50);
- DECLARE maxU int default 0;
- DECLARE u int default 0;
- DECLARE e int default 0;
- DECLARE c cursor for SELECT country.Code,country.Name from country;
- DECLARE continue handler for not found set e = 1;
- BLOCK1: begin
- DECLARE broj int;
- OPEN c;
- REPEAT
- SET u = 0;
- fetch c into b,a;
- BLOCK2: begin
- DECLARE pop int;
- DECLARE ee int default 0;
- DECLARE k cursor for SELECT city.Population from city WHERE CountryCode = b;
- DECLARE continue handler for not found set ee = 1;
- OPEN k;
- REPEAT
- fetch k into pop;
- SET u = u + pop;
- UNTIL ee END REPEAT;
- END BLOCK2;
- IF(u > maxU) THEN
- SET maxA = a;
- SET maxU = u;
- END IF;
- UNTIL e END REPEAT;
- END BLOCK1;
- CLOSE c;
- SELECT maxA as Drzava,maxU as Populacija;
- SET izlaz = CONCAT(maxA,' - ',maxU);
- END$$
- DELIMITER ;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement