Issue in creating the triggers



IBM's flagship relational database management system

Issue in creating the triggers

Postby rupa888 » Tue Jan 08, 2013 3:38 pm

Hi,
i want to create a trigger that check before insert in DNBA.T04DOM10 table if there is already no GE001 or GE006 for the cod-enmpresa/cod-persona with stato-riga = '01' exist in table T04CNB01 when not then insert it like that.So i tried it, but getting the following error
   CREATE TRIGGER DNBA.T04DOM10F AFTER INSERT ON DNBA.T04DOM10               
       REFERENCING NEW AS N                                                   
       FOR EACH ROW MODE DB2SQL                                               
       WHEN (N.COD_TIPO_DIREC      = '1' OR                                   
             N.COD_TIPO_DIREC      = '8')
       BEGIN ATOMIC                                         
       IF (SELECT COUNT(*) FROM T04CNB01 A, T04DBA01 B                       
            WHERE A.COD_PERSONA    =  N.COD_PERSONA                           
              AND A.COD_EMPRESA    =  N.COD_EMPRESA                           
              AND STATO_RIGA       = '01'                                     
              AND COD_DATO NOT IN   ('GE001','GE006')                         
              AND A.COD_PERSONA    =  B.COD_PERSONA                           
              AND A.COD_EMPRESA    =  B.COD_EMPRESA                           
              AND B.COD_CENTRO_INS = '0039') > 0 THEN                         
           INSERT INTO T04CNB01                                               
                   (COD_EMPRESA,                                             
                    COD_PERSONA,                                             
                    COD_DATO,                                                 
                      COD_AMBITO,                                               
                      STATO_RIGA,                                               
                      FEC_MODIFICACION,                                         
                      COD_USU_MODIF,                                             
                      TIMESTAMP_SIGLO)                                           
              VALUES (N.COD_EMPRESA,                                             
                      N.COD_PERSONA,                                             
                      'GE006',                                                   
                      'GENER',                                                   
                      '01',                                                     
                      CURRENT DATE,                                             
                      '30MINUPD',                                               
                      CURRENT TIMESTAMP) ;
       END IF;
       END                                             
---------+---------+---------+---------+---------+---------+---------+---------+
DSNT408I SQLCODE = -104, ERROR:  ILLEGAL SYMBOL "<END-OF-STATEMENT>". SOME       
         SYMBOLS THAT MIGHT BE LEGAL ARE: FOR ; NOT ATOMIC                       
DSNT418I SQLSTATE   = 42601 SQLSTATE RETURN CODE                                 
DSNT415I SQLERRP    = DSNHPARS SQL PROCEDURE DETECTING ERROR                     
DSNT416I SQLERRD    = 3 0  0  -1  2122  502 SQL DIAGNOSTIC INFORMATION           
DSNT416I SQLERRD    = X'00000003'  X'00000000'  X'00000000'  X'FFFFFFFF'         
         X'0000084A'  X'000001F6' SQL DIAGNOSTIC INFORMATION                     
---------+---------+---------+---------+---------+---------+---------+---------+
rupa888
 
Posts: 21
Joined: Tue Sep 18, 2012 5:12 pm
Has thanked: 1 time
Been thanked: 0 time

Re: Issue in creating the triggers

Postby dick scherrer » Tue Jan 08, 2013 10:18 pm

Hello,

Typically, the INSERT is issued and if the duplicate condition is raised, the process deals with the duplicate, otherwise the row is inserted. The overhead and additional complexity of a trigger should not be needed.

Maybe there is something i do not understand?
Hope this helps,
d.sch.
User avatar
dick scherrer
Global moderator
 
Posts: 6268
Joined: Sat Jun 09, 2007 8:58 am
Has thanked: 3 times
Been thanked: 93 times

Re: Issue in creating the triggers

Postby rupa888 » Wed Jan 09, 2013 10:13 am

Thanks dick.Ya we are checking for duplicates only and also a record should exists in other table T04DBA01 with cod-usu-modif = '0039'
rupa888
 
Posts: 21
Joined: Tue Sep 18, 2012 5:12 pm
Has thanked: 1 time
Been thanked: 0 time


Return to DB2

 


  • Related topics
    Replies
    Views
    Last post