简体   繁体   English

id 的 Oracle DB 数据类型

[英]Oracle DB data type for id

generally in postgrest the uuid data type is used for the id,通常在 postgrest 中,uuid 数据类型用于 id,

create table "users"
(
    "id"         uuid                           not null,
    "password"   varchar(255)                   not null,
    "name"       varchar(255)                   not null,
    "surname"    varchar(255)                   not null,
    "created_at" timestamp  null,
    "updated_at" timestamp  null,
    "deleted_at" timestamp  null
);
alter table "users"
    add primary key ("id");    

but in oracle it gives me an error:但在 oracle 中它给了我一个错误:

ORA-00902: invalid datatype Blockquote ORA-00904: "id": invalid identifier ORA-00902: 无效的数据类型 Blockquote ORA-00904: “id”: 无效的标识符

So, what type of data is recommended to use?那么,推荐使用什么类型的数据呢? Because BIGINT is not allowed either.因为 BIGINT 也是不允许的。 Is only NUMBER used?是否只使用了 NUMBER?

So, what type of data is recommended to use?那么,推荐使用什么类型的数据呢?

Whatever is most appropriate for your business case.最适合您的业务案例的任何内容。


  • If you have data that is uniquely identified by a short human-readable string then you can use VARCHAR2 or CHAR as a primary key.如果您的数据由人类可读的短字符串唯一标识,则可以使用VARCHAR2CHAR作为主键。
  • If you have data that is uniquely identified by a numeric column then use a NUMBER .如果您有由数字列唯一标识的数据,则使用NUMBER
  • If you have one value-per-second (or day) then you could use a DATE .如果您有一个每秒(或一天)的值,那么您可以使用DATE

If you are generating a surrogate primary key then:如果您要生成代理主键,则:

  • If you want to use an IDENTITY column then you will need a NUMBER .如果您想使用IDENTITY列,那么您将需要一个NUMBER
  • If you want to generate a GUID then you can use a RAW and default to SYS_GUID() or could use a VARCHAR2 or CHAR for a formatted GUID.如果要生成 GUID,则可以使用RAW并默认为SYS_GUID() ,或者可以使用VARCHAR2CHAR作为格式化的 GUID。

The point is that there is no recommended data type for a primary key;关键是没有推荐的主键数据类型; it is whatever is most appropriate for the particular business case that you are implementing.它是最适合您正在实施的特定业务案例的任何内容。

For storing an UUID, you can use the field types VARCHAR(36) or VARCHAR2(36) .要存储 UUID,您可以使用字段类型VARCHAR(36)VARCHAR2(36)

Why?为什么?
An UUID is a 36-character string , that contains hexadecimal characters (0-9, AF) with sections separated by - UUID 是一个 36 个字符的字符串,包含十六进制字符(0-9,AF),各部分之间用-分隔

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM