If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Database Server Software > DB2 > Trigger and cursor error

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 09-24-04, 17:03
ApoPen ApoPen is offline
Registered User
 
Join Date: Jul 2004
Location: Ottawa, Canada
Posts: 58
Trigger and cursor error

Is it possible to delcare a cursor in a trigger? The following trigger returns:

SQL0104N An unexpected token "FOR" was found following " ". Expected tokens may include: "<space>". LINE NUMBER=13.
SQLSTATE=42601



CREATE TRIGGER InsertCF_Tgr
AFTER INSERT ON CargoFolder
REFERENCING NEW AS CF_New
FOR EACH ROW MODE DB2SQL
BEGIN ATOMIC

-- declare variables
DECLARE SQLSTATE CHAR(5);
DECLARE Tgr_DeliveryStatus SMALLINT DEFAULT 0;
DECLARE Tgr_Count SMALLINT DEFAULT 0;

-- declare the cursor
DECLARE C1 CURSOR FOR SELECT DeliveryStatus, COUNT(*) FROM CargoMessage WHERE CCN = CF_New.CCN AND Type IN (501,502,504) GROUP BY DeliveryStatus;

-- open the cursor
OPEN C1;

-- Fetch from the cursor until it is empty
FETCH FROM C1 INTO Tgr_DeliveryStatus, Tgr_Count;
WHILE (SQLSTATE = '00000') DO

IF (Tgr_DeliveryStatus = 201)
THEN UPDATE CF_New.CountNew = Tgr_Count;
ELSEIF (Tgr_DeliveryStatus = 202)
THEN UPDATE CF_New.CountSent = Tgr_Count;
ELSEIF (Tgr_DeliveryStatus = 203)
THEN UPDATE CF_New.CountDelivered = Tgr_Count;
ELSEIF(Tgr_DeliveryStatus = 204)
THEN UPDATE CF_New.CountFailed = Tgr_Count;
ENDIF;

FETCH FROM C1 INTO Tgr_DeliveryStatus, Tgr_Count;
END WHILE;

CLOSE C1;
END@
Reply With Quote
  #2 (permalink)  
Old 09-24-04, 17:08
ARWinner ARWinner is offline
Registered User
 
Join Date: Jan 2003
Posts: 3,575
Nope, only is stored procedures.

Andy
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On