473,408 Members | 2,734 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,408 software developers and data experts.

Trigger compilation error


Hi,

I am creating a trigger in DB2 express version.

When i use the following syntax to create trigger

CREATE TRIGGER USER_PK_TRIGGER
BEFORE INSERT On users
REFERENCING NEW As N
FOR EACH ROW
Begin
if((N.user_id is null) or (N.user_id <= 0)) then
set N.user_id = nextval for user_seq;
end if;
End@
I am getting the following error.

DB21034E The command was processed as an SQL statement because it was
not a valid Command Line Processor command. During SQL processing it
returned: SQL0104N An unexpected token "(" was found following "EACH
ROW Begin if(".
Expected tokens may include: "<space>". LINE NUMBER=6.
SQLSTATE=42601

But when i change my create trigger syntax to include atomic word it
works.

CREATE TRIGGER USER_PK_TRIGGER
BEFORE INSERT On users
REFERENCING NEW As N
FOR EACH ROW
Begin Atomic
if((N.user_id is null) or (N.user_id <= 0)) then
set N.user_id = nextval for user_seq;
end if;
End@

Why do i need to make my trigger atomic? When it commits does it commit
everything (in the ongoing transaction) or only the compound statement
in the trigger? What is wrong in my first create trigger syntax?

I am new in DB2 and in most of the examples they have shown that
something like first syntax should work, i am not able to figure what
what is wrong here. Any help to fix this will be highly appreciated.

Thanks in advance.
--
deepdata
------------------------------------------------------------------------
deepdata's Profile: http://www.dbtalk.net/m335
View this thread: http://www.dbtalk.net/t310906

Jun 2 '06 #1
1 2185
deepdata wrote:
Hi,

I am creating a trigger in DB2 express version.

When i use the following syntax to create trigger

CREATE TRIGGER USER_PK_TRIGGER
BEFORE INSERT On users
REFERENCING NEW As N
FOR EACH ROW
Begin
if((N.user_id is null) or (N.user_id <= 0)) then
set N.user_id = nextval for user_seq;
end if;
End@
I am getting the following error.

DB21034E The command was processed as an SQL statement because it was
not a valid Command Line Processor command. During SQL processing it
returned: SQL0104N An unexpected token "(" was found following "EACH
ROW Begin if(".
Expected tokens may include: "<space>". LINE NUMBER=6.
SQLSTATE=42601

But when i change my create trigger syntax to include atomic word it
works.

CREATE TRIGGER USER_PK_TRIGGER
BEFORE INSERT On users
REFERENCING NEW As N
FOR EACH ROW
Begin Atomic
if((N.user_id is null) or (N.user_id <= 0)) then
set N.user_id = nextval for user_seq;
end if;
End@

Why do i need to make my trigger atomic? When it commits does it commit
everything (in the ongoing transaction) or only the compound statement
in the trigger? What is wrong in my first create trigger syntax?

I am new in DB2 and in most of the examples they have shown that
something like first syntax should work, i am not able to figure what
what is wrong here. Any help to fix this will be highly appreciated.

CREATE TRIGGER:
<blah..blah>
SQL-procedure-statement:

|--+-CALL----------------------------------------------+--------|
+-Compound SQL (Dynamic)----------------------------+
+...
Under compound SQL (Dynamic):
dynamic-compound-statement
-+-------------+--BEGIN ATOMIC--------.......

| (1) |
'-label:------'
So much for the syntax. Now for the semantics.
A when a trigger fails the invoking statement must fail to maintain DB
integrity. Thus atomicity is semantically required.
COMMIT or ROLLBACK are not allowed in triggers.
You can ROLLBACK TO SAVEPOINT in a procedure called by a trigger if you
wish, but that savepoint has to be local within the trigger's scope.

Cheers
Serge
--
Serge Rielau
DB2 Solutions Development
IBM Toronto Lab
Jun 3 '06 #2

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...
0
by: Dave Sisk | last post by:
I've created a system or external trigger on an AS/400 file a.k.a DB2 table. (Note this is an external trigger defined with the ADDPFTRG CL command, not a SQL trigger defined with the CREATE...
4
by: Alexander Pope | last post by:
I am using db2 udb v8.2 AIX I have created trigger, however I am not confident it meets industry standards. If I make it fail, I cant tell from the message where it is failing. what can I add to...
12
by: Bob Stearns | last post by:
I am trying to create a duplicate prevention trigger: CREATE TRIGGER is3.ard_u_unique BEFORE UPDATE OF act_recov_date ON is3.flushes REFERENCING NEW AS N FOR EACH ROW MODE DB2SQL WHEN...
5
by: Bob Stearns | last post by:
I have two (actually many) dates in a table I want to validate on insertion. The following works in the case of only one WHEN clause but fails with two (or more), with the (improper?...
1
by: umesh049 | last post by:
hello I want to update in one trigger the tables in to another schema but it doesn't work but when i select data from sql prompt it works fine. can any body help me. thanks. CREATE OR...
5
by: Bruno Rafael Moreira de Barros | last post by:
function test1() { trigger_error('My error'); } application.php //code... test1(); //code...
3
by: jaanutn | last post by:
what is wrong with this code? y it is coming with compilation error? create or replace trigger insert_error before insert or update on trig for each row declare ...
11
by: tracy | last post by:
Hi, I really need help. I run this script and error message appeal as below: drop trigger log_errors_trig; drop trigger log_errors_trig ERROR at line 1: ORA04080: trigger 'LOG_ERRORS-TRIG'...
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: 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
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

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.