得到当前用户的所有表的建表语句,要求是可以执行的用户必须有SELECT ANY TABLE权限
,缺点是对索引的创建作的并不好,没有加入索引
参考的是shiqiguo 网友的一篇帖子
create or replace procedure get_table_ddl
AUTHID CURRENT_USER
as
/**************************************************************
函数名称:get_table_ddl
函数功能:得到所有表建表的DDL语句
**************************************************************/
file_handle UTL_FILE.FILE_TYPE;
l_user varchar2(30); --表的schema的名称
l_tablename varchar2(50); --表的名称
--得到用户的所有的表
cursor table_cur is
select table_name
from user_tables;
--得到表的列的名称的游标
cursor snatch_columns is select
owner,
table_name,
column_name,
data_type,
data_length,
data_precision,
data_scale,
data_default,
nullable
from all_tab_columns
where table_name = l_tablename
and owner= l_user
order by column_id;
--得到表的索引的信息的游标
CURSOR constraint_index is select
a.table_owner,
a.index_name,
a.table_owner,
a.table_name,
a.uniqueness,
a.tablespace_name,
a.ini_trans,
a.max_trans,
a.initial_extent,
a.next_extent,
a.min_extents,
a.max_extents,
a.pct_increase,
a.pct_free
from user_indexes a ,user_constraints b
where a.table_owner =l_user and a.table_name =l_tablename and a.table_name=b.table_name
and a.index_name=b.constraint_name and b.