I am trying to create a stored procedure in DB2 which uses a cursor. However, I am having issues with the correct syntax and recieve the error:
SQL0104N An unexpected token "=" was found following "N FOR SET v_party_id". Expected tokens may include: "JOIN". LINE NUMBER=12. SQLSTATE=42601
My procedure is as follows:
CREATE PROCEDURE Core.LWRH_LIST_CARRIER_EMAILS ( IN p_party_role_id BIGINT ) LANGUAGE SQL DYNAMIC RESULT SETS 1 BEGIN DECLARE v_party_id BIGINT; DECLARE c_result CURSOR WITH RETURN FOR SET v_party_id = (Select party_id from core.party_role where party_role_id = p_party_role_id); Select cm.contact_method_id, cm.contact_method_type_id, cm.electronic_address from core.party_contact_method pcm join core.contact_method cm on cm.contact_method_id = pcm.contact_method_id and cm.contact_method_type_id = 6 and pcm.party_id = v_party_id; OPEN c_result; [email protected]
Can anybody advise on what the correct syntax would be?