Trigger to read a sequence and populate a Primary Key
DBAsupport.com Forums - Powered by vBulletin
Results 1 to 4 of 4

Thread: Trigger to read a sequence and populate a Primary Key

  1. #1
    Join Date
    Jan 2000
    Location
    Chester, England.
    Posts
    818
    I can't get a trigger to compile. What am I doing wrong?

    I want to use a sequence to generate a Primary Key on a table. I want the trigger to fire BEFORE INSERT FOR EACH ROW and use the sequence.NEXTVAL as the value of the PR KEY.

    What's the correct syntax please folks?

    I'm using 8.1.5

  2. #2
    Join Date
    Jan 2000
    Location
    Chester, England.
    Posts
    818

    My code is ...

    1 CREATE OR REPLACE TRIGGER HELP_DESK_ID_INS_TRG
    2 BEFORE INSERT ON HELP_DESK_CALLS
    3 FOR EACH ROW
    4 Declare
    5 V_SeqVal Number;
    6 BEGIN
    7 Select HELP_DESK_SEQ.NEXTVAL Into V_SeqVal From Dual;
    8 :New.call_id = V_SeqVal;
    9* END;
    10 /

    Warning: Trigger created with compilation errors.

  3. #3
    Join Date
    Mar 2001
    Posts
    635
    Hi

    Try this

    :New.call_id = V_SeqVal;

    the above statment should be

    :New.call_id := V_SeqVal;

    the colon is missing

    Regards
    Santosh

  4. #4
    Join Date
    Jan 2000
    Location
    Chester, England.
    Posts
    818

    !!!!

    Can you believe it!

    Thanks for the extra pair of eyes!
    JM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width