开发者

Is there a way to create an auto-incrementing Guid Primary Key in an Oracle database?

开发者 https://www.devze.com 2022-12-20 17:24 出处:网络
I mostly work with sql-server (when I do work with databases) and I am trying to learn pl-sql. Is there any equivalent to sql-开发者_开发问答server\'s auto-generated Guid as primary keys in Oracle?You

I mostly work with sql-server (when I do work with databases) and I am trying to learn pl-sql.

Is there any equivalent to sql-开发者_开发问答server's auto-generated Guid as primary keys in Oracle?


You can use SYS_GUID() to generate a GUID, and use it as DEFAULT value of a column:

CREATE TABLE test_table (
  uid_col RAW(32) DEFAULT SYS_GUID(),
  some_val VARCHAR2(10)
);

EDIT: See answers to this question for more details.


Make char or varchar2 column data type overwise raw to pass future troubles.

0

精彩评论

暂无评论...
验证码 换一张
取 消