运行触发器时出错

时间:2013-10-02 13:28:41

标签: sql triggers db2

创建以下触发器以将资产标签移动到其正确的字段。

虽然收到错误。不是数据库人。

CREATE TRIGGER HARRISOP.ASSET_TAG INSTEAD OF  INSERT  ON DB2ADMIN.SNMPSYS FOR EACH                                                                                STATEMENT MODE DB2SQL 
   SELECT * 
   FROM DB2ADMIN.SNMPSYS AS SNMPSYS
   WHERE SNMPSYS.SYSCONTACT_X = ' A330637'
   INSERT INTO DB2ADMIN.CITEMPLATE (ASSETTAG_X)
   VALUES (DEFAULT)

根据用户帮助新建COde。仍然没有。

CONNECT TO CMDB;
CREATE TRIGGER DB2ADMIN.ASSET_TAG NO CASCADE BEFORE  INSERT  ON DB2ADMIN.SNMPSYS  FOR EACH ROW  MODE DB2SQL 
REFERENCING 
    NEW AS N
FOR EACH ROW 
MODE DB2SQL
SET N.ASSETTAG_X = SUBSTR(
  N.SYSCONTACT_X, 
  1, 
  LOCATE(',', N.SYSCONTACT_X) - 1
);
CONNECT RESET;

1 个答案:

答案 0 :(得分:0)

如果我理解你想要什么,触发器应该看起来像

CREATE TRIGGER HARRISOP.ASSET_TAG 
BEFORE INSERT   
ON DB2ADMIN.SNMPSYS 
REFERENCING NEW AS N
FOR EACH ROW 
SET N.ASSETTAG_X = SUBSTR(
  N.SYSCONTACT_X, 
  1, 
  LOCATE(',', N.SYSCONTACT_X) - 1
)

您应该阅读手册中有关触发器的更多信息:http://pic.dhe.ibm.com/infocenter/db2luw/v10r1/topic/com.ibm.db2.luw.admin.dbobj.doc/doc/t0020225.html