java获取一个oracle表的创建的sql语句:
直接通过jdbc调用: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 COMPUTE STATISTICS
STORAGE(INITIAL 65536 NEXT 1048576 MINEXTENTS 1 MAXEXTENTS 2147483645
PCTINCREASE 0 FREELISTS 1 FREELIST GROUPS 1 BUFFER_POOL DEFAULT)
TABLESPACE "USERS" ENABLE,
CONSTRAINT "FK_DEPTNO" FOREIGN KEY ("DEPTNO")
REFERENCES "SCOTT"."DEPT" ("DEPTNO") 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 "USERS"
JDBC 连接后,执行SQL
String sql="Select Dbms_Metadata.Get_Ddl('TABLE', 'TABLE_NAME', 'OWNER')
From Dual"; //用来获取建表
sql = "Select Dbms_Metadata.Get_Ddl('INDEX', 'INDEX_NAME', 'OWNER')
From Dual;" //用来获取索引
SELECT DBMS_METADATA.GET_DDL('TABLE','HELP') FROM DUAL;
为什么不在数据库里直接看?