0

hello i am really a beginner in SQL, I want to test that by using a cursor in mysql, I tried to collect date in the database and then relay to two variables as @id and @borrower, but fails. Mysql always hint that there is error

CREATE PROCEDURE credit_facility()
delimiter &&
BEGIN
declare credit_id int;
declare credit_borrower varchar(200);
declare cur_credit for select id, borrower from credit_facility;
set @id=""
set @borrower=""
open cur_credit
repeat
    fetch cur_credit into credit_id, credit_borrower;
    set @id=@id+credit_id;
    set @borrower=@borrower+credit_borrower;
until 0 end repeat;
close cur_credit
end &&
delimiter;
call credit_facility()
select @id,@borrower;
END``

I try to write my first procedure with cursor, however it always run into problems. I tried to correct it in chatgpt but it did not work as well. there is a red line under delimiter in mysql so I guess there is the problem.

  • MySQL doesn't use `+` for concatenation, it's numeric addition. Use the `CONCAT()` function for concatenation. – Barmar Aug 11 '23 at 14:55

0 Answers0