2013-08-16 207 views

回答

31

如果你問關於SQL * Plus命令(show create table table_name並不似乎是一個SQL語句),你可以使用desc命令

SQL> desc emp 
Name          Null? Type 
----------------------------------------- -------- ---------------------------- 
EMPNO          NOT NULL NUMBER(4) 
ENAME            VARCHAR2(10) 
JOB            VARCHAR2(9) 
MGR            NUMBER(4) 
HIREDATE           DATE 
SAL            NUMBER(7,2) 
COMM            NUMBER(7,2) 
DEPTNO            NUMBER(2) 

如果你真的想要一個SQL語句,你可以使用在dbms_metadata

1 select dbms_metadata.get_ddl('TABLE', 'EMP', 'SCOTT') 
    2* from dual 
SQL>/

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 COMPUTE STATISTICS 
    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" 
    ALTER INDEX "SCOTT"."PK_EMP" UNUSABLE 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" 
    CACHE 

根據您所使用的工具,你可能需要運行set long 10000第一,它告訴SQL * Plus來顯示第一10,000字節所選擇的任何LOB的。如果您的DDL較長,請設置較大的值。

5

使用DESC

DESC mytable 

會告訴你的列,但遺憾的是創建語句中使用標準的Oracle工具不可用。

+2

遞減命令不會顯示限制和鍵和索引 – nightograph

+0

@nightograph問題不要求限制和鑰匙;它只要求*表定義(列與他們的數據類型等)* – Bohemian

+3

問題是在Oracle中要求相當於「show create table」,因爲「show create」顯示鍵索引而DESC不等同,DESC不等同 – nightograph

5

SQL>設定得長1000

SQL>設置頁面大小0

SQL>選擇DBMS_METADATA.GET_DDL( '表', '表名'[ 'SCHEMA'])從DUAL

3

如果你正在使用PL/SQL Developer;右鍵單擊表格,選擇視圖,在視圖窗口的右下角點擊'查看SQL'按鈕。

0

DDL爲我工作,更簡單的你需要的是寫DDL (SCHEMA_OWNER).(TABLE_NAME) ...例如ddl HR.LOCATIONS; .... HR是模式LOCATION是表名...確保你寫兩個SCHEMA名稱和表NAME在這裏建都輸出將是

CREATE TABLE "HR"."LOCATIONS" 
( "LOCATION_ID" NUMBER(4,0), 
"STREET_ADDRESS" VARCHAR2(40), 
"POSTAL_CODE" VARCHAR2(12), 
"CITY" VARCHAR2(30) CONSTRAINT "LOC_CITY_NN" NOT NULL ENABLE, 
"STATE_PROVINCE" VARCHAR2(25), 
"COUNTRY_ID" CHAR(2), 
CONSTRAINT "LOC_ID_PK" PRIMARY KEY ("LOCATION_ID") 
USING INDEX PCTFREE 10 INITRANS 2 MAXTRANS 255 NOLOGGING COMPUTE 
STATISTICS 
STORAGE(INITIAL 65536 NEXT 1048576 MINEXTENTS 1 MAXEXTENTS 2147483645 
PCTINCREASE 0 FREELISTS 1 FREELIST GROUPS 1 BUFFER_POOL DEFAULT 
FLASH_CACHE DEFAULT CELL_FLASH_CACHE DEFAULT) 
TABLESPACE "EXAMPLE" ENABLE, 
CONSTRAINT "LOC_C_ID_FK" FOREIGN KEY ("COUNTRY_ID") 
    REFERENCES "HR"."COUNTRIES" ("COUNTRY_ID") ENABLE 
) SEGMENT CREATION IMMEDIATE 
PCTFREE 10 PCTUSED 40 INITRANS 1 MAXTRANS 255 NOCOMPRESS NOLOGGING 
STORAGE(INITIAL 65536 NEXT 1048576 MINEXTENTS 1 MAXEXTENTS 2147483645 
PCTINCREASE 0 FREELISTS 1 FREELIST GROUPS 1 BUFFER_POOL DEFAULT 
FLASH_CACHE DEFAULT CELL_FLASH_CACHE DEFAULT) 
TABLESPACE "EXAMPLE" ; 
COMMENT ON COLUMN "HR"."LOCATIONS"."LOCATION_ID" IS 'Primary key of 
locations table'; 
COMMENT ON COLUMN "HR"."LOCATIONS"."STREET_ADDRESS" IS 'Street address 
of an office, warehouse, or production site of a company. 
Contains building number and street name'; 
COMMENT ON COLUMN "HR"."LOCATIONS"."POSTAL_CODE" IS 'Postal code of 
the 
location of an office, warehouse, or production site 
of a company. '; 
COMMENT ON COLUMN "HR"."LOCATIONS"."CITY" IS 'A not null column that 
shows city where an office, warehouse, or 
production site of a company is located. '; 
COMMENT ON COLUMN "HR"."LOCATIONS"."STATE_PROVINCE" IS 'State or 
Province where an office, warehouse, or production site of a 
company is located.'; 
COMMENT ON COLUMN "HR"."LOCATIONS"."COUNTRY_ID" IS 'Country where an 
office, warehouse, or production site of a company is 
located. Foreign key to country_id column of the countries table.'; 
COMMENT ON TABLE "HR"."LOCATIONS" IS 'Locations table that contains 
specific address of a specific office, 
warehouse, and/or production site of a company. Does not store 
addresses/
locations of customers. Contains 23 rows; references with the 
departments and countries tables. '; 
CREATE INDEX "HR"."LOC_CITY_IX" ON "HR"."LOCATIONS" ("CITY") 
PCTFREE 10 INITRANS 2 MAXTRANS 255 NOLOGGING COMPUTE STATISTICS 
STORAGE(INITIAL 65536 NEXT 1048576 MINEXTENTS 1 MAXEXTENTS 2147483645 
PCTINCREASE 0 FREELISTS 1 FREELIST GROUPS 1 BUFFER_POOL DEFAULT 
FLASH_CACHE DEFAULT CELL_FLASH_CACHE DEFAULT) 
TABLESPACE "EXAMPLE" ; 
CREATE INDEX "HR"."LOC_COUNTRY_IX" ON "HR"."LOCATIONS" ("COUNTRY_ID") 
PCTFREE 10 INITRANS 2 MAXTRANS 255 NOLOGGING COMPUTE STATISTICS 
STORAGE(INITIAL 65536 NEXT 1048576 MINEXTENTS 1 MAXEXTENTS 2147483645 
PCTINCREASE 0 FREELISTS 1 FREELIST GROUPS 1 BUFFER_POOL DEFAULT 
FLASH_CACHE DEFAULT CELL_FLASH_CACHE DEFAULT) 
TABLESPACE "EXAMPLE" ; 
CREATE INDEX "HR"."LOC_STATE_PROVINCE_IX" ON "HR"."LOCATIONS" 
("STATE_PROVINCE") 
PCTFREE 10 INITRANS 2 MAXTRANS 255 NOLOGGING COMPUTE STATISTICS 
STORAGE(INITIAL 65536 NEXT 1048576 MINEXTENTS 1 MAXEXTENTS 2147483645 
PCTINCREASE 0 FREELISTS 1 FREELIST GROUPS 1 BUFFER_POOL DEFAULT 
FLASH_CACHE DEFAULT CELL_FLASH_CACHE DEFAULT) 
TABLESPACE "EXAMPLE" ; 
+0

未知的命令,這在Oracle中不適用於我。 – jDub9

+0

你在SQL開發人員中輸入這個命令嗎?或sql plus ...還要記住,必須使用點名鍵入模式名稱,然後輸入表格名稱...例如'ddl HR.EMPLOYEES;'確保模式名稱和表格使用大寫字母。 –

+0

SQL Developer,它們都是大寫字母,但可能是我的表格是在架構下方「其他用戶」部分的30之一下創建的。 – jDub9