Generate a GUID or UUID in DB2

WordPress database error: [Got error 28 from storage engine]
SHOW FULL COLUMNS FROM `markjacobsen_options`

WordPress database error: [Got error 28 from storage engine]
SHOW FULL COLUMNS FROM `markjacobsen_options`

WordPress database error: [Got error 28 from storage engine]
SHOW FULL COLUMNS FROM `markjacobsen_options`

Want to generate the equivalent of a GUID or UUID in DB2? The closest you’ll get is with GENERATE_UNIQUE(), but beware that you need to do some conversion on it as the value is “BIT DATA” and not character data. To put the value into a typical CHAR or VARCHAR field (like you would with a java UUID), use this…

select TRIM(CHAR(HEX(GENERATE_UNIQUE()))) from sysibm.sysdummy1;

I should probably also mention that there is the IDENTITY and SEQUENCE, but the GENERATE_UNIQUE() function is the closest you’ll get to a GUID or UUID.

Like this? Consider joining my mailing list, or at least using my affiliate link when buying from Amazon 🙂

You or someone you know looking to buy or sell?

WordPress database error: [Got error 28 from storage engine]
SHOW FULL COLUMNS FROM `markjacobsen_options`

WordPress database error: [Got error 28 from storage engine]
SHOW FULL COLUMNS FROM `markjacobsen_options`

WordPress database error: [Got error 28 from storage engine]
SHOW FULL COLUMNS FROM `markjacobsen_options`

WordPress database error: [Got error 28 from storage engine]
SHOW FULL COLUMNS FROM `markjacobsen_options`

WordPress database error: [Got error 28 from storage engine]
SHOW FULL COLUMNS FROM `markjacobsen_options`

WordPress database error: [Got error 28 from storage engine]
SHOW FULL COLUMNS FROM `markjacobsen_options`

Leave a Reply