Problem in inserting values using preInsert trigger [message #477454] |
Thu, 30 September 2010 14:20 |
nikhilk411
Messages: 33 Registered: September 2010 Location: Mumbai
|
Member |
|
|
Hi,
I am facing a problem while inserting primary keys using a sequence. Following is my case
I have a Master Table, say M_A, and 2 detail tables D_1 and D_2.
I am trying to generate primary keys for the master and detail table as well as the reference keys for the detail tables using sequence.
I created a pre-insert trigger, say preInsertTRIG
proc_ABC(pri_key_master OUT VARCHAR2,
pri_key_detail1 OUT VARCHAR2,
fk_detail1 OUT VARCHAR2,
pri_key_detail2 OUT VARCHAR2,
fk_detail2 OUT VARCHAR2)
);
as
v_no NUMBER(10);
BEGIN
select id_seq.next val into v_no from dual;
pri_key_master := 'PK'||to_char(v_no); --assign P.K to mast
pri_key_detail1 := 'PK_D1'||to_char(v_no);
pri_key_detail2 := 'PK_D2'||to_char(v_no);
fk_detail1 := pri_key_master;
fk_detail2 := pri_key_master;
end;
end;
I am able to insert the P.K of the master table as well as the P.K of one of the detail table. However, it fails to insert the P.K of 2nd detail table and reference keys for both the detail tables.
Can someone kindly guide where am I going wrong?
P.S: I know there are other simple methods available in Forms, but I have to do it by this procedure only
|
|
|
|
|
|
|
|