简体   繁体   中英

Error SQLCODE -138 when doing a trigger in DB2

I get the following error trying to create a stored procedure in DB2

Error report:
DB2 SQL error: SQLCODE: -138, SQLSTATE: 22011, SQLERRMC: null

My trigger is the following one:

CREATE TRIGGER INSERT_SERIALNUMBER
AFTER INSERT ON LASERM
REFERENCING NEW ROW AS NROW
FOR EACH ROW MODE DB2SQL
BEGIN
DECLARE ARTICLECODE CHAR(30); 
DECLARE POS INT;
SET POS = LOCATE('-', NROW.PROGRAMNAME);

IF POS > 0 THEN
  SET ARTICLECODE = SUBSTR(NROW.PROGRAMNAME, 0, POS);
ELSE
  SET ARTICLECODE = NROW.PROGRAMNAME;
END IF;
CALL SP_INSERT_SERIALNUMBER(ARTICLECODE, NROW.PCBCODE);
END

According to the DB2 SQLCodes list, -138

-138 THE SECOND OR THIRD ARGUMENT OF THE SUBSTR OR SUBSTRING FUNCTION IS OUT OF RANGE

What I want to do is to substract a string from another when it finds a "-". For example, the code is "ART00001-A" and I would like to get just "ART00001".

I'm not an expert in DB2 SQL syntax, so please,thanks in advance if you see the problem in that code.

DB2中的字符串位置是基于一个的,但是您要指示一个从位置0开始的子字符串。只需使用:

SET ARTICLECODE = SUBSTR(NROW.PROGRAMNAME, 1, POS);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM