存储过程中的问题:db2

时间:2013-08-26 10:48:36

标签: db2

我在db2中编写了以下存储过程。

CREATE or REPLACE PROCEDURE RTIMD.IALERT_PROC ( IN usr_name VARCHAR(20) DEFAULT '', IN IN_RTIM_ID VARCHAR(25) default '', IN api_method VARCHAR(25) DEFAULT '', IN params VARCHAR(500) default '', IN application_name VARCHAR(20) default '', OUT TICKT_ID VARCHAR(20), OUT RTIMID_VAR VARCHAR(25))
LANGUAGE SQL
BEGIN

DECLARE RTIM_ID_OUT VARCHAR(25);

IF api_method = 'getIncident' THEN 
    SET TICKT_ID = EXECUTE IMMEDIATE ( 'SELECT DISTINCT TICKET_ID FROM RTIMD.V3_TICKET_LOG WHERE RTIM_ID = IN_RTIM_ID' );
    SET RTIM_ID_OUT = IN_RTIM_ID;
ELSEIF api_method = 'createIncident' THEN 
    SET RTIMID_VAR = EXECUTE IMMEDIATE ( "select 'RTIM_' concat usr_name concat varchar(bigint(days(current date) - days('1970-01-01'))*bigint(86400) + midnight_seconds(current_timestamp - current_timezone)) concat '_' concat varchar(SMALLINT ( RAND () *10000 + 1 )) from SYSIBM.SYSDUMMY1");
    SET RTIM_ID_OUT = RTIMID_VAR;
ELSEIF api_method = 'closeIncident' THEN 
    SET RTIM_ID_OUT = IN_RTIM_ID;
END IF;

INSERT INTO RTIMD.V3_TICKET_LOG( RTIM_ID, STATE, API_METHOD, API_MESSAGE, TICKET_TYPE, IMPACT_ROW_ID, TICKET_ID, PARAMS, REMOTE_USER, CREATED, UPDATED, DB_STATE, CPS_STATE, APPLICATION, PRB_OWNER, SN_INSTANCE ) VALUES ( RTIM_ID_OUT, 0, api_method, '', 'Incident', 0, '', params, usr_name, CURRENT TIMESTAMP, TIMESTAMP, 0, 0, application_name, 'self', '' );

END

执行存储过程时,我收到以下错误消息。

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 "IMMEDIATE" was found following "SET
TICKT_ID=EXECUTE".  Expected tokens may include:  "IN".  LINE NUMBER=1.
SQLSTATE=42601

这里出了什么问题,我已经冲浪了但没有答案:( 可能存在一些语法错误。请指导我。

TIA。