473,386 Members | 1,795 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

CREATE TRIGGER ON INSERT

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.

I wouldn't be using Google Groups if I had other options, I've been
stretched beyond my means, trigger creation isn't even my task or
forte.

Can someone please help me out?

Regards,
b00x

May 27 '06 #1
8 9687
si***********@gmail.com wrote:
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.
is your interface the regular CLP? If so simply try this:
--#SET TERMINATOR @
CREATE TRIGGER .......
BEGIN ATOMIC
.....
END
@
--#SET TERMINATOR ;

Or you can start CLP like this:
db2 -td@
perhaps
db2 -td@ -f <filename>
for your script.

Cheers
Serge
--
Serge Rielau
DB2 Solutions Development
IBM Toronto Lab
May 27 '06 #2
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 ;)

May 27 '06 #3
si***********@gmail.com wrote:
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.
What's so bad about setting the terminator in the GUI...?

Cheers
Serge
--
Serge Rielau
DB2 Solutions Development
IBM Toronto Lab
May 27 '06 #4
Just a thought,

Maybe if someone could explain to me why the following won't work:

CREATE TRIGGER DB2ADMIN.CHECK_INSTOCK
BEFORE INSERT ON DB2ADMIN.PRODUCTORDER
REFERENCING NEW AS NEW_ORDER
FOR EACH ROW MODE DB2SQL
WHEN (NEW_ORDER.QUANTITY > (SELECT INSTOCK FROM DB2ADMIN.PRODUCT
WHERE PRODUCTID = NEW_ORDER.PRODUCTID))
SIGANL SQLSTATE '70001' ('Insufficient Stock');

Yet one like below, works fine?

CREATE TRIGGER DB2ADMIN.CHECK_ORDERQTY
BEFORE INSERT ON DB2ADMIN.PRODUCTORDER
REFERENCING NEW AS NEW_PRODUCT
FOR EACH ROW MODE DB2SQL
WHEN(NEW_PRODUCT.QUANTITY < 1)
SIGNAL SQLSTATE '70001' ('You cannot order less than 1 of an
item');

And how can I over come the problem?

Maybe this is a better question than my first one.

Thanks in advance!

Regards,
b00x

May 27 '06 #5
Serge,

Nothing, its just dirty, and provides complications when transporting
the create script.

Not to worry, the GUI editor loves the --# ;)

------------------------------ Commands Entered
------------------------------
--#SET TERMINATOR @;
SELECT COUNT(*) FROM PRODUCT;
SELECT COUNT(*) FROM TOURINFO @;
------------------------------------------------------------------------------
SELECT COUNT(*) FROM PRODUCT
1
-----------
42
1 record(s) selected.

SELECT COUNT(*) FROM TOURINFO @
1
-----------
8
1 record(s) selected.

May 27 '06 #6
OKAY!!!!!!!!

I just made a massive dick of myself! (lucky i didn't expose my real
name! ;))

Seems that typo on "SIGANL" is for real. The following worked fine:

CREATE TRIGGER DB2ADMIN.CHECK_INSTOCK
BEFORE INSERT ON DB2ADMIN.PRODUCTORDER
REFERENCING NEW AS NEW_ORDER
FOR EACH ROW MODE DB2SQL
WHEN (NEW_ORDER.QUANTITY > (SELECT INSTOCK FROM DB2ADMIN.PRODUCT
WHERE PRODUCTID = NEW_ORDER.PRODUCTID))
SIGNAL SQLSTATE '70001' ('Insufficient Stock');

May 27 '06 #7
So it's working now?

--
Serge Rielau
DB2 Solutions Development
IBM Toronto Lab
May 27 '06 #8
Yeh, was just a stupid mistake. I guess it pays to have another pair of
eyes look at it.

One of my friends checked it out, and saw that typo straight away.

Thanks for your help though, nice to know people do monitor these
groups in real-time :)

May 27 '06 #9

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Darren | last post by:
Hello, I have some 'CREATE TRIGGER' definitions that work when cut/pasted into SQL*Plus worksheet and execute separately but fail with a 'trigger created with compilation errors' when executed...
1
by: Jack | last post by:
I created a trigger in the "source table" that will "feed" and second table. The trigger is as follows: CREATE TRIGGER ON dbo.FromUPS FOR INSERT AS Declare @Count int Select @Count =...
1
by: Ling Xiaoyu | last post by:
Hello there. Can anybody help me with Postgresql triggers? what I need is a trigger which update value of field "tables_rows.total_rows" to rows count of table "zzz" if I insert new row in table...
1
by: Barbara Lindsey | last post by:
I am a postgres newbie. I am trying to create a trigger that will put a copy of a record into a backup table before update or delete. As I understand it, in order to do this I must have a...
0
by: Yogesh | last post by:
Hello Everyone I have to create Oracle tables in my application on the fly, which have an Autonumber field. So, everytime I create a table, I have to create a corresponding sequence and trigger...
1
by: Bruno BAGUETTE | last post by:
Hello, I'm trying to build a PL/PGSQL function that will be called by a trigger which will update a table named 'mview_contacts'. That table plays the role of a materialized view. The...
3
by: satish | last post by:
hi, CAn i have one trigger for both Update and Delete Delete Trigger --------------------- create Trigger on . for delete as begin insert into z_user_log select * from deleted end
2
by: lakuma | last post by:
Hi, I have a table called A (say) with columns called name, place, animal and thing. I would want to write an on insert trigger on this table, which would create a table with the name of the...
3
by: Andrea MF | last post by:
Hi all, i have a problem when creating a trigger on DB2 ver 7.2 on WINDOWS. I have two tables MOVIMAG and BARCODE, the trigge when INSERT INTO MOVIMAG will be UPDATE a MOVIMAG field BARCODE...
6
by: Alvin SIU | last post by:
Hi all, I have a table in Db2 v8 like this: Team Name Role ------ -------- --------------------- A Superman Leader A Batman Member A WonderWoman Member B ...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.