How to declare timestamp variable with default as current timestamp not working.

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • somadritadas23
    New Member
    • Aug 2010
    • 2

    How to declare timestamp variable with default as current timestamp not working.

    I have a variable declaration inside a procedure which is not compiling in db2 9.5 :-
    DECLARE VSTARTTIME TIMESTAMP DEFAULT CURRENT TIMESTAMP;

    The procedure is a test procedure :-
    DROP PROCEDURE ABC_1
    @
    CREATE PROCEDURE ABC_1
    (
    INOUT STARTTIME TIMESTAMP ,
    INOUT ENDTIME TIMESTAMP ,
    OUT DIFFTIME DECIMAL(15,10)
    )
    LANGUAGE SQL
    BEGIN
    DECLARE VSTARTTIME TIMESTAMP DEFAULT CURRENT TIMESTAMP;
    BEGIN
    SET STARTTIME = VSTARTTIME ;
    VALUES CURRENT TIMESTAMP INTO ENDTIME;
    VALUES ENDTIME-STARTTIME INTO DIFFTIME;
    END;

    END
    @

    COMPILATION ERROR --
    SQL0104N An unexpected token "CURRENT TIMESTAMP" was found following "ME
    TIMESTAMP DEFAULT". Expected tokens may include: "<literal>" . LINE
    NUMBER=9. SQLSTATE=42601

    Please suggest why this is not working?
  • Anand Kaushal
    New Member
    • Oct 2010
    • 6

    #2
    Cannot specify a default like that.. set the variables instead.

    Comment

    Working...