Oracle FAQ | Your Portal to the Oracle Knowledge Grid |
Home -> Community -> Usenet -> c.d.o.server -> Re: Generating unique key numbers
Try this:
CREATE TRIGGER tabtrig
BEFORE INSERT ON tab
FOR EACH ROW
DECLARE
iNo integer;
BEGIN
select tabseq.nextval into iNo from dual;
:NEW.id := iNo;
END;
/
Michal Motalík <cross_at_zl.inext.cz> wrote in article
<01bcfcdc$3a121700$LocalHost_at_michal>...
> I am developing a client/server project which will run on both
> Interbase and Oracle. I wrote a trigger which sets unique numbers
> from generator to primary index column on Interbase. I want to
> write similar trigger on Oracle but i have a problem.
>
> I can not create trigger:
>
> CREATE TRIGGER tabtrig
> BEFORE INSERT ON tab
> FOR EACH ROW
> BEGIN
> :NEW.id := tabseq.NEXTVAL;
> END;
>
> The sequence "tabseq" was created.
> I get the error PLS-00357.
> (reference to sequence is not permitted in these context)
>
> Does anybody know where the problem is?
>
> Michal Motalík
> cross_at_zl.inext.cz
>
Received on Mon Dec 01 1997 - 00:00:00 CST