Forum Stats

  • 3,853,595 Users
  • 2,264,243 Discussions
  • 7,905,405 Comments

Discussions

A little help with trigger syntax, please...

807762
807762 Member Posts: 1
edited Oct 25, 2010 1:15AM in SQL & PL/SQL
Hey guys, I am trying to create a simple trigger to implement an cascaded updated ...

CREATE OR REPLACE TRIGGER UCRI_CA_G
BEFORE UPDATE OF CA_CODE ON CONSERVATION_AGENCY
FOR EACH ROW

--BEGIN
UPDATE GRANTS SET CA_CODE = :NEW.CA_CODE WHERE CA_CODE = :OLD.CA_CODE;
--END;

I don't understand what the incorrect syntax is here, could someone please give me a hand?
Tagged:

Answers

  • 672680
    672680 Member Posts: 806
    Here is a similar one, I didn`t get any error. You could always post your error, so it would be easier for people to tell you what went wrong.
    create or replace
    trigger test 
    BEFORE update of deptno ON dept 
    FOR EACH ROW 
    begin
    
      update emp set deptno=:new.deptno where deptno=:old.deptno;
      
    end;
  • 802709
    802709 Member Posts: 357
    edited Oct 25, 2010 1:12AM
    CREATE OR REPLACE TRIGGER UCRI_CA_G
    BEFORE UPDATE OF CA_CODE ON CONSERVATION_AGENCY
    FOR EACH ROW
    
    BEGIN
      UPDATE GRANTS SET CA_CODE = :NEW.CA_CODE WHERE CA_CODE = :OLD.CA_CODE;
    END;
    /
    your code must be like above, remove "--". there is no any error except that, what is the error that you got ?

    and also i advice you add a WHEN clause to trigger, it prevent unnecessary fire of trigger.

    CREATE OR REPLACE TRIGGER UCRI_CA_G
    BEFORE UPDATE OF CA_CODE ON CONSERVATION_AGENCY
    FOR EACH ROW
    when (old.CA_CODE != new.CA_CODE) /*ADD THIS*/
    BEGIN
      UPDATE GRANTS SET CA_CODE = :NEW.CA_CODE WHERE CA_CODE = :OLD.CA_CODE;
    END;
    /
    Edited by: Mustafa KALAYCI on 25.Eki.2010 07:59
  • KanchDev
    KanchDev Member Posts: 406
    Hi

    What's the error you're getting while compiling ?.

    Cheers
    Kanchana
This discussion has been closed.