Stored Procedures for IBM DB2
I am new to stored procedures. Need to pick up some stored procedures for DB2(which I am also new to). The code I wrote is not working:
CREATE PROCEDURE sp_test ( id NUMBER ) BEGIN IF NUMBER < 0 THEN RAISE VALUE ERROR; END IF; SELECT * FROM student_tb WHERE taskid = 'NUMBER'; END; /
and this is the script (another file) which calls the stored procedure:
BEGIN sp_test('15'); END;
I am not sure what is wrong. Hope someone can advise. Thank you.
I'm not an expert in DB2, but I'm pretty sure you have to CALL stored procs in DB2.
execute (call sp_test('15'));
The syntax might be a little different for stored procedures that return a result set. Docs for DB2 on your target platform should explain the difference.