创建表有多少种方法?
CREATE TABLE AS SELECT * from table;
DMP
SQLLDR
...
这里介绍一种不常用的方法(使用with .. as建表):
22:10:22 SCOTT@cry> create table dept60_bonuses as with t
22:11:03 2 (select 103 as employee_id,0 as bonus_amt from dual
22:11:49 3 union all
22:11:52 4 select 104 as employee_id,100 as bonus_amt from dual
22:12:07 5 union all
22:12:09 6 select 105 as employee_id,0 as bonus_amt from dual
22:12:21 7 )
22:12:24 8 select * from t;
Table created.
Elapsed: 00:00:00.10
22:12:30 SCOTT@cry> select * from dept60_bonuses;
EMPLOYEE_ID BONUS_AMT
----------- ----------
103 0
104 100
105 0
这样表就建立了,让我们来观察一下表结构以及表的创建信息.
22:15:54 SCOTT@cry> set lines 80
22:15:59 SCOTT@cry> desc dept60_bonuses
Name Null? Type
----------------------------------------- -------- -------------
EMPLOYEE_ID NUMBER
BONUS_AMT NUMBER
22:19:38 SYS@cry> set long 5000
22:21:15 SYS@cry> /
DBMS_METADATA.GET_DDL('TABLE','DEPT60_BONUSES','SCOTT')
--------------------------------------------------------------------------------
CREATE TABLE "SCOTT"."DEPT60_BONUSES"
( "EMPLOYEE_ID" NUMBER,
"BONUS_AMT" NUMBER
) SEGMENT CREATION IMMEDIATE
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 FLASH_CACHE DE
FAULT CELL_FLASH_CACHE DEFAULT)
TABLESPACE "USERS"
让我们来对比一下正常的表
22:21:18 SYS@cry> select dbms_metadata.get_ddl('TABLE','EMP','SCOTT') from dual;
DBMS_METADATA.GET_DDL('TABLE','EMP','SCOTT')
--------------------------------------------------------------------------------
CREATE TABLE "SCOTT"."EMP"
( "EMPNO" NUMBER(4,0),
"ENAME" VARCHAR2(10),
"JOB" VARCHAR2(9),
"MGR" NUMBER(4,0),
"HIREDATE" DATE,
"SAL" NUMBER(7,2),
"COMM" NUMBER(7,2),
"DEPTNO" NUMBER(2,0),
CONSTRAINT "PK_EMP" 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 FLASH_CACHE DE
FAULT CELL_FLASH_CACHE DEFAULT)
TABLESPACE "USERS" ENABLE,
CONSTRAINT "FK_DEPTNO" FOREIGN KEY ("DEPTNO")
REFERENCES "SCOTT"."DEPT" ("DEPTNO") ENABLE
) SEGMENT CREATION IMMEDIATE
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 FLASH_CACHE DE
FAULT CELL_FLASH_CACHE DEFAULT)
TABLESPACE "USERS"
和正常表差不多,只是没有索引和约束而已。