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

霸气de小男生 提交于 2019-12-20 01:58:35

问题


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?


回答1:


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.




回答2:


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



来源:https://stackoverflow.com/questions/2284738/is-there-a-way-to-create-an-auto-incrementing-guid-primary-key-in-an-oracle-data

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!