user13553031
user13553031

Reputation:

how to generate unique values using sys_GUID() in oracle?

select (SELECT   UPPER(SUBSTR(SYS_GUID(), 1, 16)) FROM DUAL) AS N_EVTtt_ID
from testing

I am using the above query to generate the unique ID(GUID) which apparently is giving me the same value for my primary key N_EVTtt_ID . Please advice how to fix this? The output for the above SQL query. I want all the IDs to be different.

AC87290F7D305666 
AC87290F7D305666
AC87290F7D305666
AC87290F7D305666
AC87290F7D305666
AC87290F7D305666

Thanks in Advance

Upvotes: 0

Views: 2903

Answers (1)

jarlh
jarlh

Reputation: 44766

Skip the subquery:

select UPPER(SUBSTR(SYS_GUID(), 1, 16)) AS N_EVTtt_ID
from testing 

In an INSERT:

insert into some_table
select UPPER(SUBSTR(SYS_GUID(), 1, 16)) AS N_EVTtt_ID from testing

Upvotes: 1

Related Questions