AskSQLTeam
Ask SQLTeam Question
0 Posts |
Posted - 2001-04-09 : 22:49:08
|
Jeff Boyer writes "Basically, I have a trigger that I use to insert some data into my parent table. Everything works great, but now I would like to add to this already working trigger. What I want to do now is, when each row is created I want to insert a row in a child table with the Primary Key that was just inserted from the parent table. I have tried a couple things but nothing seems to work. 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);
I have also tried to create a totaly different trigger for the second bit of code that is fired after an insert but I get the same error. The actual error that I am getting is "Unique Constraint Error - Primary Key Not Found"
I hope you can help, Jeff" |
|