Results 1 to 2 of 2
  1. #1
    Join Date
    Nov 2016
    Posts
    5

    Unanswered: DB2 9.1 on z/OS how to declare local variables in user-defined function

    Hi export
    Can anybody help me how to declare a local variable in UDF. I have typed the requirement as a template
    Code:
    CREATE FUNCTION MYFUN(P_I INTEGER)
      RETURNS INTEGER
      LANGUAGE SQL
      RETURN P_1 +1;
    This function works fine.

    But if i added a local variable as
    Code:
    CREATE FUNCTION MYFUN(P_I INTEGER)
      RETURNS INTEGER
      LANGUAGE SQL
      BEGIN
        DECLARE V_RET INTEGER;
    
        SET V_RET = P_I + 1;
        RETURN V_RET;
      END
    This time, it does not work, it report error:
    SQL0199N The use of the reserved word "BEGIN" following "" is not valid.
    Expected tokens may include: "<END-OF-STATEMENT> SPECIFIC FENCED RETURN
    SOURCE PARAMETER". SQLSTATE=42601
    Thanks.

  2. #2
    Join Date
    Jul 2016
    Location
    Germany
    Posts
    32
    Provided Answers: 2

    sentimental journey

    Hi hihui,

    the problem seems to be the begin clause in ZOS, please read this:

    https://groups.google.com/forum/#!to...b2/D9Dk65f1cgY


    Good luck
    db2dp

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •