db2 v7R1 - 触发器INSERT New As XML Str

时间:2018-05-25 16:37:14

标签: db2 ibm-midrange

尝试以XML字符串形式创建更改记录。

以下代码不起作用,XML无法转换为varchar或SQL无效错误。

CREATE TRIGGER "QS36F"."WEBTEST1_I" 
    AFTER INSERT ON "QS36F"."WEBTEST1"
    REFERENCING  NEW AS R
    FOR EACH ROW MODE DB2SQL
INSERT INTO "QS36F"."WEBTEST2" ( PREVIOUS_R , NEW_R , ENTRY_DATE ) VALUES ( NULL , CAST(XMLROW(R.ID,R.ITEMNUMBER) as varchar(16355)), CURRENT_TIMESTAMP )

也试过

CREATE TRIGGER "QS36F"."WEBTEST1_I" 
    AFTER INSERT ON "QS36F"."WEBTEST1"
    REFERENCING  NEW AS R
    FOR EACH ROW MODE DB2SQL
INSERT INTO "QS36F"."WEBTEST2" ( PREVIOUS_R , NEW_R , ENTRY_DATE ) VALUES ( NULL ,  CAST((SELECT XMLROW(R.ID, R.ITEMNUMBER) FROM sysibm.sysdummy1) as varchar(16355)) , CURRENT_TIMESTAMP )

还尝试将WEBTEST2的数据类型设为XML ...没有骰子。

[enter image description here]

编辑: enter image description here

EDIT2:

enter image description here

我正在

  

[SQL0312]变量ITEMNUMBER未定义或无法使用。

用于以下查询?

CREATE TRIGGER "QS36F"."WEBTEST1_U" 
    AFTER UPDATE ON "QS36F"."WEBTEST1"
    REFERENCING
    OLD AS o
    NEW AS r
    FOR EACH ROW MODE DB2SQL
    INSERT INTO 
     "QS36F"."WEBTEST2" ( NEW_R , PREVIOUS_R,  ENTRY_DATE ) 
                VALUES ( (select xmlserialize(XMLROW(id as id,itemnumber as itemnumber) as varchar(16355))
                          from table ( values (r.id, r.itemnumber)) as tbl
                          ), (select xmlserialize(XMLROW(id as id,itemnumber as itemnumber) as varchar(16355))
                          from table ( values (o.id, o.itemnumber)) as tbl
                          )
                       , CURRENT_TIMESTAMP 
                       )
          );

1 个答案:

答案 0 :(得分:1)

试试这个......

CREATE TRIGGER "QS36F"."WEBTEST1_I" 
    AFTER INSERT ON "QS36F"."WEBTEST1"
    REFERENCING  NEW AS R
    FOR EACH ROW MODE DB2SQL
    INSERT INTO 
     "QS36F"."WEBTEST2" ( NEW_R , ENTRY_DATE ) 
                VALUES ( (select xmlserialize(XMLROW(id as id,itemnumber as itemnumber) as varchar(16355))
                          from table ( values (r.id, r.itemnumber)) as tbl
                          )
                       , CURRENT_TIMESTAMP 
                       )
          );