Oracle FAQ | Your Portal to the Oracle Knowledge Grid |
![]() |
![]() |
Home -> Community -> Usenet -> c.d.o.tools -> Re: Oracle Table Key
Hi
To generate numbers you can use sequences:
create sequence uuid_seq;
For detailed options see the documentation.
To generate a number you can select the sequence:
select uuid.nextval from dual;
You can also include this directly into an insert command:
insert into TABLE_NAME (UUID) values (uuid_seq.nextval);
If you want to autmatically create the primary key, you can write a before insert trigger, where you fill the :new.uuid colum with the result of the select from the sequence. The disadvantage of this is that you have to do an additional select to get the generated number from the newly created record in case you have to crate further records whith the same number (e. g. if you have to create colums in another table which have a foreign key to this key).
With uuid_seq.currval you can access the last number you have generated within your session:
select uuid_seq.currval from dual;
Bye.
Thomas
Vladimir Tsvetkov wrote:
> Hallo,
> I want to create the new records in my table. Must I manage self the UUID
> Column in my table or I can create the constraints, wich automate the
> process of UUID creation??
>
> Regards
> Vladimir Tsvetkov
>
>
>
>
>
-- -------------------------------- more than internet worldwide consulting for Oracle, Linux, Internet ... w.e.b.s.p.o.t http://www.webspot.ch mailto:info_at_webspot.chReceived on Thu Aug 02 2001 - 06:14:39 CDT
![]() |
![]() |