Dyanamic Sequence name in User defined SQL function

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • petemcg
    New Member
    • Jan 2008
    • 1

    #1

    Dyanamic Sequence name in User defined SQL function

    I am trying to create a wrapper function to allow me to get the next value for any sequence

    I would like to pass a sequence name into the function, and return the next value.

    It looks like DB2 does not allow use of NEXT VALUE FOR syntax in a CREATE FUNCTION statement, even for a hardcoded sequence name (job log message indicates this)

    The CREATE statement fails with an error complaining about the syntax.

    Substituting hardcoded return values for the NEXT VALUE for statement allow the function to be created.

    What alternate approach would people recommend? Create a Procedure? Other?

    Am on V5R3M0

    I have been trying
    Code:
     CREATE FUNCTION GETSEQNO (seqname char(10)   )                   
     RETURNS DECIMAL(13,0)                                            
     LANGUAGE SQL                                                     
     SPECIFIC GETSEQNO1                                               
     func1_lab:                                                       
       BEGIN                                                          
       DECLARE seqno1 DECIMAL(13,0);                                  
       SET seqno1 =  decimal(next value for         seqname,13,0)  ;                                         
         RETURN seqno1 ;                                          
        END;
Working...