Why is the Procedure not returning the result set?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • lranell

    Why is the Procedure not returning the result set?

    I am attempting to select the first 50 rows only of data and then update two columns and return the resultset of the rows that were updated to my calling application. The procedure below gets the rows and performs the update but does not return the resultset. Can someone explain to me what I am doing wrong that is causing the result set not to be returned?

    Code:
    CREATE PROCEDURE PROCESSVENDORPO 
    (in p_source varchar(50), in p_channel varchar(50), out p_rowcount integer)
    DYNAMIC RESULT SETS 1
    SPECIFIC PROCESSVENDORPO
    LANGUAGE SQL MODIFIES SQL DATA
    tr: begin
    DECLARE v_sqlstatus INTEGER DEFAULT 0;
    DECLARE v_counter INTEGER DEFAULT 0;
    DECLARE v_vendor_po_id integer;
    DECLARE v_orderid CHAR(30);
    
    DECLARE c1 CURSOR WITH RETURN FOR
    select vendor_po_id, orderid from vendor_po where source=p_source and channel=p_channel order by orderdate
    FETCH FIRST 50 ROWS ONLY;
    
    DECLARE CONTINUE HANDLER FOR NOT FOUND SET v_sqlstatus = -1;
    OPEN c1;
    
    loop_over_po:
    LOOP
    FETCH FROM c1 
    INTO v_vendor_po_id, v_orderid;
    IF v_sqlstatus = -1 THEN
    LEAVE loop_over_po;
    END IF;
    Update vendor_po set state='InProcess' where vendor_po_id = v_vendor_po_id;
    SET v_counter = v_counter + 1;
    END LOOP loop_over_po;
    SET p_rowcount = v_counter;
    
    end tr
Working...