Oracle FAQ Your Portal to the Oracle Knowledge Grid
HOME | ASK QUESTION | ADD INFO | SEARCH | E-MAIL US
 

Home -> Community -> Usenet -> c.d.o.tools -> Re: using a trigger to enter data into a child table.

Re: using a trigger to enter data into a child table.

From: Van Messner <vmessner_at_bestweb.net>
Date: Tue, 10 Apr 2001 00:33:39 GMT
Message-ID: <DxsA6.2038$Uu6.196924@monger.newsread.com>

What may be happening is that you've been playing around with this for awhile and your sequences are not in sync the way you think they are, so you're inserting a row which already exists (primary key wise or unique constraint wise).

Van

"Jeff Boyer" <jdboyer@(remove)icomproductions.ca> wrote in message news:9aso2v$4qd$1_at_news3.cadvision.com...
> I have a trigger that fires whenever an insert in done on one of my
 tables.
> It has been working great, but now I want to use this trigger to insert a
> some values into a child table. I don't really understand how to do this.
> This is the code I am using:
>
> Working trigger before the added code:
>
> CREATE OR REPLACE TRIGGER Comp_Id_Trg
> BEFORE INSERT on Company_reg
> FOR EACH ROW
> DECLARE
> Temp Varchar2(30);
> BEGIN
> SELECT Comp_ID_SEQ.NEXTVAL
> INTO Temp FROM DUAL;
> Temp := 'SSCA-'||Temp;
> :New.Company_id := Temp;
> :New.Phasestat := 'Phase1Begin';
> :New.Phase := 'Choose One';
> :New.Reason := 'Choose One';
> END Comp_Id_Trg;
> /
>
> Now This is what I am trying to do but can't seem to get the code right:
>
> CREATE OR REPLACE TRIGGER Comp_Id_Trg
> BEFORE INSERT on Company_reg
> FOR EACH ROW
> DECLARE
> Temp Varchar2(30);
> Temp2 Number;
> BEGIN
> SELECT Comp_ID_SEQ.NEXTVAL
> INTO Temp FROM DUAL;
> Temp := 'SSCA-'||Temp;
> :New.Company_id := Temp;
> :New.Phasestat := 'Phase1Begin';
> :New.Phase := 'Choose One';
> :New.Reason := 'Choose One';
> SELECT Con_ID_SEQ.NEXTVAL
> INTO Temp2 FROM DUAL;
> Insert INTO CON_INFO
>

 (CON_ID,COMPANY_ID,CON_MAIL1,CON_MAIL2,CON_DIRCALL,PHS1FORM_FAX,PHS1FORM_EMA
> IL, UNSOLCALL,
> PHSFORM_COURIER, PHSFORM_RECBACK, PHSFORM_INPUTED, PHSFORM_WEBSITE,
> CON_VALQ1INFO, CON_PARTICIPATION, PHASE2PRE_CALLEDCOMP,
> CALLCOMPLETED, PHS2FAX, PHS2EMAIL, PHS2COURIER, PHS2RECBACK, PHS2INPUTTED,
> PHS2WEBSITE) VALUES (Temp2, 'Temp',
> 1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0);
>
> END Comp_Id_Trg;
> /
>
>
> Can anyone tell me what I am doing wrong. This gives me a unique
 constraint
> error.
>
> Thanks,
> Jeff
>
>
>
>
Received on Mon Apr 09 2001 - 19:33:39 CDT

Original text of this message

HOME | ASK QUESTION | ADD INFO | SEARCH | E-MAIL US