1

DB2 Stored Procedure update record and select record

CREATE PROCEDURE DB2INST1.GETPEOPLE2(IN ids bigint )

    SPECIFIC DB2INST1.GETPEOPLE2

    DYNAMIC RESULT SETS 1

    MODIFIES SQL DATA

    LANGUAGE SQL 



    BEGIN 

        update test2 set a=a+1 where a>ids;

         DECLARE rs1 CURSOR WITH RETURN TO CLIENT FOR  

        select * from db2inst1.test2;

        OPEN rs1;
END  

but it's not working. error: DB21034E The command was processed as an SQL statement because it was not a valid Command Line Processor command. During SQL processing it returned: SQL0104N An unexpected token "rs1 CURSOR sele" was found following "ids; DECLARE". Expected tokens may include: "". LINE NUMBER=10. SQLSTATE=42601

3
  • 1
    Please specify what result you expect and what result you are getting. Commented Feb 3, 2016 at 8:37
  • 1
    Check the syntax of compound SQL in the manual. All DECLARE statements must precede any executable statements. Commented Feb 3, 2016 at 13:29
  • DB2 has SELECT FROM FINAL TABLE which will return the altered rows (if any) of an inner UPDATE or INSERT statement. An INCLUDE clause can also show the original values before updates. Commented Feb 4, 2016 at 15:36

1 Answer 1

1

ok,it work:

BEGIN 
        DECLARE rs1 CURSOR WITH RETURN TO CLIENT FOR  
            select * from db2inst1.test2;
        update test2 set a=a+1 where a>ids;
        OPEN rs1;
END 
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.