You create a table and a stored procedure:
CREATE TABLE t1 (f1 int);
INSERT INTO t1 VALUES (1), (2) , (3), (4), (5);
CREATE PROCEDURE sum_t1()
BEGIN
DECLARE done INT DEFAULT 0;
DECLARE va1 INT;
DECLARE result CURSOR FOR SELECT f1 FROM t1;
DECLARE CONTINUE HANDLER FOR NOT FOUND SET done=1;
OPEN cur;
REPEAT
FETCH cur INTO va1;
IF NOT done THEN
SET result = result +va1;
END IF:
UNTIL done END REPEAT;
SELECT result;
END
CALL sum_t1();
What is the result of the CALL statement?
A.
The procedure completes, and 15 is returned
B.
The procedure’s IF condition is not satisfied, and 0 is returned.
C.
The procedure’s loop is not entered, and 1 is returned.
D.
An infinite loop will be running until the command is killed.
I tested the procedure and the syntax is not correct because cur is not defined
CORRECT IS A IF:
drop procedure if exists sum_t1;
delimiter $$
create procedure sum_t1()
begin
declare done int default 0;
declare va1 int;
declare result int default 0;
declare cur cursor for select f1 from t1;
declare continue handler for not found set done=1;
open cur;
repeat
fetch cur into va1;
if not done then
set result = result + va1;
end if;
until done end repeat;
select result;
end $$
delimiter ;
call sum_t1();
In this, I would say the question is wrong.
But the potential correct answer is A
A