如何用对象类型创建表?

时间:2019-06-24 13:53:44

标签: sql oracle user-defined-types

我无法理解代码中的错误:

create table insured_employee (of insured_employee_type scope for (employee_ref) is employee);

表格:

create type insured_employee_type as object (
control_number number(9),
contract CLOB,
employee_ref REF employee_type );

类型:

create type employee_type as object(
ssn number(9),
name varchar2(35),
address varchar2(70),
resume CLOB);

错误:

Error starting at line : 32 in command -
create table insured_employee (of insured_employee_type scope for (employee_ref) is employee)
Error report -
ORA-00904: : invalid identifier
00904. 00000 -  "%s: invalid identifier"

1 个答案:

答案 0 :(得分:2)

您要

create table insured_employee of insured_employee_type (
  control_number PRIMARY KEY,
  employee_ref   SCOPE IS employees
);

Oracle设置

CREATE TYPE employee_type IS OBJECT(
  id         NUMBER(8,0),
  first_name VARCHAR2(100),
  last_name  VARCHAR2(100)
);

CREATE TABLE employees OF employee_type(
  id PRIMARY KEY
);

create type insured_employee_type as object (
  control_number number(9),
  contract       CLOB,
  employee_ref   REF employee_type
);

db <>提琴here