A example with cursor procedure with EXCEPTION HANDLING of ER_INTO_VARIABLES_NO_ROWS

Can we get a example with cursor procedure with EXCEPTION:
qry QUERY(id_curs text)=select distinct EMP_ID from EMP_DETAILS;
BEGIN
EXCEPTION
WHEN ER_INTO_VARIABLES_NO_ROWS THEN in cursor procedure.
Because i am unable to write in singlestore and its throwing unhandled errors.
please help me to get this.

CREATE TABLE EMP_DETAILS (
EMP_ID int
);

// This will catch the error when it is thrown as a result of a select into with no rows found.
// But this is not a cursor if that’s specifically what you needed.
delimiter //
create or replace procedure find_emp(id int)
returns void as
declare qry int;
begin
begin
select EMP_ID into qry from EMP_DETAILS where EMP_ID = id;
exception
when ER_INTO_VARIABLES_NO_ROWS then
echo select ‘No rows found’;
end;

end //
delimiter ;

// Try this as you may not need to catch the error and it may manage it more gracefully.
// This is more in line with the cursor example.
delimiter //
create or replace procedure find_emp()
returns void as
declare qry QUERY(id INT) = select distinct EMP_ID from EMP_DETAILS; arr ARRAY(RECORD(id INT));_id INT;
begin
begin
arr = COLLECT(qry);
FOR x in arr LOOP
_id = x.id;
echo select ‘in the loop’;
END LOOP;
end;

end //
delimiter ;

1 Like