Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to generate a GUID in Oracle?

Tags:

guid

oracle

Is it possible to auto-generate a GUID into an Insert statement?

Also, what type of field should I use to store this GUID?

like image 339
Acibi Avatar asked Jun 14 '10 13:06

Acibi


People also ask

How do you create a GUID?

To Generate a GUID in Windows 10 with PowerShell, Type or copy-paste the following command: [guid]::NewGuid() . This will produce a new GUID in the output. Alternatively, you can run the command '{'+[guid]::NewGuid(). ToString()+'}' to get a new GUID in the traditional Registry format.

What is Sys_guid () function in Oracle?

SYS_GUID generates and returns a globally unique identifier ( RAW value) made up of 16 bytes. On most platforms, the generated identifier consists of a host identifier, a process or thread identifier of the process or thread invoking the function, and a nonrepeating value (sequence of bytes) for that process or thread.

What is GUID generator?

A GUID (globally unique identifier) is a 128-bit text string that represents an identification (ID). Organizations generate GUIDs when a unique reference number is needed to identify information on a computer or network. A GUID can be used to ID hardware, software, accounts, documents and other items.

How do I generate a random UUID in SQL?

The function random_uuid returns a randomly generated UUID, as a string of 36 characters. This function can be used to generate values for columns of type UUID in an INSERT or UPDATE SQL statements. In this example, a randomly generated UUID is fetched using the random_uuid function.


1 Answers

You can use the SYS_GUID() function to generate a GUID in your insert statement:

insert into mytable (guid_col, data) values (sys_guid(), 'xxx'); 

The preferred datatype for storing GUIDs is RAW(16).

As Gopinath answer:

 select sys_guid() from dual  union all  select sys_guid() from dual  union all   select sys_guid() from dual 

You get

88FDC68C75DDF955E040449808B55601
88FDC68C75DEF955E040449808B55601
88FDC68C75DFF955E040449808B55601

As Tony Andrews says, differs only at one character

88FDC68C75DDF955E040449808B55601
88FDC68C75DEF955E040449808B55601
88FDC68C75DFF955E040449808B55601

Maybe useful: http://feuerthoughts.blogspot.com/2006/02/watch-out-for-sequential-oracle-guids.html

like image 68
Tony Andrews Avatar answered Oct 21 '22 10:10

Tony Andrews