Home » RDBMS Server » Server Administration » insert of a pk value number generated from sequence fails
insert of a pk value number generated from sequence fails [message #375173] Thu, 02 August 2001 09:59 Go to next message
Andreas Stutzki
Messages: 2
Registered: August 2001
Junior Member
I wrote a simple before - insert trigger, that inserts a number - value generated by a sequence into a pk - column.

create or replace trigger adress_pk
before insert on evi_ora_p1.adrglob
for each row
declare
pk number;
begin
select medas_seq_1.nextval
into pk
from dual;
insert into adrglob(Glob_Adresseid)
values(pk);
end;

The trigger will be compiled without errors. If i try to unsert a new value into the table a
ORA-00036 error occurs followed by a ORA-04088 and an ORA-06512 error message. Does anybody know the how to fix the problem - thanks in advance.
Re: insert of a pk value number generated from sequence fails [message #375176 is a reply to message #375173] Thu, 02 August 2001 12:35 Go to previous messageGo to next message
Senthil
Messages: 68
Registered: December 1999
Member
where is the problem...works for me...

SQL> create sequence user_seq start with 1;

Sequence created.

SQL> create table t1 (no number);

Table created.

SQL> create table t2 (no number);

Table created.

SQL> create or replace trigger t1_trig_ins before insert on t1
2 for each row
3 declare
4 pk number;
5 begin
6 select user_seq.nextval into pk from dual;
7 insert into t2 values (pk);
8 end;
9 /

Trigger created.

SQL> insert into t1 values (5);

1 row created.

SQL> select * from t1;

NO
----------
5

SQL> select * from t2;

NO
----------
1

SQL> commit;

Commit complete.
Re: insert of a pk value number generated from sequence fails [message #375177 is a reply to message #375173] Thu, 02 August 2001 14:13 Go to previous message
Todd Barry
Messages: 4819
Registered: August 2001
Senior Member
Just select the sequence value into :new.glob_adresseid - no need for a variable.

create or replace trigger adress_pk
before insert on evi_ora_p1.adrglob
for each row
begin
if :new.glob_adresseid is null then
select medas_seq_1.nextval
into :new.glob_adresseid
from dual;
end if;
end;
Previous Topic: Re: How to copy records between 2 instances?
Next Topic: Sequence...
Goto Forum:
  


Current Time: Tue Dec 24 06:47:23 CST 2024