Oracle中获取TABLE的DDL语句的方法-创新互联
获取表的DDL的方法
在获取表的DDL的时候,可以使用多种方法进行获取:
成都创新互联公司专注于企业成都全网营销推广、网站重做改版、钟楼网站定制设计、自适应品牌网站建设、H5技术、商城系统网站开发、集团公司官网建设、外贸营销网站建设、高端网站制作、响应式网页设计等建站业务,价格优惠性价比高,为钟楼等各大城市提供网站开发制作服务。1、利用 DBMS_METADATA.GET_DDL,获取表的 DDL 语句
2、imp.indexfile
3、impdp.sqlfile
1、利用 DBMS_METADATA.GET_DDL,获取表的 DDL 语句
方法1:
SQL PLUS中执行:
首先运行 set echo off set heading off set feedback off set verify off set pagesize 0 set linesize 132 define schema=&1 输入schema的名字 然后执行: define CR=chr(10) define TAB=chr(9) col x noprint col y noprint SELECT TABLE_NAME Y ,0 X ,'CREATE TABLE ' || RTRIM(TABLE_NAME) || '(' FROM DBA_TABLES WHERE OWNER = UPPER('&schema') UNION SELECT TC.TABLE_NAME Y ,COLUMN_ID X ,DECODE(COLUMN_ID, 1, ' ', ' ,') || RTRIM(COLUMN_NAME) || &TAB || &TAB || RTRIM(DATA_TYPE) || RTRIM(DECODE(DATA_TYPE, 'DATE', NULL, 'LONG', NULL, 'NUMBER', DECODE(TO_CHAR(DATA_PRECISION), NULL, NULL, '('), '(')) || RTRIM(DECODE(DATA_TYPE, 'DATE', NULL, 'CHAR', DATA_LENGTH, 'VARCHAR2', DATA_LENGTH, 'NUMBER', DECODE(TO_CHAR(DATA_PRECISION), NULL, NULL, TO_CHAR(DATA_PRECISION) || ',' || TO_CHAR(DATA_SCALE)), 'LONG', NULL, '******ERROR')) || RTRIM(DECODE(DATA_TYPE, 'DATE', NULL, 'LONG', NULL, 'NUMBER', DECODE(TO_CHAR(DATA_PRECISION), NULL, NULL, ')'), ')')) || &TAB || &TAB || RTRIM(DECODE(NULLABLE, 'N', 'NOT NULL', NULL)) FROM DBA_TAB_COLUMNS TC ,DBA_OBJECTS O WHERE O.OWNER = TC.OWNER AND O.OBJECT_NAME = TC.TABLE_NAME AND O.OBJECT_TYPE = 'TABLE' AND O.OWNER = UPPER('&schema') UNION SELECT TABLE_NAME Y ,999999 X ,')' || &CR || ' STORAGE(' || &CR || ' INITIAL ' || INITIAL_EXTENT || &CR || ' NEXT ' || NEXT_EXTENT || &CR || ' MINEXTENTS ' || MIN_EXTENTS || &CR || ' MAXEXTENTS ' || MAX_EXTENTS || &CR || ' PCTINCREASE ' || PCT_INCREASE || ')' || &CR || ' INITRANS ' || INI_TRANS || &CR || ' MAXTRANS ' || MAX_TRANS || &CR || ' PCTFREE ' || PCT_FREE || &CR || ' PCTUSED ' || PCT_USED || &CR || ' PARALLEL (DEGREE ' || RTRIM(DEGREE) || ') ' || &CR || ' TABLESPACE ' || RTRIM(TABLESPACE_NAME) || &CR || '/' || &CR || &CR FROM DBA_TABLES WHERE OWNER = UPPER('&schema') ORDER BY 1 ,2;
分享名称:Oracle中获取TABLE的DDL语句的方法-创新互联
分享地址:http://lswzjz.com/article/ccchoj.html