create table EmpTest ( empNo integer not null, lastName varchar2(30) not null, firstName varchar2(20) not null, job varchar2(9) ’ hireDate date ’ isActive number(1) constraint EmpTest_CK1 check (isActive in (0,1)) , salary number(9,2) , commision number(9,2) , deptNo number(2) , constraint EmpTest_PK primary key (empNo), constraint EmpTest_AK1 unique (lastName, firstName) ); create index EmpTest_HireDate_Salary on EmpTest ( salary, hireDate ); |
select index_name, index_type, uniqueness from user_indexes where table_name = ’EMPTEST’; |
索引名称 | 索引类型 | 唯一性 |
EMPTEST_AK1 | NORMAL | UNIQUE |
EMPTEST_HIREDATE_SALARY | NORMAL | NONUNIQUE |
EMPTEST_PK | NORMAL | UNIQUE |
约束名称 | 约束类型 | 索引名称 |
SYS_C002144065 | C | |
SYS_C002144066 | C | |
SYS_C002144067 | C | |
EMPTEST_CK1 | C | |
EMPTEST_PK | P | EMPTEST_PK |
EMPTEST_AK1 | U | EMPTEST_AK1 |
declare vClob clob; vLongString varchar2(32767); vOffSet pls_integer := 0; vLength pls_integer := 0; vTable varchar2(30) := ’EmpTest’; procedure Show (pVariable varchar2, pLineSize pls_integer := 80) is begin dbms_output.enable(1000000); if (length(pVariable) > pLineSize) then dbms_output.put_line(substr(pVariable, 1, pLineSize)); Show(substr(pVariable, pLineSize + 1), pLineSize); else dbms_output.put_line(pVariable); end if; end Show; begin -- 获取 DDL vClob := dbms_metadata.get_ddl(’TABLE’, upper(vTable)); -- 获取 CLOB 长度 vLength := dbms_lob.GetLength(vClob); dbms_output.put_line(’DDL length: ’ || to_char(vLength)); vOffSet := 1; dbms_lob.read(vClob, vLength, vOffSet, vLongString); -- 关闭 CLOB if (dbms_lob.isOpen(vClob) > 0) then dbms_lob.close(vClob); end if; Show(vLongString, 80); end; |
DDL length: 461 CREATE TABLE "BORIS"."EMPTEST" ( "EMPNO" NUMBER(*,0) NOT NULL ENABLE, "LASTNAME" VARCHAR2(30) NOT NULL ENABLE, "FIRSTNAME" VARCHAR2(20) NOT NULL ENABLE, "JOB" VARCHAR2(9), "HIREDATE" DATE, "ISACTIVE" NUMBER(1,0), "SALARY" NUMBER(9,2), "COMMISION" NUMBER(9,2), "DEPTNO" NUMBER(2,0), CONSTRAINT "EMPTEST_CK1" CHECK (isActive in (0,1)) ENABLE, CONSTRAINT "EMPTEST_PK" PRIMARY KEY ("EMPNO") USING INDEX PCTFREE 10 INITRANS 2 MAXTRANS 255 STORAGE(INITIAL 65536 NEXT 1048576 MINEXTENTS 1 MAXEXTENTS 2147483645 PCTINCREASE 0 FREELISTS 1 FREELIST GROUPS 1 BUFFER_POOL DEFAULT) TABLESPACE "TOOLS" ENABLE, CONSTRAINT "EMPTEST_AK1" UNIQUE ("LASTNAME", "FIRSTNAME") USING INDEX PCTFREE 10 INITRANS 2 MAXTRANS 255 STORAGE(INITIAL 65536 NEXT 1048576 MINEXTENTS 1 MAXEXTENTS 2147483645 PCTINCREASE 0 FREELISTS 1 FREELIST GROUPS 1 BUFFER_POOL DEFAULT) TABLESPACE "TOOLS" ENABLE) PCTFREE 10 PCTUSED 40 INITRANS 1 MAXTRANS 255 NOCOMPRESS LOGGING STORAGE(INITIAL 65536 NEXT 1048576 MINEXTENTS 1 MAXEXTENTS 2147483645 PCTINCREASE 0 FREELISTS 1 FREELIST GROUPS 1 BUFFER_POOL DEFAULT) TABLESPACE "TOOLS" |
它运行的情况太好了,返回的数据表的DDL字符串带有主键EmpTest_PK、备用键EmpTest_AK1和检查约束EmpTest_CK1。它建立了两个唯一的索引来支持主键和备用键约束。这不是你需要的结果:你需要一个表,但是为了加快数据载入速度,它不要包含约束和索引。只有在数据载入工作完成以后,你才建立索引和约束。
保证对象的定义独立的另外一个原因在于灵活性:你可能需要改变对象建立的次序。
现在可以设计一个数据结构来存储对象的元数据了。
[1]