GENERATE_UUID

The GENERATE_UUID function returns the formatted string representation of a Universally Unique Identifier (UUID) using the version 4 algorithm.

Read syntax diagramSkip visual syntax diagramGENERATE_UUID ()

The result of the function is a CHAR(36) value formatted like xxxxxxxx-xxxx-4xxx-xxxx-xxxxxxxxxxxx. Characters in the string are in upper case. The CCSID of the result is the default SBCS CCSID at the current server. The result cannot be null.

GENERATE_UUID is a non-deterministic function.

Note

To convert from the CHAR(36) form of a UUID value to a BINARY(16) representation of the value, use the VARBINARY_FORMAT scalar function. See VARBINARY_FORMAT.

To convert from the BINARY(16) form of a UUID value to the CHAR(36) representation of the value, use the VARCHAR_FORMAT_BINARY scalar function. See VARCHAR_FORMAT_BINARY.

Example

  • Generate a UUID value. This generates a CHAR(36) string value.
    VALUES GENERATE_UUID() 
    For example, this string could be generated: 'D83D6360-1818-41EB-9804-B622A1FE5492'