Oracle FAQ | Your Portal to the Oracle Knowledge Grid |
Home -> Community -> Mailing Lists -> Oracle-L -> Re: TRIGGERS
On 5/18/05, Kean Jacinta <jacintakean_at_yahoo.com> wrote:
> Hi ,
>=20
>=20
>=20
>=20
>=20
>=20
>=20
> IF :NEW.id IS NULL THEN
> SELECT myclassseq.NEXTVAL INTO :NEW.id FROM DUAL;
>=20
> END IF;
>=20
>=20
>=20
>=20
>=20
>=20
>=20
>=20
>=20
Hi,
It seems that you don't create the trigger proper (what type of
trigger did you create?)
Otherwise the code David gave you would work regarding your first question.
Here's one way to do it:
SQL> create table t(a int,b varchar2(10));
Table created.
SQL> create sequence seq_a;
Sequence created.
SQL> create trigger trig_t before insert on t for each row
2 begin
3 if :new.a is null then
4 select seq_a.nextval into :new.a from dual;
5 end if;
6 end;
7 /
Trigger created.
SQL> insert into t(b) values ('first');
1 row created.
SQL> insert into t(b) values ('second');
1 row created.
SQL> insert into t values(10,'bypass');
1 row created.
SQL> select * from t;
A B
---------- ----------
1 first 2 second 10 bypass
SQL>
Regards,
Jerome
-- http://www.freelists.org/webpage/oracle-lReceived on Wed May 18 2005 - 09:28:02 CDT