![]() | |
#1
| |||
| |||
|
#2
| |||
| |||
|
|
Hi, I have looked over various forums, and refined this trigger to the best of my abilities, but when someone pastes a trigger using code -very- similar to yours and it still doesn't work for you, ya gotta ask yourself, what's wrong? CREATE TRIGGER DB2ADMIN.CHECK_INSTOCK BEFORE INSERT ON DB2ADMIN.PRODUCTORDER REFERENCING NEW AS NEW_ORDER FOR EACH STATEMENT MODE DB2SQL BEGIN ATOMIC DECLARE TEMP INTEGER; SET TEMP = (SELECT INSTOCK FROM DB2ADMIN.PRODUCT WHERE PRODUCTID = NEW_ORDER.PRODUCTID); IF (NEW_ORDER.QUANTITY > TEMP) THEN SIGANL SQLSTATE '70001' ('Insufficient Stock'); END IF; END; Above is the trigger i'm trying to get working, the error message clipping is: SQL0104N An unexpected token "INTEGER" was found following "ATOMIC DECLARE TEMP". Expected tokens may include: "END-OF-STATEMENT". LINE NUMBER=6. SQLSTATE=42601 I've seen this line used in other triggers. I've also heard about setting up an alternate termination character such as @ or #. The problem being, I need a way to do that in SQL, as this needs to be submitted as part of a "create script" for an assignment, thus command editor customizations aren't really ideal. The termination character is indeed your problem. |
#3
| |||
| |||
|
#4
| |||
| |||
|
|
Serge, Interesting that a fellow IBMer would respond to me ![]() I tried what you said using the following code, and feeding it straight through the Command Editor GUI: --#SET TERMINATOR @ CREATE TRIGGER DB2ADMIN.CHECK_INSTOCK BEFORE INSERT ON DB2ADMIN.PRODUCTORDER REFERENCING NEW AS NEW_ORDER FOR EACH STATEMENT MODE DB2SQL BEGIN ATOMIC DECLARE TEMP INTEGER; SET TEMP = (SELECT INSTOCK FROM DB2ADMIN.PRODUCT WHERE PRODUCTID = NEW_ORDER.PRODUCTID); IF (NEW_ORDER.QUANTITY > TEMP) THEN SIGANL SQLSTATE '70001' ('Insufficient Stock'); END IF; END @ --#SET TERMINATOR ; But still the same error, it doesn't like the "INTEGER" following "DECLARE TEMP" for some reason. Thanx for the SQL on to set the terminator though, heh I could of almost guessed it ![]() I'm not sure if the GUI eats the --# notation. Might do nothing. |
#5
| |||
| |||
|
#6
| |||
| |||
|
#7
| |||
| |||
|
#8
| |||
| |||
|
#9
| |||
| |||
|
![]() |
| Thread Tools | |
| Display Modes | |
| |