关于导出oracle多个表的建表语句DLL,生成.sql语句。
--('TABLE','LINE','ODS_XX')这里面的表和用户都需要大写。
如果表名用户名不大写会报这个错误:对象 "emp" 属于类型 TABLE, 在方案 "scott" 中未找到
亲测的代码:
set long 90000;
set linesize 4000;
set pagesize 4000;
spool table.sql
select dbms_metadata.get_ddl('TABLE','LINE','ODS_XX') from dual;
spool off
模仿plsql导出用户对象的详细的代码:
set pagesize 0
set long 90000
set feedback off
set echo off
--数据库登录
conn testgdzc/testgdzc@testjjgdzc
--导出文件名称
spool E:\table.sql
--输出信息采用缩排或换行格式化
EXEC DBMS_METADATA.set_transform_param(DBMS_METADATA.session_transform, 'PRETTY', TRUE);
--确保每个语句都带分号
EXEC DBMS_METADATA.set_transform_param(DBMS_METADATA.session_transform, 'SQLTERMINATOR', TRUE);
--关闭表索引、外键等关联(后面单独生成)
EXEC DBMS_METADATA.set_transform_param(DBMS_METADATA.session_transform, 'CONSTRAINTS', FALSE);
EXEC DBMS_METADATA.set_transform_param(DBMS_METADATA.session_transform, 'REF_CONSTRAINTS', FALSE);
EXEC DBMS_METADATA.set_transform_param(DBMS_METADATA.session_transform, 'CONSTRAINTS_AS_ALTER', FALSE);
--关闭存储、表空间属性
EXEC DBMS_METADATA.set_transform_param(DBMS_METADATA.session_transform, 'STORAGE', FALSE);
EXEC DBMS_METADATA.set_transform_param(DBMS_METADATA.session_transform, 'TABLESPACE', FALSE);
--关闭创建表的PCTFREE、NOCOMPRESS等属性
EXEC DBMS_METADATA.set_transform_param(DBMS_METADATA.session_transform, 'SEGMENT_ATTRIBUTES', FALSE);
select dbms_metadata.get_ddl('TABLE','PROJECT_STAGE_CONFIG') from dual;
select dbms_metadata.get_ddl('TABLE','PROJECT_LIBRARY_TEST') from dual;
select dbms_metadata.get_ddl('TABLE','PROJECT_UNIT_CONFIG') from dual;
--获取表注释
SELECT DBMS_LOB.substr(DBMS_METADATA.get_dependent_ddl ('COMMENT', 'PROJECT_STAGE_CONFIG'))
FROM (SELECT distinct 'PROJECT_STAGE_CONFIG'
FROM user_col_comments
WHERE comments IS NOT NULL
)
;
spool off;
alter table SP_PD_ANTI_ACCIDENT add(gsdm varchar2(6),jlsj date);
- 不单单是获取到了创建的基本字段的语句,还有主键,约束,外键,存储参数,表空间等,如果这些你不需要,都是可以进行过滤的,例如我过滤掉主键、外键、存储信息
使用如下语句:
exec DBMS_METADATA.SET_TRANSFORM_PARAM(DBMS_METADATA.SESSION_TRANSFORM,'REF_CONSTRAINTS',false);
exec DBMS_METADATA.SET_TRANSFORM_PARAM(DBMS_METADATA.SESSION_TRANSFORM,'CONSTRAINTS',false);
exec DBMS_METADATA.SET_TRANSFORM_PARAM(DBMS_METADATA.SESSION_TRANSFORM,'STORAGE',false);
|
Object Type |
Name |
Datatype |
Meaning |
|
All objects |
PRETTY |
BOOLEAN |
If TRUE, format the output with indentation and line feeds. Defaults toTRUE. |
|
All objects |
SQLTERMINATOR |
BOOLEAN |
If TRUE, append a SQL terminator (; or /) to each DDL statement. Defaults to FALSE. |
|
TABLE |
SEGMENT_ATTRIBUTES |
BOOLEAN |
If TRUE, include segment attributes clauses in the DDL. If FALSE, omit them. Defaults to TRUE. |
|
TABLE |
STORAGE |
BOOLEAN |
If TRUE, include storage clauses in the DDL. If FALSE, omit them. Defaults to TRUE. (Ignored if SEGMENT_ATTRIBUTES is FALSE.) |
|
TABLE |
TABLESPACE |
BOOLEAN |
If TRUE, include tablespace clauses in the DDL. If FALSE, omit them. (Ignored if SEGMENT_ATTRIBUTES is FALSE.) Defaults to TRUE. |
|
TABLE |
CONSTRAINTS |
BOOLEAN |
If TRUE, include all non-referential table constraints in the DDL. If FALSE, omit them. Defaults to TRUE. |
|
TABLE |
REF_CONSTRAINTS |
BOOLEAN |
If TRUE, include all referential constraints (foreign keys) in the DDL. IfFALSE, omit them. Defaults to TRUE. |
|
TABLE |
CONSTRAINTS_AS_ALTER |
BOOLEAN |
If TRUE, include table constraints as separate ALTER TABLE (and, if necessary, CREATE INDEX) statements. If FALSE, specify table constraints as part of the CREATE TABLE statement. Defaults to FALSE. Requires thatCONSTRAINTS be TRUE. |
|
TABLE |
OID |
BOOLEAN |
If TRUE, include the OID clause for object tables in the DDL. If FALSE, omit it. Defaults to FALSE. |
|
TABLE |
SIZE_BYTE_KEYWORD |
BOOLEAN |
If TRUE, include the BYTE keyword as part of the size specification ofCHAR and VARCHAR2 columns that use byte semantics. If FALSE, omit the keyword. Defaults to FALSE. |
|
TABLE, INDEX |
PARTITIONING |
BOOLEAN |
If TRUE, include partitioning clauses in the DDL. If FALSE, omit them. Defaults to TRUE. |
|
INDEX, CONSTRAINT,ROLLBACK_SEGMENT,CLUSTER, TABLESPACE |
SEGMENT_ATTRIBUTES |
BOOLEAN |
If TRUE, include segment attributes clauses (physical attributes, storage attributes, tablespace, logging) in the DDL. If FALSE, omit them. Defaults to TRUE. |
|
INDEX, CONSTRAINT,ROLLBACK_SEGMENT, CLUSTER |
STORAGE |
BOOLEAN |
If TRUE, include storage clauses in the DDL. If FALSE, omit them. (Ignored if SEGMENT_ATTRIBUTES is FALSE.) Defaults to TRUE. |
|
INDEX, CONSTRAINT,ROLLBACK_SEGMENT, CLUSTER |
TABLESPACE |
BOOLEAN |
If TRUE, include tablespace clauses in the DDL. If FALSE, omit them. (Ignored if SEGMENT_ATTRIBUTES is FALSE.) Defaults to TRUE. |
|
TYPE |
SPECIFICATION |
BOOLEAN |
If TRUE, include the type specification in the DDL. If FALSE, omit it. Defaults to TRUE. |
|
TYPE |
BODY |
BOOLEAN |
If TRUE, include the type body in the DDL. If FALSE, omit it. Defaults toTRUE. |
|
TYPE |
OID |
BOOLEAN |
If TRUE, include the OID clause in the DDL. If FALSE, omit it. Defaults toFALSE. |
|
PACKAGE |
SPECIFICATION |
BOOLEAN |
If TRUE, include the package specification in the DDL. If FALSE, omit it. Defaults to TRUE. |
|
PACKAGE |
BODY |
BOOLEAN |
If TRUE, include the package body in the DDL. If FALSE, omit it. Defaults to TRUE. |
|
VIEW |
FORCE |
BOOLEAN |
If TRUE, use the FORCE keyword in the CREATE VIEW statement. If FALSE, do not use the FORCE keyword in the CREATE VIEW statement. Defaults toTRUE. |
|
OUTLINE |
INSERT |
BOOLEAN |
If TRUE, include the INSERT statements into the OL$ dictionary tables that will create the outline and its hints. If FALSE, omit a CREATE OUTLINEstatement. Defaults to FALSE. Note: This object type is being deprecated. |
|
All objects |
DEFAULT |
BOOLEAN |
Calling SET_TRANSFORM_PARAM with this parameter set to TRUE has the effect of resetting all parameters for the transform to their default values. Setting this FALSE has no effect. There is no default. |
|
All objects |
INHERIT |
BOOLEAN |
If TRUE, inherits session-level parameters. Defaults to FALSE. If an application calls ADD_TRANSFORM to add the DDL transform, then by default the only transform parameters that apply are those explicitly set for that transform handle. This has no effect if the transform handle is the session transform handle. |
|
ROLE |
REVOKE_FROM |
Text |
The name of a user from whom the role must be revoked. If this is a non-null string and if the CREATE ROLE statement grants you the role, aREVOKE statement is included in the DDL after the CREATE ROLEstatement. Note: When you issue a CREATE ROLE statement, Oracle may grant you the role. You can use this transform parameter to undo the grant. Defaults to null string. |
|
TABLESPACE |
REUSE |
BOOLEAN |
If TRUE, include the REUSE parameter for datafiles in a tablespace to indicate that existing files can be reused. If FALSE, omit the REUSEparameter. Defaults to FALSE. |
|
CLUSTER, INDEX,ROLLBACK_SEGMENT, TABLE,TABLESPACE |
PCTSPACE |
NUMBER |
A number representing the percentage by which space allocation for the object type is to be modified. The value is the number of one-hundreths of the current allocation. For example, 100 means 100%. If the object type is TABLESPACE, the following size values are affected: - in file specifications, the value of SIZE - MINIMUM EXTENT - EXTENT MANAGEMENT LOCAL UNIFORM SIZE For other object types, INITIAL and NEXT are affected. |
关于导出oracle多个表的建表语句DLL,生成.sql语句。的更多相关文章
- 批量导出hive表的建表语句
转的这里的 首先先导出所有的table表 hive -e "use xxxdb;show tables;" > tables.txt 然后再使用hive内置语法导出hive表 ...
- mysql添加删除索引,查看某个表的建表语句
查看某个表的建表语句 :show create table data_statdata; drop index ts on data_statdata; 索引是加速查询的主要手段,特别对于涉及多个表的 ...
- oracle查看执行最慢与查询次数最多的sql语句及其执行速度很慢的问题分析
oracle查看执行最慢与查询次数最多的sql语句 注:本文来源 于<oracle查看执行最慢与查询次数最多的sql语句> 前言 在ORACLE数据库应用调优中,一个SQL的执行次数/频率 ...
- 项目总结04:SQL批量导入数据:将具有多表关联的Excel数据,通过sql语句脚本的形式,导入到数据库
将具有多表关联的Excel数据,通过sql语句脚本的形式,导入到数据库 写在前面:本文用的语言是java:数据库是MySql: 需求:在实际项目中,经常会被客户要求,做批量导入数据:一般的简单的单表数 ...
- 优化、分析Mysql表读写、索引等操作的sql语句效率优化问题
为什么要优化: 随着实际项目的启动,数据库经过一段时间的运行,最初的数据库设置,会与实际数据库运行性能会有一些差异,这时我们 就需要做一个优化调整. 数据库优化这个课题较大,可分为四大类: >主 ...
- Oracle笔记(十一) 建表、更新、查询综合练习
有某个学生运动会比赛信息的数据库,保存了如下的表: 运动员sporter(运动员编号sporterid,运动员姓名name,运动员性别sex,所属系号department) 项目item(项目编号it ...
- Oracle 获取 某个表的建表SQL
获取A表的创表SQL select dbms_metadata.get_ddl('TABLE','A') from dual
- HBase-建表(普通建表及预分区建表)
package com.hbase.HBaseAdmin; import java.io.IOException; import org.apache.hadoop.conf.Configuratio ...
- Oracle 行转列pivot 、列转行unpivot 的Sql语句总结
这个比较简单,用||或concat函数可以实现 select concat(id,username) str from app_user select id||username str from ap ...
- Oracle、DB2、SQLSERVER、Mysql、Access分页SQL语句梳理
最近把平时在项目中常用到的数据库分页sql总结了下.大家可以贴出分页更高效的sql语句.sqlserver分页 第一种分页方法 需用到的参数: pageSize 每页显示多少条数据 pageNumbe ...
随机推荐
- C++ STL基本容器的使用
C++中有两种类型的容器:顺序容器和关联容器.顺序容器主要有vector.list.deque等.其中vector表示一段连续的内存,基于数组实现,list表示非连续的内存,基于链表实现,deque与 ...
- C++学习笔记5——类的继承
简介: 通过继承联系在以前的类构成一种层次关系.通常在层次关系的根部有一个基类,其他类则直接或间接地从基类继承,这些继承得到的类称为类的派生类. 作用: 1.子类拥有父类的所有成员函数和成员变量. 2 ...
- 多目标遗传算法 ------ NSGA-II (部分源码解析) 目标函数值计算 eval.c
这部分比较简单,具体的函数数值计算是需要调用设定的目标函数的,此部分一个不能忽略的问题是 超出限制条件的处理 , 故对此加以解释. 首先是包装函数, 核心操作调用 evaluate_ind 实现 ...
- Watchcow
传送门 题目大意: 给你一幅连通的图,要求从起点1开始走,要经过每条边刚好两次,并且最终回到1起点. 思路:将无向图转换成有向图求欧拉回路. #include<cstdio> #defin ...
- WebSocket 支持的浏览器
http://caniuse.com/#feat=websockets
- 学渣上手 LaTeX 完成毕业论文
学渣上手 LaTeX 完成毕业论文 作为一个标准的学渣,虽然经历了一系列变故但最终还是使用 LaTeX 完成了我的毕业论文.要问我感想的话,就是——如果没有做好迎接比较陡峭的学习曲线以及各种打击人的小 ...
- Ubuntu中Samba的安装配置和使用[图文]
Samba服务在Ubuntu服务器版本中默认并没有安装. 1. Samba软件包的安装 使用源安装,在终端中输入如下命令: #sudo apt-get install samba#sudo apt-g ...
- sqlserver 时间格式化
SELECT CONVERT(varchar(), GETDATE(), ) :12AM SELECT CONVERT(varchar(), GETDATE(), ) // SELECT CONVER ...
- Google Java 风格 阅读随笔
官方文档:Google Java Style 中文翻译版:Google Java编程风格指南, Hawstein's Blog 可以先看官方文档,遇到不确定有疑问的,可以再对照翻译版本阅读,加深理解. ...
- Going Home - poj 2195(最小费用流 | 二分匹配)
题目大意:在一个网格里面有n个小男人和n个房子,现在想让每个小男人都有一个房子住,不过每个人移动一下都需要花费¥1,现在求出来最小的总花费.ps:可以认为网格的每个点都是很大的广场并且容纳所有的人,人 ...