导出创建用户下各个对象数据结构的sql语句的脚本,包括表、视图、索引、约束等等
前言:
这是我用很长时间才写的存储包,其间经历了多次修改,以适应多种情况,今将其贡献出来,如果能读懂这个存储包,恭喜你,你的oracle知识已经达到一定程度了,而且这不失为一个学习oracle存储过程的模板,掌握它之后你可以自如的写存储包,存储过程,和函数了。
在我的实际工作中我发现它的功能很强,可以生成我们常用的对象的创建语句,这在很多情况下比较好用
1。想导出创建用户下的对象的sql语句。
2。有时我们用copy命令与create table as .... 命令在2个数据库之间建立一个用户的所有数据的拷贝时,只能拷贝数据,而如各个约束,索引则不能导过来,此时,该脚本生成的sql语句正好可以弥补这一缺点。
不好意思独享该脚本,共享出来,忘大家共同进步。
版权所有人: 徐玉金
备注:用户可以根据实际需要修改、使用、发布该脚本,但是不能修改版权所有人
适用的数据库:8i, 9i数据库下该脚本通用
功能:导出一个用户的数据结构,包括表、视图、索引、约束、存储过程、触发器、函数、序列等等的定义,并且每个定义为一个文件
导出的各个对象的定义格式比较规范。
如表的定义为:
prompt Create Table BBNACTIVEHISTORY
CREATE TABLE test(
USERID VARCHAR2(20) NOT NULL,
SPUSERID VARCHAR2(30) NOT NULL,
PRODUCTID VARCHAR2(20) NOT NULL,
GAMETYPE NUMBER NOT NULL,
STARTTIME DATE NOT NULL,
CHARGED CHAR(1) default 'N' NOT NULL
);
每个存储过程有多个参数,可以控制输出何种形式的内容,如可以只生成删除表的sql,可以在生成的创建表与索引的语句上加上storage子句等等。
运行 user_dll_sql.sql的准备工作:
1. 修改win_mkdir.bat文件,以便生成存放生成脚本的基本目录及其子目录
win_mkdir.bat文件生成上面所需要的所有目录
打开win_mkdir.bat文件,修改BASE_DIC变量的值,如c:/temp/,该目录是存放生成的脚本文件的基本目录
2. 运行 win_mkdir.bat文件创建必要的目录
3. 用sql*plus以想导出数据结构的用户登陆到数据库
运行user_dll_sql.sql 生成文件的路径文件,生成所有的ddl语句
运行文件时,将存放生成脚本的基本目录作为参数(与步骤1改的基本目录一样)传入, ?要根据需要改为实际的目录
SQL> @?/user_ddl_sql.sql c:/temp/
说明:
运行win_mkdir.bat,文件后,会自动在生成脚本的基本目录下产生如下目录:
procedures, functions, triggers, packages, temp_sql.
每个目录的作用如下:
procedures: 该目录存放存储过程, 有子目录separ_files, 该目录下的每个文件都是一个存储过程的源代码
functions: 该目录存放函数, 有子目录separ_files, 该目录下的每个文件都是一个函数的源代码
triggers: 该目录存放触发器, 有子目录separ_files, 该目录下的每个文件都是一个触发器的源代码
packages: 该目录存放包, 有子目录separ_files, 该目录下的每个文件都是一个包的源代码
有子目录separ_headbobdy_file, 该目录下的每个文件都是一个包的包头或包体的源代码
temp_sql:存放生成的临时文件
来自:
http://www.oracle.com.cn/viewthread.php?tid=69847&extra=page%3D1%26amp%3Bfilter%3Ddigest
这是我用很长时间才写的存储包,其间经历了多次修改,以适应多种情况,今将其贡献出来,如果能读懂这个存储包,恭喜你,你的oracle知识已经达到一定程度了,而且这不失为一个学习oracle存储过程的模板,掌握它之后你可以自如的写存储包,存储过程,和函数了。
在我的实际工作中我发现它的功能很强,可以生成我们常用的对象的创建语句,这在很多情况下比较好用
1。想导出创建用户下的对象的sql语句。
2。有时我们用copy命令与create table as .... 命令在2个数据库之间建立一个用户的所有数据的拷贝时,只能拷贝数据,而如各个约束,索引则不能导过来,此时,该脚本生成的sql语句正好可以弥补这一缺点。
不好意思独享该脚本,共享出来,忘大家共同进步。
版权所有人: 徐玉金
备注:用户可以根据实际需要修改、使用、发布该脚本,但是不能修改版权所有人
适用的数据库:8i, 9i数据库下该脚本通用
功能:导出一个用户的数据结构,包括表、视图、索引、约束、存储过程、触发器、函数、序列等等的定义,并且每个定义为一个文件
导出的各个对象的定义格式比较规范。
如表的定义为:
prompt Create Table BBNACTIVEHISTORY
CREATE TABLE test(
USERID VARCHAR2(20) NOT NULL,
SPUSERID VARCHAR2(30) NOT NULL,
PRODUCTID VARCHAR2(20) NOT NULL,
GAMETYPE NUMBER NOT NULL,
STARTTIME DATE NOT NULL,
CHARGED CHAR(1) default 'N' NOT NULL
);
每个存储过程有多个参数,可以控制输出何种形式的内容,如可以只生成删除表的sql,可以在生成的创建表与索引的语句上加上storage子句等等。
运行 user_dll_sql.sql的准备工作:
1. 修改win_mkdir.bat文件,以便生成存放生成脚本的基本目录及其子目录
win_mkdir.bat文件生成上面所需要的所有目录
打开win_mkdir.bat文件,修改BASE_DIC变量的值,如c:/temp/,该目录是存放生成的脚本文件的基本目录
2. 运行 win_mkdir.bat文件创建必要的目录
3. 用sql*plus以想导出数据结构的用户登陆到数据库
运行user_dll_sql.sql 生成文件的路径文件,生成所有的ddl语句
运行文件时,将存放生成脚本的基本目录作为参数(与步骤1改的基本目录一样)传入, ?要根据需要改为实际的目录
SQL> @?/user_ddl_sql.sql c:/temp/
说明:
运行win_mkdir.bat,文件后,会自动在生成脚本的基本目录下产生如下目录:
procedures, functions, triggers, packages, temp_sql.
每个目录的作用如下:
procedures: 该目录存放存储过程, 有子目录separ_files, 该目录下的每个文件都是一个存储过程的源代码
functions: 该目录存放函数, 有子目录separ_files, 该目录下的每个文件都是一个函数的源代码
triggers: 该目录存放触发器, 有子目录separ_files, 该目录下的每个文件都是一个触发器的源代码
packages: 该目录存放包, 有子目录separ_files, 该目录下的每个文件都是一个包的源代码
有子目录separ_headbobdy_file, 该目录下的每个文件都是一个包的包头或包体的源代码
temp_sql:存放生成的临时文件
- DEFINE file_dic=1
- CREATE TABLE temp_for_pkg_gen_sql4000_temp
- ( line_no NUMBER(38,0),
- object_type VARCHAR2(30),
- user_name VARCHAR2(30),
- object_name VARCHAR2(200),
- sql_text VARCHAR2(4000)
- );
- -- synonym, job, db_link, role, user_type
- CREATE TABLE temp_for_pkg_gen_sql2000_temp
- ( line_no NUMBER(38,0),
- object_type VARCHAR2(30),
- user_name VARCHAR2(30),
- object_name VARCHAR2(200),
- sql_text VARCHAR2(2000)
- );
- DELETE temp_for_pkg_gen_sql4000_temp;
- DELETE temp_for_pkg_gen_sql2000_temp;
- COMMIT;
- CREATE OR REPLACE PACKAGE pkg_gen_user_sql AS
- -- 产生start脚本
- PROCEDURE pro_gen_start_sql(p_v_file_path VARCHAR2 default 'C:/');
- FUNCTION fun_return_table_name_tab4(p_v_table_name VARCHAR2,
- p_n_col_max_len NUMBER) RETURN VARCHAR2;
- FUNCTION fun_return_table_name_tab8(p_v_table_name VARCHAR2,
- p_n_col_max_len NUMBER) RETURN VARCHAR2;
- -- generate sql for create tables;
- PROCEDURE pro_tab_sql_tab4(p_v_gen_drop_sql VARCHAR2 default 'T',
- p_v_gen_create_sql VARCHAR2 default 'T',
- p_v_gen_store_clause VARCHAR2 default 'T',
- p_v_display_prompt_info VARCHAR2 default 'T');
- PROCEDURE pro_tab_sql_tab8(p_v_gen_drop_sql VARCHAR2 default 'T',
- p_v_gen_create_sql VARCHAR2 default 'T',
- p_v_gen_store_clause VARCHAR2 default 'T',
- p_v_display_prompt_info VARCHAR2 default 'T');
- PROCEDURE pro_con_sql(p_v_con_type VARCHAR2 default 'ALL',
- p_v_gen_drop_sql VARCHAR2 default 'T',
- p_v_gen_create_sql VARCHAR2 default 'T',
- p_v_gen_null_chk VARCHAR2 default 'T',
- p_v_display_prompt_info VARCHAR2 default 'T');
- PROCEDURE pro_indx_sql(p_v_gen_drop_sql VARCHAR2 default 'T',
- p_v_gen_create_sql VARCHAR2 default 'T',
- p_v_gen_store_clause VARCHAR2 default 'T',
- p_v_gen_ts_only VARCHAR2 default 'F',
- p_v_display_prompt_info VARCHAR2 default 'T');
- -- 重建索引
- PROCEDURE pro_reb_indx_sql(p_v_gen_store_clause VARCHAR2 default 'T',
- p_v_rebuild_online VARCHAR2 default 'T',
- p_v_display_prompt_info VARCHAR2 default 'T');
- PROCEDURE pro_view_sql(p_v_gen_drop_sql VARCHAR2 default 'T',
- p_v_gen_create_sql VARCHAR2 default 'T',
- p_v_display_prompt_info VARCHAR2 default 'T');
- PROCEDURE pro_seq_max_val_sql(p_v_gen_drop_sql VARCHAR2 default 'T',
- p_v_gen_create_sql VARCHAR2 default 'T',
- p_v_display_prompt_info VARCHAR2 default 'T');
- PROCEDURE pro_seq_next_val_sql(p_v_gen_drop_sql VARCHAR2 default 'T',
- p_v_gen_create_sql VARCHAR2 default 'T',
- p_v_display_prompt_info VARCHAR2 default 'T');
- PROCEDURE pro_seq_init_val_sql(p_v_gen_drop_sql VARCHAR2 default 'T',
- p_v_gen_create_sql VARCHAR2 default 'T',
- p_v_display_prompt_info VARCHAR2 default 'T');
- PROCEDURE pro_synonym_sql(p_v_gen_drop_sql VARCHAR2 default 'T',
- p_v_gen_create_sql VARCHAR2 default 'T',
- p_v_display_prompt_info VARCHAR2 default 'T');
- PROCEDURE pro_job_sql(p_v_gen_drop_sql VARCHAR2 default 'T',
- p_v_gen_create_sql VARCHAR2 default 'T',
- p_v_display_prompt_info VARCHAR2 default 'T');
- PROCEDURE pro_dl_sql(p_v_gen_drop_sql VARCHAR2 default 'T',
- p_v_gen_create_sql VARCHAR2 default 'T',
- p_v_display_prompt_info VARCHAR2 default 'T');
- PROCEDURE pro_role_sql(p_v_gen_drop_sql VARCHAR2 default 'T',
- p_v_gen_create_sql VARCHAR2 default 'T',
- p_v_display_prompt_info VARCHAR2 default 'T');
- PROCEDURE pro_priv_sql(p_v_gen_drop_sql VARCHAR2 default 'T',
- p_v_gen_create_sql VARCHAR2 default 'T',
- p_v_display_prompt_info VARCHAR2 default 'T');
- PROCEDURE pro_pkgprofuntri_sql(p_v_gen_drop_sql VARCHAR2 default 'T',
- p_v_gen_create_sql VARCHAR2 default 'T',
- p_v_display_prompt_info VARCHAR2 default 'T',
- p_v_separ_file VARCHAR2 default 'T',
- p_v_file_path VARCHAR2 default 'C:/');
- END pkg_gen_user_sql;
- /
- show err
- show err
- CREATE OR REPLACE PACKAGE BODY pkg_gen_user_sql AS
- PROCEDURE pro_gen_start_sql(p_v_file_path VARCHAR2 default 'C:/') AS
- v_username VARCHAR2(30);
- v_object_type VARCHAR2(30);
- n_line_no NUMBER(10, 0);
- v_sql VARCHAR2(2000);
- v_prompt VARCHAR2(30);
- v_file_path VARCHAR2(600);
- v_notion char(1);
- PROCEDURE insert_rec(p_line_no INTEGER,
- p_object_type VARCHAR2,
- p_user_name VARCHAR2,
- p_view_name VARCHAR2,
- p_string VARCHAR2) IS
- BEGIN
- INSERT INTO temp_for_pkg_gen_sql2000_temp
- (line_no, object_type, user_name, object_name, sql_text)
- VALUES
- (p_line_no, p_object_type, p_user_name, p_view_name, p_string);
- END;
- BEGIN
- v_object_type := 'START_SQL';
- v_prompt := '-- prompt ';
- v_file_path := p_v_file_path;
- -- find the notion between the dictionary
- IF instr(p_v_file_path, '/') > 0 THEN
- v_notion := '/';
- ELSE
- v_notion := '/';
- END IF;
- IF substr(v_file_path, length(v_file_path)) <> v_notion THEN
- v_file_path := v_file_path || v_notion;
- END IF;
- SELECT username INTO v_username FROM user_users;
- DELETE temp_for_pkg_gen_sql2000_temp WHERE object_type = v_object_type;
- COMMIT;
- n_line_no := 1;
- v_sql := '@ ' || v_file_path || 'cre_tables.sql';
- insert_rec(n_line_no, v_object_type, v_username, v_object_type, v_sql);
- n_line_no := n_line_no + 1;
- v_sql := '@ ' || v_file_path || 'cre_sequences.sql';
- insert_rec(n_line_no, v_object_type, v_username, v_object_type, v_sql);
- n_line_no := n_line_no + 1;
- v_sql := '@ ' || v_file_path || 'cre_synonyms.sql';
- insert_rec(n_line_no, v_object_type, v_username, v_object_type, v_sql);
- n_line_no := n_line_no + 1;
- v_sql := '@ ' || v_file_path || 'cre_views.sql';
- insert_rec(n_line_no, v_object_type, v_username, v_object_type, v_sql);
- n_line_no := n_line_no + 1;
- v_sql := '@ ' || v_file_path || 'functions/';
- insert_rec(n_line_no, v_object_type, v_username, v_object_type, v_sql);
- n_line_no := n_line_no + 1;
- v_sql := '@ ' || v_file_path || 'procedures/';
- insert_rec(n_line_no, v_object_type, v_username, v_object_type, v_sql);
- n_line_no := n_line_no + 1;
- v_sql := '@ ' || v_file_path || 'packages/';
- insert_rec(n_line_no, v_object_type, v_username, v_object_type, v_sql);
- n_line_no := n_line_no + 1;
- v_sql := '@ ' || v_file_path || 'triggers/';
- insert_rec(n_line_no, v_object_type, v_username, v_object_type, v_sql);
- n_line_no := n_line_no + 1;
- v_sql := '@ ' || v_file_path || 'cre_synonyms.sql';
- insert_rec(n_line_no, v_object_type, v_username, v_object_type, v_sql);
- n_line_no := n_line_no + 1;
- v_sql := ' ';
- insert_rec(n_line_no, v_object_type, v_username, v_object_type, v_sql);
- n_line_no := n_line_no + 1;
- v_sql := '-- ***** import data ***** -- ';
- insert_rec(n_line_no, v_object_type, v_username, v_object_type, v_sql);
- n_line_no := n_line_no + 1;
- v_sql := ' ';
- insert_rec(n_line_no, v_object_type, v_username, v_object_type, v_sql);
- n_line_no := n_line_no + 1;
- v_sql := '@ ' || v_file_path || 'cre_indexes.sql';
- insert_rec(n_line_no, v_object_type, v_username, v_object_type, v_sql);
- n_line_no := n_line_no + 1;
- v_sql := '@ ' || v_file_path || 'cre_pri_constraint.sql';
- insert_rec(n_line_no, v_object_type, v_username, v_object_type, v_sql);
- n_line_no := n_line_no + 1;
- v_sql := '@ ' || v_file_path || 'cre_not_pri_constraint.sql';
- insert_rec(n_line_no, v_object_type, v_username, v_object_type, v_sql);
- n_line_no := n_line_no + 1;
- v_sql := '@ ' || v_file_path || 'cre_db_links.sql';
- insert_rec(n_line_no, v_object_type, v_username, v_object_type, v_sql);
- n_line_no := n_line_no + 1;
- COMMIT;
- END;
- FUNCTION fun_return_table_name_tab4(p_v_table_name VARCHAR2,
- p_n_col_max_len NUMBER) RETURN VARCHAR2 AS
- v_table_name VARCHAR2(100);
- v_temp VARCHAR2(100);
- n_col_max_len NUMBER;
- BEGIN
- v_table_name := trim(p_v_table_name);
- n_col_max_len := p_n_col_max_len;
- v_temp := v_table_name;
- WHILE mod(length(v_temp), 4) <> 0 LOOP
- v_temp := v_temp || ' ';
- END LOOP;
- IF mod(length(v_table_name), 4) <> 0 THEN
- v_table_name := v_table_name || chr(9);
- END IF;
- WHILE length(v_temp) < n_col_max_len LOOP
- v_table_name := v_table_name || chr(9);
- v_temp := v_temp || ' ';
- END LOOP;
- RETURN v_table_name;
- END;
- FUNCTION fun_return_table_name_tab8(p_v_table_name VARCHAR2,
- p_n_col_max_len NUMBER) RETURN VARCHAR2 AS
- v_table_name VARCHAR2(100);
- v_temp VARCHAR2(100);
- n_col_max_len NUMBER;
- BEGIN
- v_table_name := trim(p_v_table_name);
- n_col_max_len := p_n_col_max_len;
- v_temp := v_table_name;
- WHILE mod(length(v_temp), 8) <> 0 LOOP
- v_temp := v_temp || ' ';
- END LOOP;
- IF mod(length(v_table_name), 8) <> 0 THEN
- v_table_name := v_table_name || chr(9);
- END IF;
- WHILE length(v_temp) < n_col_max_len LOOP
- v_table_name := v_table_name || chr(9);
- v_temp := v_temp || ' ';
- END LOOP;
- RETURN v_table_name;
- END;
- PROCEDURE pro_tab_sql_tab4(p_v_gen_drop_sql VARCHAR2 default 'T',
- p_v_gen_create_sql VARCHAR2 default 'T',
- p_v_gen_store_clause VARCHAR2 default 'T',
- p_v_display_prompt_info VARCHAR2 default 'T') AS
- CURSOR cur_tables is
- SELECT table_name,
- tablespace_name,
- pct_free,
- pct_used,
- ini_trans,
- max_trans,
- initial_extent,
- next_extent,
- min_extents,
- max_extents,
- pct_increase,
- freelists,
- freelist_groups,
- buffer_pool,
- decode(logging, 'YES', 'LOGGING', 'NOLOGGING') logging
- FROM user_tables
- WHERE lower(TABLE_NAME) NOT IN
- ('temp_for_pkg_gen_sql2000_temp',
- 'temp_for_pkg_gen_sql4000_temp')
- ORDER BY table_name;
- CURSOR cur_cols(t_name VARCHAR2) is
- SELECT table_name,
- column_name,
- data_type,
- data_length,
- data_precision,
- data_scale,
- nullable,
- data_default
- FROM user_tab_columns
- WHERE table_name = t_name
- ORDER BY column_id;
- v_tab_name VARCHAR2(40);
- v_tabsp_name VARCHAR2(40);
- n_mpct_free user_tables.pct_free%TYPE;
- n_mpct_used user_tables.pct_used%TYPE;
- n_mini_trans user_tables.ini_trans%TYPE;
- n_mmax_trans user_tables.max_trans%TYPE;
- n_mini_ext user_tables.initial_extent%TYPE;
- n_mnext_ext user_tables.next_extent%TYPE;
- n_mmin_ext user_tables.min_extents%TYPE;
- n_mmax_ext user_tables.max_extents%TYPE;
- n_mpct_inc user_tables.pct_increase%TYPE;
- n_freelists user_tables.freelists%TYPE;
- n_freelist_groups user_tables.freelist_groups%TYPE;
- v_buffer_pool user_tables.buffer_pool%TYPE;
- v_logging VARCHAR2(15);
- col_name VARCHAR2(40);
- ct NUMBER := 0;
- n_line_no NUMBER := 0;
- col_content VARCHAR2(120);
- n_col_max_len NUMBER(10, 0);
- v_default_val VARCHAR2(4000);
- v_gen_drop_tab_sql VARCHAR2(10);
- v_gen_create_tab_sql VARCHAR2(10);
- v_gen_store_clause VARCHAR2(10);
- v_display_prompt_info VARCHAR2(10);
- v_username VARCHAR2(30);
- v_sql VARCHAR2(2000);
- n_position NUMBER(6, 0);
- v_object_type VARCHAR2(10);
- v_prompt VARCHAR2(10);
- PROCEDURE insert_rec(p_line_no INTEGER,
- p_object_type VARCHAR2,
- p_user_name VARCHAR2,
- p_object_name VARCHAR2,
- p_string VARCHAR2) IS
- BEGIN
- INSERT INTO temp_for_pkg_gen_sql2000_temp
- (line_no, object_type, user_name, object_name, sql_text)
- VALUES
- (p_line_no, p_object_type, p_user_name, p_object_name, p_string);
- END;
- BEGIN
- v_gen_drop_tab_sql := p_v_gen_drop_sql;
- v_gen_create_tab_sql := p_v_gen_create_sql;
- v_gen_store_clause := p_v_gen_store_clause;
- v_display_prompt_info := p_v_display_prompt_info;
- v_prompt := '-- prompt ';
- v_object_type := 'TABLE_4';
- n_line_no := 1;
- SELECT username INTO v_username FROM user_users;
- DELETE temp_for_pkg_gen_sql2000_temp WHERE OBJECT_TYPE = v_object_type;
- COMMIT;
- FOR cur_tables_rec IN cur_tables LOOP
- v_tab_name := cur_tables_rec.table_name;
- v_tabsp_name := cur_tables_rec.tablespace_name;
- n_mpct_free := cur_tables_rec.pct_free;
- n_mpct_used := cur_tables_rec.pct_used;
- n_mini_trans := cur_tables_rec.ini_trans;
- n_mmax_trans := cur_tables_rec.max_trans;
- n_mini_ext := cur_tables_rec.initial_extent;
- n_mnext_ext := cur_tables_rec.next_extent;
- n_mmin_ext := cur_tables_rec.min_extents;
- n_mmax_ext := cur_tables_rec.max_extents;
- n_mpct_inc := nvl(cur_tables_rec.pct_increase, 0);
- n_freelists := cur_tables_rec.freelists;
- n_freelist_groups := cur_tables_rec.freelist_groups;
- v_buffer_pool := cur_tables_rec.buffer_pool;
- v_logging := cur_tables_rec.logging;
- IF v_gen_drop_tab_sql = 'T' THEN
- IF upper(v_display_prompt_info) = 'T' THEN
- v_sql := v_prompt || ' Drop Table ' || v_tab_name;
- insert_rec(n_line_no,
- v_object_type,
- v_username,
- v_tab_name,
- v_sql);
- n_line_no := n_line_no + 1;
- END IF;
- v_sql := 'ALTER TABLE ' || v_tab_name ||
- ' drop primary key cascade;';
- insert_rec(n_line_no, v_object_type, v_username, v_tab_name, v_sql);
- n_line_no := n_line_no + 1;
- v_sql := 'DROP TABLE ' || v_tab_name || ' cascade constraint;';
- insert_rec(n_line_no, v_object_type, v_username, v_tab_name, v_sql);
- n_line_no := n_line_no + 1;
- v_sql := ' ';
- insert_rec(n_line_no, v_object_type, v_username, v_tab_name, v_sql);
- n_line_no := n_line_no + 1;
- END IF;
- IF upper(v_gen_create_tab_sql) = 'T' THEN
- IF upper(v_display_prompt_info) = 'T' THEN
- v_sql := v_prompt || ' Create Table ' || v_tab_name;
- insert_rec(n_line_no,
- v_object_type,
- v_username,
- v_tab_name,
- v_sql);
- n_line_no := n_line_no + 1;
- END IF;
- v_sql := 'CREATE TABLE ' || v_tab_name || '(';
- insert_rec(n_line_no, v_object_type, v_username, v_tab_name, v_sql);
- n_line_no := n_line_no + 1;
- -- 找到最长的列名的长度
- n_col_max_len := 1;
- FOR cur_cols_rec IN cur_cols(v_tab_name) LOOP
- IF n_col_max_len < length(trim(cur_cols_rec.column_name)) THEN
- n_col_max_len := length(trim(cur_cols_rec.column_name));
- END IF;
- END LOOP;
- ct := 0;
- FOR cur_cols_rec IN cur_cols(v_tab_name) LOOP
- ct := ct + 1;
- v_default_val := cur_cols_rec.data_default;
- v_default_val := trim(v_default_val);
- n_position := instr(v_default_val, chr(10), -1);
- WHILE n_position > 0 LOOP
- IF n_position = length(v_default_val) THEN
- v_default_val := substr(v_default_val, 1, n_position - 1);
- ELSE
- v_default_val := substr(v_default_val, 1, n_position - 1) ||
- substr(v_default_val, n_position + 1);
- END IF;
- n_position := instr(v_default_val, chr(10), -1);
- END LOOP;
- n_position := instr(v_default_val, chr(9), -1);
- IF n_position = length(v_default_val) THEN
- v_default_val := substr(v_default_val, 1, n_position - 1);
- END IF;
- IF ct = 1 THEN
- INSERT INTO temp_for_pkg_gen_sql2000_temp
- (line_no, object_type, user_name, object_name, sql_text)
- VALUES
- (n_line_no,
- v_object_type,
- v_username,
- v_tab_name,
- chr(9) ||
- pkg_gen_user_sql.fun_return_table_name_tab4(trim(cur_cols_rec.column_name),
- n_col_max_len) ||
- chr(9) || trim(cur_cols_rec.data_type) ||
- decode(cur_cols_rec.data_type,
- 'VARCHAR2',
- '(' || to_char(cur_cols_rec.data_length) || ')',
- 'VARCHAR',
- '(' || to_char(cur_cols_rec.data_length) || ')',
- 'NVARCHAR2',
- '(' || to_char(cur_cols_rec.data_length) || ')',
- 'NVARCHAR',
- '(' || to_char(cur_cols_rec.data_length) || ')',
- 'CHAR',
- '(' || to_char(cur_cols_rec.data_length) || ')',
- 'NCHAR',
- '(' || to_char(cur_cols_rec.data_length) || ')',
- 'NUMBER',
- decode(cur_cols_rec.data_precision,
- null,
- '',
- '(' || to_char(cur_cols_rec.data_precision) ||
- decode(cur_cols_rec.data_scale,
- null,
- ')',
- ',' || to_char(cur_cols_rec.data_scale) || ')')),
- '') ||
- decode(cur_cols_rec.nullable,
- 'Y',
- decode(v_default_val,
- null,
- ',',
- chr(9) || 'default' || chr(9) || v_default_val || ','),
- decode(v_default_val,
- null,
- chr(9) || 'NOT NULL,',
- chr(9) || 'default' || chr(9) || v_default_val ||
- chr(9) || chr(9) || 'NOT NULL,')));
- n_line_no := n_line_no + 1;
- ELSE
- INSERT INTO temp_for_pkg_gen_sql2000_temp
- (line_no, object_type, user_name, object_name, sql_text)
- VALUES
- (n_line_no,
- v_object_type,
- v_username,
- v_tab_name,
- chr(9) ||
- pkg_gen_user_sql.fun_return_table_name_tab4(trim(cur_cols_rec.column_name),
- n_col_max_len) ||
- chr(9) || trim(cur_cols_rec.data_type) ||
- decode(cur_cols_rec.data_type,
- 'VARCHAR2',
- '(' || to_char(cur_cols_rec.data_length) || ')',
- 'VARCHAR',
- '(' || to_char(cur_cols_rec.data_length) || ')',
- 'NVARCHAR2',
- '(' || to_char(cur_cols_rec.data_length) || ')',
- 'NVARCHAR',
- '(' || to_char(cur_cols_rec.data_length) || ')',
- 'CHAR',
- '(' || to_char(cur_cols_rec.data_length) || ')',
- 'NCHAR',
- '(' || to_char(cur_cols_rec.data_length) || ')',
- 'NUMBER',
- decode(cur_cols_rec.data_precision,
- null,
- '',
- '(' || to_char(cur_cols_rec.data_precision) ||
- decode(cur_cols_rec.data_scale,
- null,
- ')',
- ',' || to_char(cur_cols_rec.data_scale) || ')')),
- '') ||
- decode(cur_cols_rec.nullable,
- 'Y',
- decode(v_default_val,
- null,
- ',',
- chr(9) || 'default' || chr(9) || v_default_val || ','),
- decode(v_default_val,
- null,
- chr(9) || 'NOT NULL,',
- chr(9) || 'default' || chr(9) || v_default_val ||
- chr(9) || chr(9) || 'NOT NULL,')));
- n_line_no := n_line_no + 1;
- END IF;
- END LOOP;
- SELECT rtrim(sql_text)
- into col_content
- FROM temp_for_pkg_gen_sql2000_temp
- WHERE line_no = n_line_no - 1
- AND object_type = v_object_type;
- col_content := substr(col_content, 1, length(col_content) - 1);
- UPDATE temp_for_pkg_gen_sql2000_temp
- SET sql_text = col_content
- WHERE line_no = n_line_no - 1
- AND object_type = v_object_type;
- v_sql := ')';
- insert_rec(n_line_no, v_object_type, v_username, v_tab_name, v_sql);
- n_line_no := n_line_no + 1;
- IF v_gen_store_clause = 'T' THEN
- v_sql := v_logging;
- insert_rec(n_line_no,
- v_object_type,
- v_username,
- v_tab_name,
- v_sql);
- n_line_no := n_line_no + 1;
- v_sql := 'TABLESPACE ' || v_tabsp_name;
- insert_rec(n_line_no,
- v_object_type,
- v_username,
- v_tab_name,
- v_sql);
- n_line_no := n_line_no + 1;
- v_sql := 'PCTFREE ' || n_mpct_free || chr(9) || 'PCTUSED ' ||
- n_mpct_used;
- insert_rec(n_line_no,
- v_object_type,
- v_username,
- v_tab_name,
- v_sql);
- n_line_no := n_line_no + 1;
- v_sql := 'INITRANS ' || n_mini_trans || chr(9) || 'MAXTRANS ' ||
- n_mmax_trans;
- insert_rec(n_line_no,
- v_object_type,
- v_username,
- v_tab_name,
- v_sql);
- n_line_no := n_line_no + 1;
- v_sql := 'STORAGE (';
- insert_rec(n_line_no,
- v_object_type,
- v_username,
- v_tab_name,
- v_sql);
- n_line_no := n_line_no + 1;
- v_sql := chr(9) || 'INITIAL ' || n_mini_ext;
- insert_rec(n_line_no,
- v_object_type,
- v_username,
- v_tab_name,
- v_sql);
- n_line_no := n_line_no + 1;
- IF n_mnext_ext IS NOT NULL THEN
- UPDATE temp_for_pkg_gen_sql2000_temp
- SET sql_text = sql_text || chr(9) || 'NEXT ' ||
- to_char(n_mnext_ext)
- WHERE line_no = n_line_no - 1
- AND object_type = v_object_type;
- END IF;
- UPDATE temp_for_pkg_gen_sql2000_temp
- SET sql_text = sql_text || chr(9) || 'PCTINCREASE ' ||
- to_char(n_mpct_inc)
- WHERE line_no = n_line_no - 1
- AND object_type = v_object_type;
- v_sql := chr(9) || 'FREELISTS ' || to_char(n_freelists);
- insert_rec(n_line_no,
- v_object_type,
- v_username,
- v_tab_name,
- v_sql);
- n_line_no := n_line_no + 1;
- UPDATE temp_for_pkg_gen_sql2000_temp
- SET sql_text = sql_text || chr(9) || 'FREELIST GROUPS ' ||
- to_char(n_freelist_groups)
- WHERE line_no = n_line_no - 1
- AND object_type = v_object_type;
- v_sql := chr(9) || 'BUFFER_POOL ' || v_buffer_pool;
- insert_rec(n_line_no,
- v_object_type,
- v_username,
- v_tab_name,
- v_sql);
- n_line_no := n_line_no + 1;
- UPDATE temp_for_pkg_gen_sql2000_temp
- SET sql_text = sql_text || ');'
- WHERE line_no = n_line_no - 1
- AND object_type = v_object_type;
- ELSE
- UPDATE temp_for_pkg_gen_sql2000_temp
- SET sql_text = sql_text || ';'
- WHERE line_no = n_line_no - 1
- AND object_type = v_object_type;
- END IF;
- v_sql := ' ';
- insert_rec(n_line_no, v_object_type, v_username, v_tab_name, v_sql);
- n_line_no := n_line_no + 1;
- END IF;
- END LOOP;
- COMMIT;
- END;
- PROCEDURE pro_tab_sql_tab8(p_v_gen_drop_sql VARCHAR2 default 'T',
- p_v_gen_create_sql VARCHAR2 default 'T',
- p_v_gen_store_clause VARCHAR2 default 'T',
- p_v_display_prompt_info VARCHAR2 default 'T') AS
- CURSOR cur_tables IS
- SELECT table_name,
- tablespace_name,
- pct_free,
- pct_used,
- ini_trans,
- max_trans,
- initial_extent,
- next_extent,
- min_extents,
- max_extents,
- pct_increase,
- freelists,
- freelist_groups,
- buffer_pool,
- decode(logging, 'YES', 'LOGGING', 'NOLOGGING') logging
- FROM user_tables
- WHERE lower(TABLE_NAME) NOT IN
- ('temp_for_pkg_gen_sql2000_temp',
- 'temp_for_pkg_gen_sql4000_temp')
- ORDER BY table_name;
- CURSOR cur_cols(t_name VARCHAR2) IS
- SELECT table_name,
- column_name,
- data_type,
- data_length,
- data_precision,
- data_scale,
- nullable,
- data_default
- FROM user_tab_columns
- WHERE table_name = t_name
- ORDER BY column_id;
- v_tab_name VARCHAR2(40);
- v_tabsp_name VARCHAR2(40);
- n_mpct_free user_tables.pct_free%TYPE;
- n_mpct_used user_tables.pct_used%TYPE;
- n_mini_trans user_tables.ini_trans%TYPE;
- n_mmax_trans user_tables.max_trans%TYPE;
- n_mini_ext user_tables.initial_extent%TYPE;
- n_mnext_ext user_tables.next_extent%TYPE;
- n_mmin_ext user_tables.min_extents%TYPE;
- n_mmax_ext user_tables.max_extents%TYPE;
- n_mpct_inc user_tables.pct_increase%TYPE;
- n_freelists user_tables.freelists%TYPE;
- n_freelist_groups user_tables.freelist_groups%TYPE;
- v_buffer_pool user_tables.buffer_pool%TYPE;
- v_logging VARCHAR2(15);
- col_name VARCHAR2(40);
- ct NUMBER := 0;
- n_line_no NUMBER := 0;
- col_content VARCHAR2(120);
- n_col_max_len NUMBER(10, 0);
- v_default_val VARCHAR2(4000);
- v_gen_drop_tab_sql VARCHAR2(10);
- v_gen_create_tab_sql VARCHAR2(10);
- v_gen_store_clause VARCHAR2(10);
- v_display_prompt_info VARCHAR2(10);
- v_username VARCHAR2(30);
- v_sql VARCHAR2(2000);
- n_position NUMBER(6, 0);
- v_object_type VARCHAR2(10);
- v_prompt VARCHAR2(10);
- PROCEDURE insert_rec(p_line_no INTEGER,
- p_object_type VARCHAR2,
- p_user_name VARCHAR2,
- p_object_name VARCHAR2,
- p_string VARCHAR2) IS
- BEGIN
- INSERT INTO temp_for_pkg_gen_sql2000_temp
- (line_no, object_type, user_name, object_name, sql_text)
- VALUES
- (p_line_no, p_object_type, p_user_name, p_object_name, p_string);
- END;
- BEGIN
- v_gen_drop_tab_sql := p_v_gen_drop_sql;
- v_gen_create_tab_sql := p_v_gen_create_sql;
- v_gen_store_clause := p_v_gen_store_clause;
- v_display_prompt_info := p_v_display_prompt_info;
- v_prompt := '-- prompt ';
- v_object_type := 'TABLE_8';
- n_line_no := 1;
- SELECT username INTO v_username FROM user_users;
- DELETE temp_for_pkg_gen_sql2000_temp WHERE OBJECT_TYPE = v_object_type;
- COMMIT;
- FOR cur_tables_rec IN cur_tables LOOP
- v_tab_name := cur_tables_rec.table_name;
- v_tabsp_name := cur_tables_rec.tablespace_name;
- n_mpct_free := cur_tables_rec.pct_free;
- n_mpct_used := cur_tables_rec.pct_used;
- n_mini_trans := cur_tables_rec.ini_trans;
- n_mmax_trans := cur_tables_rec.max_trans;
- n_mini_ext := cur_tables_rec.initial_extent;
- n_mnext_ext := cur_tables_rec.next_extent;
- n_mmin_ext := cur_tables_rec.min_extents;
- n_mmax_ext := cur_tables_rec.max_extents;
- n_mpct_inc := nvl(cur_tables_rec.pct_increase, 0);
- n_freelists := cur_tables_rec.freelists;
- n_freelist_groups := cur_tables_rec.freelist_groups;
- v_buffer_pool := cur_tables_rec.buffer_pool;
- v_logging := cur_tables_rec.logging;
- IF v_gen_drop_tab_sql = 'T' THEN
- IF upper(v_display_prompt_info) = 'T' THEN
- v_sql := v_prompt || ' Drop Table ' || v_tab_name;
- insert_rec(n_line_no,
- v_object_type,
- v_username,
- v_tab_name,
- v_sql);
- n_line_no := n_line_no + 1;
- END IF;
- v_sql := 'ALTER TABLE ' || v_tab_name ||
- ' drop primary key cascade;';
- insert_rec(n_line_no, v_object_type, v_username, v_tab_name, v_sql);
- n_line_no := n_line_no + 1;
- v_sql := 'DROP TABLE ' || v_tab_name || ' cascade constraint;';
- insert_rec(n_line_no, v_object_type, v_username, v_tab_name, v_sql);
- n_line_no := n_line_no + 1;
- v_sql := ' ';
- insert_rec(n_line_no, v_object_type, v_username, v_tab_name, v_sql);
- n_line_no := n_line_no + 1;
- END IF;
- IF upper(v_gen_create_tab_sql) = 'T' THEN
- IF upper(v_display_prompt_info) = 'T' THEN
- v_sql := v_prompt || ' Create Table ' || v_tab_name;
- insert_rec(n_line_no,
- v_object_type,
- v_username,
- v_tab_name,
- v_sql);
- n_line_no := n_line_no + 1;
- END IF;
- v_sql := 'CREATE TABLE ' || v_tab_name || '(';
- insert_rec(n_line_no, v_object_type, v_username, v_tab_name, v_sql);
- n_line_no := n_line_no + 1;
- -- 找到最长的列名的长度
- n_col_max_len := 1;
- FOR cur_cols_rec IN cur_cols(v_tab_name) LOOP
- IF n_col_max_len < length(trim(cur_cols_rec.column_name)) THEN
- n_col_max_len := length(trim(cur_cols_rec.column_name));
- END IF;
- END LOOP;
- ct := 0;
- FOR cur_cols_rec IN cur_cols(v_tab_name) LOOP
- ct := ct + 1;
- v_default_val := cur_cols_rec.data_default;
- v_default_val := trim(v_default_val);
- n_position := instr(v_default_val, chr(10), -1);
- WHILE n_position > 0 LOOP
- IF n_position = length(v_default_val) THEN
- v_default_val := substr(v_default_val, 1, n_position - 1);
- ELSE
- v_default_val := substr(v_default_val, 1, n_position - 1) ||
- substr(v_default_val, n_position + 1);
- END IF;
- n_position := instr(v_default_val, chr(10), -1);
- END LOOP;
- n_position := instr(v_default_val, chr(9), -1);
- IF n_position = length(v_default_val) THEN
- v_default_val := substr(v_default_val, 1, n_position - 1);
- END IF;
- IF ct = 1 THEN
- INSERT INTO temp_for_pkg_gen_sql2000_temp
- (line_no, object_type, user_name, object_name, sql_text)
- VALUES
- (n_line_no,
- v_object_type,
- v_username,
- v_tab_name,
- chr(9) ||
- pkg_gen_user_sql.fun_return_table_name_tab8(trim(cur_cols_rec.column_name),
- n_col_max_len) ||
- chr(9) || trim(cur_cols_rec.data_type) ||
- decode(cur_cols_rec.data_type,
- 'VARCHAR2',
- '(' || to_char(cur_cols_rec.data_length) || ')',
- 'VARCHAR',
- '(' || to_char(cur_cols_rec.data_length) || ')',
- 'NVARCHAR2',
- '(' || to_char(cur_cols_rec.data_length) || ')',
- 'NVARCHAR',
- '(' || to_char(cur_cols_rec.data_length) || ')',
- 'CHAR',
- '(' || to_char(cur_cols_rec.data_length) || ')',
- 'NCHAR',
- '(' || to_char(cur_cols_rec.data_length) || ')',
- 'NUMBER',
- decode(cur_cols_rec.data_precision,
- null,
- '',
- '(' || to_char(cur_cols_rec.data_precision) ||
- decode(cur_cols_rec.data_scale,
- null,
- ')',
- ',' || to_char(cur_cols_rec.data_scale) || ')')),
- '') ||
- decode(cur_cols_rec.nullable,
- 'Y',
- decode(v_default_val,
- null,
- ',',
- chr(9) || 'default' || chr(9) || v_default_val || ','),
- decode(v_default_val,
- null,
- chr(9) || 'NOT NULL,',
- chr(9) || 'default' || chr(9) || v_default_val ||
- chr(9) || chr(9) || 'NOT NULL,')));
- n_line_no := n_line_no + 1;
- ELSE
- INSERT INTO temp_for_pkg_gen_sql2000_temp
- (line_no, object_type, user_name, object_name, sql_text)
- VALUES
- (n_line_no,
- v_object_type,
- v_username,
- v_tab_name,
- chr(9) ||
- pkg_gen_user_sql.fun_return_table_name_tab8(trim(cur_cols_rec.column_name),
- n_col_max_len) ||
- chr(9) || trim(cur_cols_rec.data_type) ||
- decode(cur_cols_rec.data_type,
- 'VARCHAR2',
- '(' || to_char(cur_cols_rec.data_length) || ')',
- 'VARCHAR',
- '(' || to_char(cur_cols_rec.data_length) || ')',
- 'NVARCHAR2',
- '(' || to_char(cur_cols_rec.data_length) || ')',
- 'NVARCHAR',
- '(' || to_char(cur_cols_rec.data_length) || ')',
- 'CHAR',
- '(' || to_char(cur_cols_rec.data_length) || ')',
- 'NCHAR',
- '(' || to_char(cur_cols_rec.data_length) || ')',
- 'NUMBER',
- decode(cur_cols_rec.data_precision,
- null,
- '',
- '(' || to_char(cur_cols_rec.data_precision) ||
- decode(cur_cols_rec.data_scale,
- null,
- ')',
- ',' || to_char(cur_cols_rec.data_scale) || ')')),
- '') ||
- decode(cur_cols_rec.nullable,
- 'Y',
- decode(v_default_val,
- null,
- ',',
- chr(9) || 'default' || chr(9) || v_default_val || ','),
- decode(v_default_val,
- null,
- chr(9) || 'NOT NULL,',
- chr(9) || 'default' || chr(9) || v_default_val ||
- chr(9) || chr(9) || 'NOT NULL,')));
- n_line_no := n_line_no + 1;
- END IF;
- END LOOP;
- SELECT rtrim(sql_text)
- into col_content
- FROM temp_for_pkg_gen_sql2000_temp
- WHERE line_no = n_line_no - 1
- AND object_type = v_object_type;
- col_content := substr(col_content, 1, length(col_content) - 1);
- UPDATE temp_for_pkg_gen_sql2000_temp
- SET sql_text = col_content
- WHERE line_no = n_line_no - 1
- AND object_type = v_object_type;
- v_sql := ')';
- insert_rec(n_line_no, v_object_type, v_username, v_tab_name, v_sql);
- n_line_no := n_line_no + 1;
- IF v_gen_store_clause = 'T' THEN
- v_sql := v_logging;
- insert_rec(n_line_no,
- v_object_type,
- v_username,
- v_tab_name,
- v_sql);
- n_line_no := n_line_no + 1;
- v_sql := 'TABLESPACE ' || v_tabsp_name;
- insert_rec(n_line_no,
- v_object_type,
- v_username,
- v_tab_name,
- v_sql);
- n_line_no := n_line_no + 1;
- v_sql := 'PCTFREE ' || n_mpct_free || chr(9) || 'PCTUSED ' ||
- n_mpct_used;
- insert_rec(n_line_no,
- v_object_type,
- v_username,
- v_tab_name,
- v_sql);
- n_line_no := n_line_no + 1;
- v_sql := 'INITRANS ' || n_mini_trans || chr(9) || 'MAXTRANS ' ||
- n_mmax_trans;
- insert_rec(n_line_no,
- v_object_type,
- v_username,
- v_tab_name,
- v_sql);
- n_line_no := n_line_no + 1;
- v_sql := 'STORAGE (';
- insert_rec(n_line_no,
- v_object_type,
- v_username,
- v_tab_name,
- v_sql);
- n_line_no := n_line_no + 1;
- v_sql := chr(9) || 'INITIAL ' || n_mini_ext;
- insert_rec(n_line_no,
- v_object_type,
- v_username,
- v_tab_name,
- v_sql);
- n_line_no := n_line_no + 1;
- IF n_mnext_ext IS NOT NULL THEN
- UPDATE temp_for_pkg_gen_sql2000_temp
- SET sql_text = sql_text || chr(9) || 'NEXT ' ||
- to_char(n_mnext_ext)
- WHERE line_no = n_line_no - 1
- AND object_type = v_object_type;
- END IF;
- UPDATE temp_for_pkg_gen_sql2000_temp
- SET sql_text = sql_text || chr(9) || 'PCTINCREASE ' ||
- to_char(n_mpct_inc)
- WHERE line_no = n_line_no - 1
- AND object_type = v_object_type;
- v_sql := chr(9) || 'FREELISTS ' || to_char(n_freelists);
- insert_rec(n_line_no,
- v_object_type,
- v_username,
- v_tab_name,
- v_sql);
- n_line_no := n_line_no + 1;
- UPDATE temp_for_pkg_gen_sql2000_temp
- SET sql_text = sql_text || chr(9) || 'FREELIST GROUPS ' ||
- to_char(n_freelist_groups)
- WHERE line_no = n_line_no - 1
- AND object_type = v_object_type;
- v_sql := chr(9) || 'BUFFER_POOL ' || v_buffer_pool;
- insert_rec(n_line_no,
- v_object_type,
- v_username,
- v_tab_name,
- v_sql);
- n_line_no := n_line_no + 1;
- UPDATE temp_for_pkg_gen_sql2000_temp
- SET sql_text = sql_text || ');'
- WHERE line_no = n_line_no - 1
- AND object_type = v_object_type;
- ELSE
- UPDATE temp_for_pkg_gen_sql2000_temp
- SET sql_text = sql_text || ';'
- WHERE line_no = n_line_no - 1
- AND object_type = v_object_type;
- END IF;
- v_sql := ' ';
- insert_rec(n_line_no, v_object_type, v_username, v_tab_name, v_sql);
- n_line_no := n_line_no + 1;
- END IF;
- END LOOP;
- COMMIT;
- END;
- PROCEDURE pro_con_sql(p_v_con_type VARCHAR2 default 'ALL',
- p_v_gen_drop_sql VARCHAR2 default 'T',
- p_v_gen_create_sql VARCHAR2 default 'T',
- p_v_gen_null_chk VARCHAR2 default 'T',
- p_v_display_prompt_info VARCHAR2 default 'T') AS
- CURSOR cur_tables is
- SELECT table_name FROM user_tables ORDER BY table_name;
- CURSOR cur_con_cols(c_name VARCHAR2) IS
- SELECT column_name
- FROM user_cons_columns
- WHERE constraint_name = c_name
- ORDER BY position;
- type ref_cur is REF CURSOR; -- 定义一个ref 类型的游标
- cur_cons ref_cur; -- 定义游标变量
- TYPE type_con IS RECORD(
- constraint_name user_constraints.constraint_name%type,
- r_constraint_name user_constraints.r_constraint_name%type,
- constraint_type user_constraints.constraint_type%type,
- search_condition user_constraints.search_condition%type);
- cur_cons_rec type_con;
- v_tab_name VARCHAR2(40);
- v_table_name VARCHAR2(40);
- v_type VARCHAR2(1);
- n_ct NUMBER := 0;
- n_line_no NUMBER := 0;
- v_con_type VARCHAR2(10);
- v_con_sql VARCHAR2(500);
- v_sql VARCHAR2(2000);
- v_gen_drop_con_sql VARCHAR2(10);
- v_display_prompt_info VARCHAR2(10);
- v_gen_create_con_sql VARCHAR2(10);
- v_gen_null_chk VARCHAR2(10);
- v_username VARCHAR2(30);
- v_object_type VARCHAR2(30);
- v_prompt VARCHAR2(30);
- v_search_condition VARCHAR2(1000);
- PROCEDURE insert_rec(p_line_no INTEGER,
- p_object_type VARCHAR2,
- p_user_name VARCHAR2,
- p_con_name VARCHAR2,
- p_string VARCHAR2) IS
- BEGIN
- INSERT INTO temp_for_pkg_gen_sql2000_temp
- (line_no, object_type, user_name, object_name, sql_text)
- VALUES
- (p_line_no, p_object_type, p_user_name, p_con_name, p_string);
- END;
- BEGIN
- v_con_type := p_v_con_type;
- v_gen_drop_con_sql := p_v_gen_drop_sql;
- v_display_prompt_info := p_v_display_prompt_info;
- v_gen_create_con_sql := p_v_gen_create_sql;
- v_gen_null_chk := p_v_gen_null_chk;
- v_object_type := 'CONSTRAINT';
- v_prompt := '-- prompt ';
- n_line_no := 1;
- SELECT username INTO v_username FROM user_users;
- DELETE FROM temp_for_pkg_gen_sql2000_temp
- WHERE object_type = v_object_type;
- COMMIT;
- FOR cur_tables_rec IN cur_tables LOOP
- v_tab_name := trim(cur_tables_rec.table_name);
- -- Get the constraint info for specified table
- v_con_sql := 'SELECT constraint_name, r_constraint_name, ';
- v_con_sql := v_con_sql || ' constraint_type, search_condition ';
- v_con_sql := v_con_sql || 'FROM user_constraints ';
- IF upper(v_con_type) <> 'ALL' AND upper(v_con_type) <> 'A' AND
- upper(v_con_type) <> 'NOT_PRI' THEN
- v_con_sql := v_con_sql || 'WHERE table_name = ''' || v_tab_name ||
- ''' AND constraint_type = ''' || upper(v_con_type) ||
- ''' ';
- ELSIF upper(v_con_type) = 'NOT_PRI' THEN
- v_con_sql := v_con_sql || 'WHERE table_name = ''' || v_tab_name ||
- ''' AND constraint_type <> ''P'' ';
- ELSE
- v_con_sql := v_con_sql || 'WHERE table_name = ''' || v_tab_name ||
- ''' ';
- END IF;
- v_con_sql := v_con_sql || 'ORDER BY constraint_name';
- OPEN cur_cons FOR v_con_sql;
- LOOP
- FETCH cur_cons
- INTO cur_cons_rec;
- EXIT WHEN cur_cons%NOTFOUND;
- v_type := cur_cons_rec.constraint_type;
- v_search_condition := cur_cons_rec.search_condition;
- IF upper(v_gen_drop_con_sql) = 'T' THEN
- IF v_gen_null_chk = 'F' AND v_type = 'C' AND
- instr(v_search_condition, 'IS NOT NULL') > 0 THEN
- -- do null
- v_gen_null_chk := v_gen_null_chk;
- ELSE
- IF upper(v_display_prompt_info) = 'T' THEN
- -- insert prompt info
- INSERT INTO temp_for_pkg_gen_sql2000_temp
- (line_no, object_type, user_name, object_name, sql_text)
- VALUES
- (n_line_no,
- v_object_type,
- v_username,
- cur_cons_rec.constraint_name,
- v_prompt || ' Drop constraints : ' || v_tab_name || '.' ||
- trim(cur_cons_rec.constraint_name) || '; Type : ' ||
- decode(v_type,
- 'C',
- 'CHECK',
- 'P',
- 'PRIMARY KEY',
- 'U',
- 'UNIQUE',
- 'R',
- 'FROEIGN RELATION',
- v_type));
- n_line_no := n_line_no + 1;
- END IF;
- v_sql := 'alter table ' || v_tab_name || ' drop constraint ' ||
- cur_cons_rec.constraint_name || ';';
- insert_rec(n_line_no,
- v_object_type,
- v_username,
- cur_cons_rec.constraint_name,
- v_sql);
- n_line_no := n_line_no + 1;
- v_sql := ' ';
- insert_rec(n_line_no,
- v_object_type,
- v_username,
- cur_cons_rec.constraint_name,
- v_sql);
- n_line_no := n_line_no + 1;
- END IF;
- END IF;
- IF upper(v_gen_create_con_sql) = 'T' THEN
- IF v_gen_null_chk = 'F' AND v_type = 'C' AND
- instr(v_search_condition, 'IS NOT NULL') > 0 THEN
- -- do null
- v_gen_null_chk := v_gen_null_chk;
- ELSE
- IF upper(v_display_prompt_info) = 'T' THEN
- -- insert prompt info
- INSERT INTO temp_for_pkg_gen_sql2000_temp
- (line_no, object_type, user_name, object_name, sql_text)
- VALUES
- (n_line_no,
- v_object_type,
- v_username,
- cur_cons_rec.constraint_name,
- v_prompt || ' Add constraints : ' || v_tab_name || '.' ||
- trim(cur_cons_rec.constraint_name) || '; Type : ' ||
- decode(v_type,
- 'C',
- 'CHECK',
- 'P',
- 'PRIMARY KEY',
- 'U',
- 'UNIQUE',
- 'R',
- 'FROEIGN RELATION',
- v_type));
- n_line_no := n_line_no + 1;
- END IF;
- v_sql := 'alter table ' || v_tab_name || ' add constraint ' ||
- trim(cur_cons_rec.constraint_name);
- insert_rec(n_line_no,
- v_object_type,
- v_username,
- cur_cons_rec.constraint_name,
- v_sql);
- n_line_no := n_line_no + 1;
- IF v_type = 'C' THEN
- v_sql := ' check( ' ||
- trim(cur_cons_rec.search_condition);
- insert_rec(n_line_no,
- v_object_type,
- v_username,
- cur_cons_rec.constraint_name,
- v_sql);
- n_line_no := n_line_no + 1;
- END IF;
- n_ct := 0;
- FOR cur_con_cols_rec IN cur_con_cols(cur_cons_rec.constraint_name) LOOP
- n_ct := n_ct + 1;
- IF n_ct = 1 THEN
- IF v_type = 'R' THEN
- v_sql := ' foreign key( ' ||
- trim(cur_con_cols_rec.column_name);
- insert_rec(n_line_no,
- v_object_type,
- v_username,
- cur_cons_rec.constraint_name,
- v_sql);
- n_line_no := n_line_no + 1;
- END IF;
- IF v_type = 'P' THEN
- v_sql := ' primary key( ' ||
- trim(cur_con_cols_rec.column_name);
- insert_rec(n_line_no,
- v_object_type,
- v_username,
- cur_cons_rec.constraint_name,
- v_sql);
- n_line_no := n_line_no + 1;
- END IF;
- IF v_type = 'U' THEN
- v_sql := ' unique( ' ||
- trim(cur_con_cols_rec.column_name);
- insert_rec(n_line_no,
- v_object_type,
- v_username,
- cur_cons_rec.constraint_name,
- v_sql);
- n_line_no := n_line_no + 1;
- END IF;
- ELSE
- UPDATE temp_for_pkg_gen_sql2000_temp
- SET sql_text = rtrim(sql_text) || ' , ' ||
- trim(cur_con_cols_rec.column_name)
- WHERE line_no = n_line_no - 1
- AND object_type = v_object_type;
- END IF;
- END LOOP;
- UPDATE temp_for_pkg_gen_sql2000_temp
- SET sql_text = rtrim(sql_text) || ' )'
- WHERE line_no = n_line_no - 1
- AND object_type = v_object_type;
- IF v_type = 'R' THEN
- SELECT table_name
- into v_table_name
- FROM user_constraints
- WHERE constraint_name = cur_cons_rec.r_constraint_name;
- n_ct := 0;
- FOR cur_con_cols_rec IN cur_con_cols(cur_cons_rec.r_constraint_name) LOOP
- n_ct := n_ct + 1;
- IF n_ct = 1 THEN
- v_sql := ' references ' || v_table_name || '( ';
- insert_rec(n_line_no,
- v_object_type,
- v_username,
- cur_cons_rec.constraint_name,
- v_sql);
- n_line_no := n_line_no + 1;
- UPDATE temp_for_pkg_gen_sql2000_temp
- SET sql_text = rtrim(sql_text) ||
- trim(cur_con_cols_rec.column_name)
- WHERE line_no = n_line_no - 1
- AND object_type = v_object_type;
- ELSE
- UPDATE temp_for_pkg_gen_sql2000_temp
- SET sql_text = rtrim(sql_text) || ' , ' ||
- trim(cur_con_cols_rec.column_name)
- WHERE line_no = n_line_no - 1
- AND object_type = v_object_type;
- END IF;
- END LOOP;
- UPDATE temp_for_pkg_gen_sql2000_temp
- SET sql_text = rtrim(sql_text) || ' )'
- WHERE line_no = n_line_no - 1
- AND object_type = v_object_type;
- ELSE
- IF v_type = 'P' or v_type = 'U' THEN
- UPDATE temp_for_pkg_gen_sql2000_temp
- SET sql_text = rtrim(sql_text) || ' USING INDEX '
- WHERE line_no = n_line_no - 1
- AND object_type = v_object_type;
- END IF;
- END IF;
- UPDATE temp_for_pkg_gen_sql2000_temp
- SET sql_text = sql_text || ';'
- WHERE line_no = n_line_no - 1
- AND object_type = v_object_type;
- v_sql := ' ';
- insert_rec(n_line_no,
- v_object_type,
- v_username,
- cur_cons_rec.constraint_name,
- v_sql);
- n_line_no := n_line_no + 1;
- END IF;
- END IF;
- END LOOP;
- CLOSE cur_cons;
- END LOOP;
- COMMIT;
- END;
- PROCEDURE pro_indx_sql(p_v_gen_drop_sql VARCHAR2 default 'T',
- p_v_gen_create_sql VARCHAR2 default 'T',
- p_v_gen_store_clause VARCHAR2 default 'T',
- p_v_gen_ts_only VARCHAR2 default 'F',
- p_v_display_prompt_info VARCHAR2 default 'T') AS
- CURSOR cur_indxes IS
- SELECT index_name,
- table_owner,
- table_name,
- index_type,
- uniqueness,
- tablespace_name,
- ini_trans,
- max_trans,
- initial_extent,
- next_extent,
- min_extents,
- max_extents,
- pct_increase,
- pct_free,
- freelists,
- freelist_groups,
- buffer_pool,
- decode(logging, 'YES', 'LOGGING', 'NOLOGGING') logging
- FROM user_indexes
- WHERE index_type <> 'LOB'
- ORDER BY index_name;
- CURSOR cur_cols(c_ind VARCHAR2, c_tab VARCHAR2) IS
- SELECT column_name
- FROM user_ind_columns
- WHERE index_name = c_ind
- AND table_name = c_tab
- ORDER BY column_position;
- CURSOR cur_fun_expression(c_ind VARCHAR2, c_tab VARCHAR2) IS
- SELECT column_expression
- FROM user_ind_expressions
- WHERE index_name = c_ind
- and table_name = c_tab;
- v_index_name user_indexes.index_name%TYPE;
- v_table_owner user_indexes.table_owner%TYPE;
- v_table_name user_indexes.table_name%TYPE;
- v_index_type user_indexes.index_type%TYPE;
- v_uniqueness user_indexes.uniqueness%TYPE;
- v_tablespace_name user_indexes.tablespace_name%TYPE;
- n_ini_trans user_indexes.ini_trans%TYPE;
- n_max_trans user_indexes.max_trans%TYPE;
- n_initial_extent user_indexes.initial_extent%TYPE;
- n_next_extent user_indexes.next_extent%TYPE;
- n_min_extents user_indexes.min_extents%TYPE;
- n_max_extents user_indexes.max_extents%TYPE;
- n_pct_increase user_indexes.pct_increase%TYPE;
- n_pct_free user_indexes.pct_free%TYPE;
- n_freelists user_indexes.freelists%TYPE;
- n_freelist_groups user_indexes.freelist_groups%TYPE;
- v_buffer_pool user_indexes.buffer_pool%TYPE;
- v_logging VARCHAR2(15);
- lv_column_name user_ind_columns.column_name%TYPE;
- b_first_rec BOOLEAN;
- v_string VARCHAR2(800);
- n_line_no NUMBER := 0;
- v_gen_drop_indx_sql VARCHAR2(10);
- v_gen_create_indx_sql VARCHAR2(10);
- v_gen_store_clause VARCHAR2(10);
- v_display_prompt_info VARCHAR2(10);
- v_gen_ts_only VARCHAR2(10);
- n_temp NUMBER(10, 0);
- v_object_type VARCHAR2(30);
- v_prompt VARCHAR2(30);
- v_username VARCHAR2(30);
- procedure insert_rec(p_line_no INTEGER,
- p_object_type VARCHAR2,
- p_user_name VARCHAR2,
- p_index_name VARCHAR2,
- p_string VARCHAR2) IS
- BEGIN
- INSERT INTO temp_for_pkg_gen_sql2000_temp
- (line_no, object_type, user_name, object_name, sql_text)
- VALUES
- (p_line_no, p_object_type, p_user_name, p_index_name, p_string);
- END;
- BEGIN
- v_gen_drop_indx_sql := p_v_gen_drop_sql;
- v_gen_create_indx_sql := p_v_gen_create_sql;
- v_gen_store_clause := p_v_gen_store_clause;
- v_gen_ts_only := p_v_gen_ts_only;
- v_display_prompt_info := p_v_display_prompt_info;
- v_object_type := 'INDEX';
- v_prompt := '-- prompt ';
- SELECT username INTO v_username FROM user_users;
- DELETE FROM temp_for_pkg_gen_sql2000_temp
- WHERE object_type = v_object_type;
- COMMIT;
- n_line_no := 1;
- OPEN cur_indxes;
- LOOP
- FETCH cur_indxes
- INTO v_index_name, v_table_owner, v_table_name, v_index_type, v_uniqueness, v_tablespace_name, n_ini_trans,
- n_max_trans, n_initial_extent, n_next_extent, n_min_extents, n_max_extents, n_pct_increase, n_pct_free, n_freelists,
- n_freelist_groups, v_buffer_pool, v_logging;
- EXIT WHEN cur_indxes%NOTFOUND;
- b_first_rec := TRUE;
- IF upper(v_gen_drop_indx_sql) = 'T' THEN
- IF upper(v_display_prompt_info) = 'T' THEN
- IF v_uniqueness = 'UNIQUE' AND v_index_type = 'NORMAL' THEN
- v_string := v_prompt || ' DROP UNIQUE INDEX ' ||
- lower(v_index_name);
- ELSIF v_uniqueness <> 'UNIQUE' AND v_index_type = 'NORMAL' THEN
- v_string := v_prompt || ' DROP INDEX ' || lower(v_index_name);
- ELSIF v_index_type = 'BITMAP' THEN
- v_string := v_prompt || ' DROP BITMAP INDEX ' ||
- lower(v_index_name);
- ELSIF v_uniqueness = 'UNIQUE' AND v_index_type = 'NORMAL/REV' THEN
- v_string := v_prompt || ' DROP UNIQUE, REVERSE INDEX ' ||
- lower(v_index_name);
- ELSIF v_uniqueness <> 'UNIQUE' AND v_index_type = 'NORMAL/REV' THEN
- v_string := v_prompt || ' DROP REVERSE INDEX ' ||
- lower(v_index_name);
- ELSIF v_uniqueness = 'UNIQUE' AND
- v_index_type = 'FUNCTION-BASED NORMAL' THEN
- v_string := v_prompt || ' DROP UNIQUE, FUNCTION INDEX ' ||
- lower(v_index_name);
- ELSIF v_uniqueness <> 'UNIQUE' AND
- v_index_type = 'FUNCTION-BASED NORMAL' THEN
- v_string := v_prompt || ' DROP FUNCTION INDEX ' ||
- lower(v_index_name);
- END IF;
- insert_rec(n_line_no,
- v_object_type,
- v_username,
- v_index_name,
- v_string);
- n_line_no := n_line_no + 1;
- END IF;
- v_string := 'DROP INDEX ' || lower(v_index_name) || ';';
- insert_rec(n_line_no,
- v_object_type,
- v_username,
- v_index_name,
- v_string);
- n_line_no := n_line_no + 1;
- v_string := ' ';
- insert_rec(n_line_no,
- v_object_type,
- v_username,
- v_index_name,
- v_string);
- n_line_no := n_line_no + 1;
- END IF;
- IF upper(v_gen_create_indx_sql) = 'T' THEN
- IF upper(p_v_display_prompt_info) = 'T' THEN
- IF v_uniqueness = 'UNIQUE' AND v_index_type = 'NORMAL' THEN
- v_string := v_prompt || ' CREATE UNIQUE INDEX ' ||
- lower(v_index_name);
- ELSIF v_uniqueness <> 'UNIQUE' AND v_index_type = 'NORMAL' THEN
- v_string := v_prompt || ' CREATE INDEX ' || lower(v_index_name);
- ELSIF v_index_type = 'BITMAP' THEN
- v_string := v_prompt || ' CREATE BITMAP INDEX ' ||
- lower(v_index_name);
- ELSIF v_uniqueness = 'UNIQUE' AND v_index_type = 'NORMAL/REV' THEN
- v_string := v_prompt || ' CREATE UNIQUE, REVERSE INDEX ' ||
- lower(v_index_name);
- ELSIF v_uniqueness <> 'UNIQUE' AND v_index_type = 'NORMAL/REV' THEN
- v_string := v_prompt || ' CREATE REVERSE INDEX ' ||
- lower(v_index_name);
- ELSIF v_uniqueness = 'UNIQUE' AND
- v_index_type = 'FUNCTION-BASED NORMAL' THEN
- v_string := v_prompt || ' CREATE UNIQUE, FUNCTION INDEX ' ||
- lower(v_index_name);
- ELSIF v_uniqueness <> 'UNIQUE' AND
- v_index_type = 'FUNCTION-BASED NORMAL' THEN
- v_string := v_prompt || ' CREATE FUNCTION INDEX ' ||
- lower(v_index_name);
- END IF;
- insert_rec(n_line_no,
- v_object_type,
- v_username,
- v_index_name,
- v_string);
- n_line_no := n_line_no + 1;
- END IF;
- IF v_uniqueness = 'UNIQUE' AND v_index_type = 'NORMAL' THEN
- v_string := 'CREATE UNIQUE INDEX ' || lower(v_index_name);
- insert_rec(n_line_no,
- v_object_type,
- v_username,
- v_index_name,
- v_string);
- n_line_no := n_line_no + 1;
- ELSIF v_uniqueness <> 'UNIQUE' AND v_index_type = 'NORMAL' THEN
- v_string := 'CREATE INDEX ' || lower(v_index_name);
- insert_rec(n_line_no,
- v_object_type,
- v_username,
- v_index_name,
- v_string);
- n_line_no := n_line_no + 1;
- ELSIF v_index_type = 'BITMAP' THEN
- v_string := 'CREATE BITMAP INDEX ' || lower(v_index_name);
- insert_rec(n_line_no,
- v_object_type,
- v_username,
- v_index_name,
- v_string);
- n_line_no := n_line_no + 1;
- ELSIF v_uniqueness = 'UNIQUE' AND v_index_type = 'NORMAL/REV' THEN
- v_string := 'CREATE UNIQUE INDEX ' || lower(v_index_name);
- insert_rec(n_line_no,
- v_object_type,
- v_username,
- v_index_name,
- v_string);
- n_line_no := n_line_no + 1;
- ELSIF v_uniqueness <> 'UNIQUE' AND v_index_type = 'NORMAL/REV' THEN
- v_string := 'CREATE INDEX ' || lower(v_index_name);
- insert_rec(n_line_no,
- v_object_type,
- v_username,
- v_index_name,
- v_string);
- n_line_no := n_line_no + 1;
- ELSIF v_uniqueness = 'UNIQUE' AND
- v_index_type = 'FUNCTION-BASED NORMAL' THEN
- v_string := 'CREATE UNIQUE INDEX ' || lower(v_index_name);
- insert_rec(n_line_no,
- v_object_type,
- v_username,
- v_index_name,
- v_string);
- n_line_no := n_line_no + 1;
- ELSIF v_uniqueness <> 'UNIQUE' AND
- v_index_type = 'FUNCTION-BASED NORMAL' THEN
- v_string := 'CREATE INDEX ' || lower(v_index_name);
- insert_rec(n_line_no,
- v_object_type,
- v_username,
- v_index_name,
- v_string);
- n_line_no := n_line_no + 1;
- END IF;
- IF v_index_type <> 'FUNCTION-BASED NORMAL' THEN
- OPEN cur_cols(v_index_name, v_table_name);
- LOOP
- FETCH cur_cols
- INTO lv_column_name;
- EXIT WHEN cur_cols%NOTFOUND;
- IF (b_first_rec) THEN
- v_string := chr(9) || 'ON ' || lower(v_table_name) || ' (';
- b_first_rec := FALSE;
- ELSE
- v_string := v_string || ', ';
- END IF;
- v_string := v_string || lower(lv_column_name);
- END LOOP;
- CLOSE cur_cols;
- ELSE
- OPEN cur_fun_expression(v_index_name, v_table_name);
- LOOP
- FETCH cur_fun_expression
- INTO lv_column_name;
- EXIT WHEN cur_fun_expression%NOTFOUND;
- lv_column_name := replace(lv_column_name, '"', '');
- v_string := chr(9) || 'ON ' || lower(v_table_name) || ' (';
- n_temp := length(v_string);
- n_temp := length(chr(9));
- v_string := v_string || lower(lv_column_name);
- END LOOP;
- CLOSE cur_fun_expression;
- END IF;
- v_string := v_string || ')';
- insert_rec(n_line_no,
- v_object_type,
- v_username,
- v_index_name,
- v_string);
- n_line_no := n_line_no + 1;
- IF upper(v_gen_store_clause) = 'T' THEN
- v_string := null;
- v_string := v_logging;
- insert_rec(n_line_no,
- v_object_type,
- v_username,
- v_index_name,
- v_string);
- n_line_no := n_line_no + 1;
- v_string := 'PCTFREE ' || to_char(n_pct_free);
- insert_rec(n_line_no,
- v_object_type,
- v_username,
- v_index_name,
- v_string);
- n_line_no := n_line_no + 1;
- v_string := 'INITRANS ' || to_char(n_ini_trans) || ' MAXTRANS ' ||
- to_char(n_max_trans);
- insert_rec(n_line_no,
- v_object_type,
- v_username,
- v_index_name,
- v_string);
- n_line_no := n_line_no + 1;
- v_string := 'TABLESPACE ' || v_tablespace_name || ' ';
- insert_rec(n_line_no,
- v_object_type,
- v_username,
- v_index_name,
- v_string);
- n_line_no := n_line_no + 1;
- v_string := 'STORAGE (';
- insert_rec(n_line_no,
- v_object_type,
- v_username,
- v_index_name,
- v_string);
- n_line_no := n_line_no + 1;
- v_string := chr(9) || 'INITIAL ' || to_char(n_initial_extent);
- IF n_next_extent IS NOT NULL THEN
- v_string := v_string || ' NEXT ' || to_char(n_next_extent);
- END IF;
- insert_rec(n_line_no,
- v_object_type,
- v_username,
- v_index_name,
- v_string);
- n_line_no := n_line_no + 1;
- v_string := chr(9) || 'MINEXTENTS ' || to_char(n_min_extents) ||
- ' MAXEXTENTS ' || to_char(n_max_extents) ||
- ' PCTINCREASE ' || to_char(nvl(n_pct_increase, 0));
- insert_rec(n_line_no,
- v_object_type,
- v_username,
- v_index_name,
- v_string);
- n_line_no := n_line_no + 1;
- v_string := chr(9) || 'FREELISTS ' || to_char(n_freelists) ||
- ' FREELIST GROUPS ' || to_char(n_freelist_groups);
- insert_rec(n_line_no,
- v_object_type,
- v_username,
- v_index_name,
- v_string);
- n_line_no := n_line_no + 1;
- v_string := chr(9) || 'BUFFER_POOL ' || v_buffer_pool || ' ';
- insert_rec(n_line_no,
- v_object_type,
- v_username,
- v_index_name,
- v_string);
- n_line_no := n_line_no + 1;
- UPDATE temp_for_pkg_gen_sql2000_temp
- SET sql_text = sql_text || ')'
- WHERE line_no = n_line_no - 1
- AND object_type = v_object_type;
- ELSE
- IF upper(v_gen_store_clause) = 'F' AND upper(v_gen_ts_only) = 'T' THEN
- v_string := 'TABLESPACE ' || v_tablespace_name || ' ';
- insert_rec(n_line_no,
- v_object_type,
- v_username,
- v_index_name,
- v_string);
- n_line_no := n_line_no + 1;
- END IF;
- END IF;
- IF v_index_type <> 'NORMAL/REV' THEN
- UPDATE temp_for_pkg_gen_sql2000_temp
- SET sql_text = sql_text || ';'
- WHERE line_no = n_line_no - 1
- AND object_type = v_object_type;
- ELSE
- UPDATE temp_for_pkg_gen_sql2000_temp
- SET sql_text = sql_text || ' REVERSE;'
- WHERE line_no = n_line_no - 1
- AND object_type = v_object_type;
- END IF;
- v_string := ' ';
- insert_rec(n_line_no,
- v_object_type,
- v_username,
- v_index_name,
- v_string);
- n_line_no := n_line_no + 1;
- END IF;
- END LOOP;
- CLOSE cur_indxes;
- SELECT COUNT(*) INTO n_temp FROM user_indexes WHERE index_type = 'LOB';
- IF n_temp > 0 THEN
- v_string := ' ';
- insert_rec(n_line_no,
- v_object_type,
- v_username,
- 'LOB INDEX',
- v_string);
- n_line_no := n_line_no + 1;
- v_string := '-- There is some LOB index, and we don''t list;';
- insert_rec(n_line_no,
- v_object_type,
- v_username,
- 'LOB INDEX',
- v_string);
- n_line_no := n_line_no + 1;
- v_string := ' ';
- insert_rec(n_line_no,
- v_object_type,
- v_username,
- 'LOB INDEX',
- v_string);
- n_line_no := n_line_no + 1;
- v_string := ' ';
- insert_rec(n_line_no,
- v_object_type,
- v_username,
- 'LOB INDEX',
- v_string);
- n_line_no := n_line_no + 1;
- END IF;
- COMMIT;
- END;
- PROCEDURE pro_reb_indx_sql(p_v_gen_store_clause VARCHAR2 default 'T',
- p_v_rebuild_online VARCHAR2 default 'T',
- p_v_display_prompt_info VARCHAR2 default 'T') AS
- CURSOR cur_indxes IS
- SELECT index_name,
- table_owner,
- table_name,
- index_type,
- uniqueness,
- tablespace_name,
- ini_trans,
- max_trans,
- initial_extent,
- next_extent,
- min_extents,
- max_extents,
- pct_increase,
- pct_free,
- freelists,
- freelist_groups,
- buffer_pool,
- decode(logging, 'YES', 'LOGGING', 'NOLOGGING') logging
- FROM user_indexes
- WHERE index_type <> 'LOB'
- ORDER BY index_name;
- v_index_name user_indexes.index_name%TYPE;
- v_table_owner user_indexes.table_owner%TYPE;
- v_table_name user_indexes.table_name%TYPE;
- v_index_type user_indexes.index_type%TYPE;
- v_uniqueness user_indexes.uniqueness%TYPE;
- v_tablespace_name user_indexes.tablespace_name%TYPE;
- n_ini_trans user_indexes.ini_trans%TYPE;
- n_max_trans user_indexes.max_trans%TYPE;
- n_initial_extent user_indexes.initial_extent%TYPE;
- n_next_extent user_indexes.next_extent%TYPE;
- n_min_extents user_indexes.min_extents%TYPE;
- n_max_extents user_indexes.max_extents%TYPE;
- n_pct_increase user_indexes.pct_increase%TYPE;
- n_pct_free user_indexes.pct_free%TYPE;
- n_freelists user_indexes.freelists%TYPE;
- n_freelist_groups user_indexes.freelist_groups%TYPE;
- v_buffer_pool user_indexes.buffer_pool%TYPE;
- v_logging VARCHAR2(15);
- lv_column_name user_ind_columns.column_name%TYPE;
- b_first_rec BOOLEAN;
- v_string VARCHAR2(800);
- n_line_no NUMBER := 0;
- v_gen_store_clause VARCHAR2(10);
- v_rebuild_online VARCHAR2(10);
- v_display_prompt_info VARCHAR2(10);
- n_temp NUMBER(10, 0);
- v_object_type VARCHAR2(30);
- v_prompt VARCHAR2(30);
- v_username VARCHAR2(30);
- PROCEDURE insert_rec(p_line_no INTEGER,
- p_object_type VARCHAR2,
- p_user_name VARCHAR2,
- p_index_name VARCHAR2,
- p_string VARCHAR2) IS
- BEGIN
- INSERT INTO temp_for_pkg_gen_sql2000_temp
- (line_no, object_type, user_name, object_name, sql_text)
- VALUES
- (p_line_no, p_object_type, p_user_name, p_index_name, p_string);
- END;
- BEGIN
- v_gen_store_clause := p_v_gen_store_clause;
- v_display_prompt_info := p_v_display_prompt_info;
- v_rebuild_online := p_v_rebuild_online;
- v_object_type := 'REBUILD_INDEX';
- v_prompt := '-- prompt ';
- SELECT username INTO v_username FROM user_users;
- DELETE FROM temp_for_pkg_gen_sql2000_temp
- WHERE object_type = v_object_type;
- COMMIT;
- n_line_no := 1;
- OPEN cur_indxes;
- LOOP
- FETCH cur_indxes
- INTO v_index_name, v_table_owner, v_table_name, v_index_type, v_uniqueness, v_tablespace_name, n_ini_trans,
- n_max_trans, n_initial_extent, n_next_extent, n_min_extents, n_max_extents, n_pct_increase, n_pct_free, n_freelists,
- n_freelist_groups, v_buffer_pool, v_logging;
- EXIT WHEN cur_indxes%NOTFOUND;
- b_first_rec := TRUE;
- IF upper(p_v_display_prompt_info) = 'T' THEN
- IF v_rebuild_online = 'T' THEN
- v_string := v_prompt || ' REBUILD INDEX ' || lower(v_index_name) ||
- ' ONLINE ';
- ELSE
- v_string := v_prompt || ' REBUILD INDEX ' || lower(v_index_name);
- END IF;
- insert_rec(n_line_no,
- v_object_type,
- v_username,
- v_index_name,
- v_string);
- n_line_no := n_line_no + 1;
- END IF;
- IF v_rebuild_online = 'T' THEN
- v_string := 'ALTER INDEX ' || lower(v_index_name) ||
- ' REBUILD ONLINE ';
- ELSE
- v_string := 'ALTER INDEX ' || lower(v_index_name) || ' REBUILD ';
- END IF;
- insert_rec(n_line_no,
- v_object_type,
- v_username,
- v_index_name,
- v_string);
- n_line_no := n_line_no + 1;
- IF upper(v_gen_store_clause) = 'T' THEN
- v_string := null;
- v_string := v_logging;
- insert_rec(n_line_no,
- v_object_type,
- v_username,
- v_index_name,
- v_string);
- n_line_no := n_line_no + 1;
- v_string := 'PCTFREE ' || to_char(n_pct_free);
- insert_rec(n_line_no,
- v_object_type,
- v_username,
- v_index_name,
- v_string);
- n_line_no := n_line_no + 1;
- v_string := 'INITRANS ' || to_char(n_ini_trans) || ' MAXTRANS ' ||
- to_char(n_max_trans);
- insert_rec(n_line_no,
- v_object_type,
- v_username,
- v_index_name,
- v_string);
- n_line_no := n_line_no + 1;
- v_string := 'TABLESPACE ' || v_tablespace_name || ' ';
- insert_rec(n_line_no,
- v_object_type,
- v_username,
- v_index_name,
- v_string);
- n_line_no := n_line_no + 1;
- v_string := 'STORAGE (';
- insert_rec(n_line_no,
- v_object_type,
- v_username,
- v_index_name,
- v_string);
- n_line_no := n_line_no + 1;
- v_string := chr(9) || 'INITIAL ' || to_char(n_initial_extent);
- IF n_next_extent IS NOT NULL THEN
- v_string := v_string || ' NEXT ' || to_char(n_next_extent);
- END IF;
- insert_rec(n_line_no,
- v_object_type,
- v_username,
- v_index_name,
- v_string);
- n_line_no := n_line_no + 1;
- v_string := chr(9) || 'MINEXTENTS ' || to_char(n_min_extents) ||
- ' MAXEXTENTS ' || to_char(n_max_extents) ||
- ' PCTINCREASE ' || to_char(nvl(n_pct_increase, 0));
- insert_rec(n_line_no,
- v_object_type,
- v_username,
- v_index_name,
- v_string);
- n_line_no := n_line_no + 1;
- IF n_freelists IS NOT NULL AND n_freelist_groups IS NOT NULL THEN
- v_string := chr(9) || 'FREELISTS ' || to_char(n_freelists) ||
- ' FREELIST GROUPS ' || to_char(n_freelist_groups);
- insert_rec(n_line_no,
- v_object_type,
- v_username,
- v_index_name,
- v_string);
- n_line_no := n_line_no + 1;
- END IF;
- v_string := chr(9) || 'BUFFER_POOL ' || v_buffer_pool || ' ';
- insert_rec(n_line_no,
- v_object_type,
- v_username,
- v_index_name,
- v_string);
- n_line_no := n_line_no + 1;
- UPDATE temp_for_pkg_gen_sql2000_temp
- SET sql_text = sql_text || ')'
- WHERE line_no = n_line_no - 1
- AND object_type = v_object_type;
- END IF;
- UPDATE temp_for_pkg_gen_sql2000_temp
- SET sql_text = sql_text || ';'
- WHERE line_no = n_line_no - 1
- AND object_type = v_object_type;
- v_string := ' ';
- insert_rec(n_line_no,
- v_object_type,
- v_username,
- v_index_name,
- v_string);
- n_line_no := n_line_no + 1;
- END LOOP;
- CLOSE cur_indxes;
- SELECT COUNT(*) INTO n_temp FROM user_indexes WHERE index_type = 'LOB';
- IF n_temp > 0 THEN
- v_string := ' ';
- insert_rec(n_line_no,
- v_object_type,
- v_username,
- 'LOB INDEX',
- v_string);
- n_line_no := n_line_no + 1;
- v_string := '-- There is some LOB index, and we don''t list;';
- insert_rec(n_line_no,
- v_object_type,
- v_username,
- 'LOB INDEX',
- v_string);
- n_line_no := n_line_no + 1;
- v_string := ' ';
- insert_rec(n_line_no,
- v_object_type,
- v_username,
- 'LOB INDEX',
- v_string);
- n_line_no := n_line_no + 1;
- v_string := ' ';
- insert_rec(n_line_no,
- v_object_type,
- v_username,
- 'LOB INDEX',
- v_string);
- n_line_no := n_line_no + 1;
- END IF;
- COMMIT;
- END;
- PROCEDURE pro_view_sql(p_v_gen_drop_sql VARCHAR2 default 'T',
- p_v_gen_create_sql VARCHAR2 default 'T',
- p_v_display_prompt_info VARCHAR2 default 'T') AS
- CURSOR cur_views IS
- select view_name, text from user_views order by view_name;
- CURSOR cur_cols(v_name VARCHAR2) IS
- SELECT table_name,
- column_name,
- data_type,
- data_length,
- data_precision,
- data_scale,
- nullable,
- data_default
- FROM user_tab_columns
- WHERE table_name = v_name
- ORDER BY column_id;
- v_username VARCHAR2(30);
- v_view_name VARCHAR2(100);
- v_col_names VARCHAR2(2000);
- v_text VARCHAR2(30000);
- v_sql VARCHAR2(30000);
- v_sql_temp VARCHAR2(30000);
- n_line_no NUMBER(10, 0);
- n38_count NUMBER(38, 0);
- n_position NUMBER(38, 0);
- v_object_type VARCHAR2(30);
- v_prompt VARCHAR2(30);
- PROCEDURE insert_rec(p_line_no INTEGER,
- p_object_type VARCHAR2,
- p_user_name VARCHAR2,
- p_view_name VARCHAR2,
- p_string VARCHAR2) IS
- BEGIN
- INSERT INTO temp_for_pkg_gen_sql4000_temp
- (line_no, object_type, user_name, object_name, sql_text)
- VALUES
- (p_line_no, p_object_type, p_user_name, p_view_name, p_string);
- END;
- BEGIN
- v_object_type := 'VIEW';
- v_prompt := '-- prompt ';
- SELECT username INTO v_username FROM user_users;
- DELETE temp_for_pkg_gen_sql4000_temp WHERE object_type = v_object_type;
- COMMIT;
- n_line_no := 1;
- OPEN cur_views;
- LOOP
- FETCH cur_views
- INTO v_view_name, v_text;
- EXIT WHEN cur_views%NOTFOUND;
- IF upper(p_v_gen_drop_sql) = 'T' THEN
- IF upper(p_v_display_prompt_info) = 'T' THEN
- v_sql := v_prompt || ' DROP VIEW ' || v_view_name;
- insert_rec(n_line_no,
- v_object_type,
- v_username,
- v_view_name,
- v_sql);
- n_line_no := n_line_no + 1;
- END IF;
- v_sql := 'DROP VIEW ' || v_view_name || ';';
- insert_rec(n_line_no,
- v_object_type,
- v_username,
- v_view_name,
- v_sql);
- n_line_no := n_line_no + 1;
- v_sql := ' ';
- insert_rec(n_line_no,
- v_object_type,
- v_username,
- v_view_name,
- v_sql);
- n_line_no := n_line_no + 1;
- END IF;
- IF upper(p_v_gen_create_sql) = 'T' THEN
- IF upper(p_v_display_prompt_info) = 'T' THEN
- v_sql := v_prompt || ' CREATE VIEW ' || v_view_name;
- insert_rec(n_line_no,
- v_object_type,
- v_username,
- v_view_name,
- v_sql);
- n_line_no := n_line_no + 1;
- END IF;
- v_sql := 'CREATE OR REPLACE VIEW ' || v_view_name;
- insert_rec(n_line_no,
- v_object_type,
- v_username,
- v_view_name,
- v_sql);
- n_line_no := n_line_no + 1;
- v_sql := '(';
- insert_rec(n_line_no,
- v_object_type,
- v_username,
- v_view_name,
- v_sql);
- n_line_no := n_line_no + 1;
- v_col_names := '';
- n38_count := 0;
- FOR cur_cols_rec IN cur_cols(v_view_name) LOOP
- v_col_names := v_col_names || cur_cols_rec.column_name || ', ';
- n38_count := n38_count + 1;
- IF MOD(n38_count, 5) = 0 THEN
- v_sql := chr(9) || v_col_names;
- insert_rec(n_line_no,
- v_object_type,
- v_username,
- v_view_name,
- v_sql);
- n_line_no := n_line_no + 1;
- v_col_names := '';
- END IF;
- END LOOP;
- IF length(v_col_names) > 2 THEN
- v_col_names := substr(v_col_names, 1, length(v_col_names) - 2);
- v_sql := chr(9) || v_col_names;
- insert_rec(n_line_no,
- v_object_type,
- v_username,
- v_view_name,
- v_sql);
- n_line_no := n_line_no + 1;
- ELSE
- UPDATE temp_for_pkg_gen_sql4000_temp
- SET sql_text = substr(sql_text, 1, length(sql_text) - 2)
- WHERE line_no = n_line_no - 1
- AND object_type = v_object_type;
- END IF;
- v_sql := ')';
- insert_rec(n_line_no,
- v_object_type,
- v_username,
- v_view_name,
- v_sql);
- n_line_no := n_line_no + 1;
- v_sql := 'AS';
- insert_rec(n_line_no,
- v_object_type,
- v_username,
- v_view_name,
- v_sql);
- n_line_no := n_line_no + 1;
- v_text := replace(v_text, ',', ', ');
- v_sql := v_text;
- IF length(v_sql) > 3800 THEN
- WHILE length(v_sql) > 3800 LOOP
- n_position := instr(substr(v_sql, 1, 3800), ',', -1);
- insert_rec(n_line_no,
- v_object_type,
- v_username,
- v_view_name,
- substr(v_sql, 1, n_position));
- v_sql := substr(v_sql, n_position + 1);
- END LOOP;
- insert_rec(n_line_no,
- v_object_type,
- v_username,
- v_view_name,
- v_sql);
- ELSE
- insert_rec(n_line_no,
- v_object_type,
- v_username,
- v_view_name,
- v_sql);
- END IF;
- n_line_no := n_line_no + 1;
- UPDATE temp_for_pkg_gen_sql4000_temp
- SET sql_text = sql_text || ';'
- WHERE line_no = n_line_no - 1
- AND object_type = v_object_type;
- v_sql := ' ';
- insert_rec(n_line_no,
- v_object_type,
- v_username,
- v_view_name,
- v_sql);
- n_line_no := n_line_no + 1;
- END IF;
- END LOOP;
- CLOSE cur_views;
- COMMIT;
- END;
- PROCEDURE pro_seq_max_val_sql(p_v_gen_drop_sql VARCHAR2 default 'T',
- p_v_gen_create_sql VARCHAR2 default 'T',
- p_v_display_prompt_info VARCHAR2 default 'T') AS
- v_sql VARCHAR2(500);
- n_max_id NUMBER(38, 0);
- v_max_val VARCHAR2(1000);
- CURSOR cur_etl_data IS
- SELECT table_name FROM user_tables;
- rec_etl_data cur_etl_data%rowtype;
- type ref_cur is REF CURSOR; -- 定义一个ref 类型的游标
- cur_id ref_cur;
- CURSOR cur_cols(t_name VARCHAR2) IS
- SELECT column_name, data_type
- FROM user_tab_columns
- WHERE table_name = t_name
- ORDER BY column_id;
- rec_col_name cur_cols%rowtype;
- v_sequence_name VARCHAR2(50);
- n_line_no NUMBER(38, 0);
- v_object_type VARCHAR2(30);
- v_prompt VARCHAR2(30);
- v_username VARCHAR2(30);
- PROCEDURE insert_rec(p_line_no INTEGER,
- p_object_type VARCHAR2,
- p_user_name VARCHAR2,
- p_sequence_name VARCHAR2,
- p_string VARCHAR2) IS
- BEGIN
- INSERT INTO temp_for_pkg_gen_sql2000_temp
- (line_no, object_type, user_name, object_name, sql_text)
- VALUES
- (p_line_no, p_object_type, p_user_name, p_sequence_name, p_string);
- END;
- BEGIN
- n_line_no := 1;
- v_object_type := 'SEQUENCE_CHAR';
- v_prompt := '-- prompt ';
- SELECT username INTO v_username FROM user_users;
- DELETE temp_for_pkg_gen_sql2000_temp WHERE object_type = v_object_type;
- COMMIT;
- OPEN cur_etl_data;
- LOOP
- FETCH cur_etl_data
- INTO rec_etl_data;
- EXIT WHEN cur_etl_data%NOTFOUND;
- -- 得到表的第一个列
- OPEN cur_cols(rec_etl_data.table_name);
- LOOP
- FETCH cur_cols
- INTO rec_col_name;
- EXIT WHEN cur_cols%NOTFOUND;
- EXIT;
- END LOOP;
- CLOSE cur_cols;
- IF rec_col_name.data_type = 'VARCHAR2' OR
- rec_col_name.data_type = 'VARCHAR' OR
- rec_col_name.data_type = 'CHAR' THEN
- BEGIN
- v_sql := 'SELECT max(to_NUMBER(' || rec_col_name.column_name ||
- ')) FROM ' || rec_etl_data.table_name || '';
- OPEN cur_id FOR v_sql;
- LOOP
- FETCH cur_id
- INTO v_max_val;
- EXIT WHEN cur_id%NOTFOUND;
- EXIT;
- END LOOP;
- CLOSE cur_id;
- EXCEPTION
- WHEN others THEN
- IF cur_id%ISOPEN THEN
- CLOSE cur_id;
- END IF;
- v_max_val := '-1000';
- END;
- ELSIF rec_col_name.data_type = 'NUMBER' THEN
- v_sql := 'SELECT max(' || rec_col_name.column_name || ') FROM ' ||
- rec_etl_data.table_name || '';
- OPEN cur_id FOR v_sql;
- LOOP
- FETCH cur_id
- INTO n_max_id;
- EXIT WHEN cur_id%NOTFOUND;
- EXIT;
- END LOOP;
- CLOSE cur_id;
- END IF;
- -- need modify, generate sequence name
- v_sequence_name := 'seq_' || substr(rec_etl_data.table_name, 3) ||
- '_id';
- IF p_v_gen_drop_sql = 'T' THEN
- IF p_v_display_prompt_info = 'T' THEN
- v_sql := v_prompt || ' DROP SEQUENCE ' || v_sequence_name;
- insert_rec(n_line_no,
- v_object_type,
- v_username,
- v_sequence_name,
- v_sql);
- n_line_no := n_line_no + 1;
- END IF;
- v_sql := 'DROP SEQUENCE ' || v_sequence_name || ';';
- insert_rec(n_line_no,
- v_object_type,
- v_username,
- v_sequence_name,
- v_sql);
- n_line_no := n_line_no + 1;
- v_sql := ' ';
- insert_rec(n_line_no,
- v_object_type,
- v_username,
- v_sequence_name,
- v_sql);
- n_line_no := n_line_no + 1;
- END IF;
- IF p_v_gen_create_sql = 'T' THEN
- IF p_v_display_prompt_info = 'T' THEN
- v_sql := v_prompt || ' CREATE SEQUENCE ' || v_sequence_name;
- insert_rec(n_line_no,
- v_object_type,
- v_username,
- v_sequence_name,
- v_sql);
- n_line_no := n_line_no + 1;
- END IF;
- v_sql := 'CREATE SEQUENCE ' || v_sequence_name;
- insert_rec(n_line_no,
- v_object_type,
- v_username,
- v_sequence_name,
- v_sql);
- n_line_no := n_line_no + 1;
- -- handle the station : treate the sequence value as varchar column(primary key)
- IF rec_col_name.data_type = 'VARCHAR2' OR
- rec_col_name.data_type = 'VARCHAR' OR
- rec_col_name.data_type = 'CHAR' THEN
- v_sql := 'START WITH ' ||
- to_char(to_number(nvl(v_max_val, '1')) + 1) || ' ';
- ELSIF rec_col_name.data_type = 'NUMBER' THEN
- v_sql := 'START WITH ' || TO_CHAR(nvl(n_max_id, 1) + 1) || ' ';
- END IF;
- insert_rec(n_line_no,
- v_object_type,
- v_username,
- v_sequence_name,
- v_sql);
- n_line_no := n_line_no + 1;
- v_sql := 'INCREMENT BY 1 ';
- insert_rec(n_line_no,
- v_object_type,
- v_username,
- v_sequence_name,
- v_sql);
- n_line_no := n_line_no + 1;
- v_sql := 'CACHE 100 NOCYCLE ';
- insert_rec(n_line_no,
- v_object_type,
- v_username,
- v_sequence_name,
- v_sql);
- n_line_no := n_line_no + 1;
- UPDATE temp_for_pkg_gen_sql2000_temp
- SET sql_text = sql_text || ';'
- WHERE line_no = n_line_no - 1
- AND object_type = v_object_type;
- v_sql := ' ';
- insert_rec(n_line_no,
- v_object_type,
- v_username,
- v_sequence_name,
- v_sql);
- n_line_no := n_line_no + 1;
- END IF;
- END LOOP;
- CLOSE cur_etl_data;
- COMMIT;
- END;
- PROCEDURE pro_seq_next_val_sql(p_v_gen_drop_sql VARCHAR2 default 'T',
- p_v_gen_create_sql VARCHAR2 default 'T',
- p_v_display_prompt_info VARCHAR2 default 'T') AS
- v_sql VARCHAR2(2000);
- n_max_id NUMBER(38, 0);
- v_max_val VARCHAR2(1000);
- CURSOR cur_sequence IS
- SELECT * FROM user_sequences;
- rec_cur_sequence cur_sequence%rowtype;
- v_sequence_name VARCHAR2(50);
- n_line_no NUMBER(38, 0);
- v_object_type VARCHAR2(30);
- v_prompt VARCHAR2(30);
- v_username VARCHAR2(30);
- PROCEDURE insert_rec(p_line_no INTEGER,
- p_object_type VARCHAR2,
- p_user_name VARCHAR2,
- p_sequence_name VARCHAR2,
- p_string VARCHAR2) IS
- BEGIN
- INSERT INTO temp_for_pkg_gen_sql2000_temp
- (line_no, object_type, user_name, object_name, sql_text)
- VALUES
- (p_line_no, p_object_type, p_user_name, p_sequence_name, p_string);
- END;
- BEGIN
- n_line_no := 1;
- v_object_type := 'SEQUENCE';
- v_prompt := '-- prompt ';
- SELECT username INTO v_username FROM user_users;
- DELETE temp_for_pkg_gen_sql2000_temp WHERE object_type = v_object_type;
- COMMIT;
- OPEN cur_sequence;
- LOOP
- FETCH cur_sequence
- INTO rec_cur_sequence;
- EXIT WHEN cur_sequence%NOTFOUND;
- IF p_v_gen_drop_sql = 'T' THEN
- IF p_v_display_prompt_info = 'T' THEN
- v_sql := v_prompt || ' DROP SEQUENCE ' ||
- rec_cur_sequence.sequence_name;
- insert_rec(n_line_no,
- v_object_type,
- v_username,
- rec_cur_sequence.sequence_name,
- v_sql);
- n_line_no := n_line_no + 1;
- END IF;
- v_sql := 'DROP SEQUENCE ' || rec_cur_sequence.sequence_name || ';';
- insert_rec(n_line_no,
- v_object_type,
- v_username,
- rec_cur_sequence.sequence_name,
- v_sql);
- n_line_no := n_line_no + 1;
- v_sql := ' ';
- insert_rec(n_line_no,
- v_object_type,
- v_username,
- rec_cur_sequence.sequence_name,
- v_sql);
- n_line_no := n_line_no + 1;
- END IF;
- IF p_v_gen_create_sql = 'T' THEN
- IF p_v_display_prompt_info = 'T' THEN
- v_sql := v_prompt || ' CREATE SEQUENCE ' ||
- rec_cur_sequence.sequence_name;
- insert_rec(n_line_no,
- v_object_type,
- v_username,
- rec_cur_sequence.sequence_name,
- v_sql);
- n_line_no := n_line_no + 1;
- END IF;
- v_sql := 'CREATE SEQUENCE ' || rec_cur_sequence.sequence_name;
- insert_rec(n_line_no,
- v_object_type,
- v_username,
- rec_cur_sequence.sequence_name,
- v_sql);
- n_line_no := n_line_no + 1;
- v_sql := 'MINVALUE ' || to_char(rec_cur_sequence.min_value);
- insert_rec(n_line_no,
- v_object_type,
- v_username,
- rec_cur_sequence.sequence_name,
- v_sql);
- n_line_no := n_line_no + 1;
- v_sql := 'MAXVALUE ' || to_char(rec_cur_sequence.max_value);
- insert_rec(n_line_no,
- v_object_type,
- v_username,
- rec_cur_sequence.sequence_name,
- v_sql);
- n_line_no := n_line_no + 1;
- v_sql := 'START WITH ' || to_char(rec_cur_sequence.last_number);
- insert_rec(n_line_no,
- v_object_type,
- v_username,
- rec_cur_sequence.sequence_name,
- v_sql);
- n_line_no := n_line_no + 1;
- v_sql := 'INCREMENT BY ' || to_char(rec_cur_sequence.increment_by);
- insert_rec(n_line_no,
- v_object_type,
- v_username,
- rec_cur_sequence.sequence_name,
- v_sql);
- n_line_no := n_line_no + 1;
- IF rec_cur_sequence.cache_size = 0 THEN
- v_sql := 'NOCACHE ';
- ELSE
- v_sql := 'CACHE ' || to_char(rec_cur_sequence.cache_size);
- END IF;
- IF rec_cur_sequence.cycle_flag = 'N' THEN
- v_sql := v_sql || ' NOCYCLE ';
- ELSE
- v_sql := v_sql || ' CYCLE ';
- END IF;
- insert_rec(n_line_no,
- v_object_type,
- v_username,
- rec_cur_sequence.sequence_name,
- v_sql);
- n_line_no := n_line_no + 1;
- UPDATE temp_for_pkg_gen_sql2000_temp
- SET sql_text = sql_text || ';'
- WHERE line_no = n_line_no - 1
- AND object_type = v_object_type;
- v_sql := ' ';
- insert_rec(n_line_no,
- v_object_type,
- v_username,
- rec_cur_sequence.sequence_name,
- v_sql);
- n_line_no := n_line_no + 1;
- END IF;
- END LOOP;
- CLOSE cur_sequence;
- COMMIT;
- END;
- PROCEDURE pro_seq_init_val_sql(p_v_gen_drop_sql VARCHAR2 default 'T',
- p_v_gen_create_sql VARCHAR2 default 'T',
- p_v_display_prompt_info VARCHAR2 default 'T') AS
- v_sql VARCHAR2(2000);
- n_max_id NUMBER(38, 0);
- v_max_val VARCHAR2(1000);
- CURSOR cur_sequence IS
- SELECT * FROM user_sequences;
- rec_cur_sequence cur_sequence%rowtype;
- v_sequence_name VARCHAR2(50);
- n_line_no NUMBER(38, 0);
- v_object_type VARCHAR2(30);
- v_prompt VARCHAR2(30);
- v_username VARCHAR2(30);
- PROCEDURE insert_rec(p_line_no INTEGER,
- p_object_type VARCHAR2,
- p_user_name VARCHAR2,
- p_sequence_name VARCHAR2,
- p_string VARCHAR2) IS
- BEGIN
- INSERT INTO temp_for_pkg_gen_sql2000_temp
- (line_no, object_type, user_name, object_name, sql_text)
- VALUES
- (p_line_no, p_object_type, p_user_name, p_sequence_name, p_string);
- END;
- BEGIN
- n_line_no := 1;
- v_object_type := 'SEQUENCE_INIT';
- v_prompt := '-- prompt ';
- SELECT username INTO v_username FROM user_users;
- DELETE temp_for_pkg_gen_sql2000_temp WHERE object_type = v_object_type;
- COMMIT;
- OPEN cur_sequence;
- LOOP
- FETCH cur_sequence
- INTO rec_cur_sequence;
- EXIT WHEN cur_sequence%NOTFOUND;
- IF p_v_gen_drop_sql = 'T' THEN
- IF p_v_display_prompt_info = 'T' THEN
- v_sql := v_prompt || ' DROP SEQUENCE ' ||
- rec_cur_sequence.sequence_name;
- insert_rec(n_line_no,
- v_object_type,
- v_username,
- rec_cur_sequence.sequence_name,
- v_sql);
- n_line_no := n_line_no + 1;
- END IF;
- v_sql := 'DROP SEQUENCE ' || rec_cur_sequence.sequence_name || ';';
- insert_rec(n_line_no,
- v_object_type,
- v_username,
- rec_cur_sequence.sequence_name,
- v_sql);
- n_line_no := n_line_no + 1;
- v_sql := ' ';
- insert_rec(n_line_no,
- v_object_type,
- v_username,
- rec_cur_sequence.sequence_name,
- v_sql);
- n_line_no := n_line_no + 1;
- END IF;
- IF p_v_gen_create_sql = 'T' THEN
- IF p_v_display_prompt_info = 'T' THEN
- v_sql := v_prompt || ' CREATE SEQUENCE ' ||
- rec_cur_sequence.sequence_name;
- insert_rec(n_line_no,
- v_object_type,
- v_username,
- rec_cur_sequence.sequence_name,
- v_sql);
- n_line_no := n_line_no + 1;
- END IF;
- v_sql := 'CREATE SEQUENCE ' || rec_cur_sequence.sequence_name;
- insert_rec(n_line_no,
- v_object_type,
- v_username,
- rec_cur_sequence.sequence_name,
- v_sql);
- n_line_no := n_line_no + 1;
- v_sql := 'MINVALUE ' || to_char(rec_cur_sequence.min_value);
- insert_rec(n_line_no,
- v_object_type,
- v_username,
- rec_cur_sequence.sequence_name,
- v_sql);
- n_line_no := n_line_no + 1;
- v_sql := 'MAXVALUE ' || to_char(rec_cur_sequence.max_value);
- insert_rec(n_line_no,
- v_object_type,
- v_username,
- rec_cur_sequence.sequence_name,
- v_sql);
- n_line_no := n_line_no + 1;
- v_sql := 'START WITH 1';
- insert_rec(n_line_no,
- v_object_type,
- v_username,
- rec_cur_sequence.sequence_name,
- v_sql);
- n_line_no := n_line_no + 1;
- v_sql := 'INCREMENT BY ' || to_char(rec_cur_sequence.increment_by);
- insert_rec(n_line_no,
- v_object_type,
- v_username,
- rec_cur_sequence.sequence_name,
- v_sql);
- n_line_no := n_line_no + 1;
- IF rec_cur_sequence.cycle_flag = 'N' THEN
- v_sql := 'CACHE ' || to_char(rec_cur_sequence.cache_size) ||
- ' NOCYCLE ';
- ELSE
- v_sql := 'CACHE ' || to_char(rec_cur_sequence.cache_size) ||
- ' CYCLE ';
- END IF;
- insert_rec(n_line_no,
- v_object_type,
- v_username,
- rec_cur_sequence.sequence_name,
- v_sql);
- n_line_no := n_line_no + 1;
- UPDATE temp_for_pkg_gen_sql2000_temp
- SET sql_text = sql_text || ';'
- WHERE line_no = n_line_no - 1
- AND object_type = v_object_type;
- v_sql := ' ';
- insert_rec(n_line_no,
- v_object_type,
- v_username,
- rec_cur_sequence.sequence_name,
- v_sql);
- n_line_no := n_line_no + 1;
- END IF;
- END LOOP;
- CLOSE cur_sequence;
- COMMIT;
- END;
- PROCEDURE pro_synonym_sql(p_v_gen_drop_sql VARCHAR2 default 'T',
- p_v_gen_create_sql VARCHAR2 default 'T',
- p_v_display_prompt_info VARCHAR2 default 'T') AS
- v_sql VARCHAR2(2000);
- n_max_id NUMBER(38, 0);
- v_max_val VARCHAR2(1000);
- v_object_type VARCHAR2(30);
- v_prompt VARCHAR2(30);
- v_username VARCHAR2(30);
- CURSOR cur_synonym IS
- SELECT synonym_name,
- 'CREATE SYNONYM ' || synonym_name || ' for ' ||
- decode(db_link, null, table_owner || '.', '') || table_name ||
- decode(db_link, null, '', '@' || db_link) || ';' sql_text
- FROM user_synonyms;
- rec_cur_synonym cur_synonym%rowtype;
- v_synonym_name VARCHAR2(50);
- n_line_no NUMBER(38, 0);
- PROCEDURE insert_rec(p_line_no INTEGER,
- p_object_type VARCHAR2,
- p_user_name VARCHAR2,
- p_object_name VARCHAR2,
- p_string VARCHAR2) IS
- BEGIN
- INSERT INTO temp_for_pkg_gen_sql2000_temp
- (line_no, object_type, user_name, object_name, sql_text)
- VALUES
- (p_line_no, p_object_type, p_user_name, p_object_name, p_string);
- END;
- BEGIN
- n_line_no := 1;
- v_object_type := upper('SYNONYM');
- v_prompt := '-- prompt ';
- SELECT username INTO v_username FROM user_users;
- DELETE temp_for_pkg_gen_sql2000_temp WHERE OBJECT_TYPE = v_object_type;
- COMMIT;
- OPEN cur_synonym;
- LOOP
- FETCH cur_synonym
- INTO rec_cur_synonym;
- EXIT WHEN cur_synonym%NOTFOUND;
- IF p_v_gen_drop_sql = 'T' THEN
- IF p_v_display_prompt_info = 'T' THEN
- v_sql := v_prompt || ' DROP SYNONYM ' ||
- rec_cur_synonym.synonym_name;
- insert_rec(n_line_no,
- v_object_type,
- v_username,
- rec_cur_synonym.synonym_name,
- v_sql);
- n_line_no := n_line_no + 1;
- END IF;
- v_sql := 'DROP SYNONYM ' || rec_cur_synonym.synonym_name || ';';
- insert_rec(n_line_no,
- v_object_type,
- v_username,
- rec_cur_synonym.synonym_name,
- v_sql);
- n_line_no := n_line_no + 1;
- v_sql := ' ';
- insert_rec(n_line_no,
- v_object_type,
- v_username,
- rec_cur_synonym.synonym_name,
- v_sql);
- n_line_no := n_line_no + 1;
- END IF;
- IF p_v_gen_create_sql = 'T' THEN
- IF p_v_display_prompt_info = 'T' THEN
- v_sql := v_prompt || ' CREATE SYNONYM ' ||
- rec_cur_synonym.synonym_name;
- insert_rec(n_line_no,
- v_object_type,
- v_username,
- rec_cur_synonym.synonym_name,
- v_sql);
- n_line_no := n_line_no + 1;
- END IF;
- v_sql := rec_cur_synonym.sql_text;
- insert_rec(n_line_no,
- v_object_type,
- v_username,
- rec_cur_synonym.synonym_name,
- v_sql);
- n_line_no := n_line_no + 1;
- v_sql := ' ';
- insert_rec(n_line_no,
- v_object_type,
- v_username,
- rec_cur_synonym.synonym_name,
- v_sql);
- n_line_no := n_line_no + 1;
- END IF;
- END LOOP;
- CLOSE cur_synonym;
- COMMIT;
- END;
- PROCEDURE pro_job_sql(p_v_gen_drop_sql VARCHAR2 default 'T',
- p_v_gen_create_sql VARCHAR2 default 'T',
- p_v_display_prompt_info VARCHAR2 default 'T') AS
- v_sql VARCHAR2(4000);
- n_max_id NUMBER(38, 0);
- v_max_val VARCHAR2(1000);
- v_object_type VARCHAR2(30);
- v_prompt VARCHAR2(30);
- v_username VARCHAR2(30);
- v_object_name VARCHAR2(200);
- CURSOR cur_job IS
- SELECT job job_no,
- decode(instr(what, chr(10)),
- 0,
- what,
- substr(what, 1, instr(what, chr(10)) - 1)) job_name,
- 'dbms_job.submit(:jobno,''' || what || ''', sysdate, ''' ||
- interval || ''');' sql_text
- FROM user_jobs;
- rec_cur_job cur_job%rowtype;
- v_job_name VARCHAR2(50);
- n_line_no NUMBER(38, 0);
- PROCEDURE insert_rec(p_line_no INTEGER,
- p_object_type VARCHAR2,
- p_user_name VARCHAR2,
- p_object_name VARCHAR2,
- p_string VARCHAR2) IS
- BEGIN
- INSERT INTO temp_for_pkg_gen_sql4000_temp
- (line_no, object_type, user_name, object_name, sql_text)
- VALUES
- (p_line_no, p_object_type, p_user_name, p_object_name, p_string);
- END;
- BEGIN
- n_line_no := 1;
- v_object_type := upper('job');
- v_prompt := '-- prompt ';
- SELECT username INTO v_username FROM user_users;
- DELETE temp_for_pkg_gen_sql4000_temp WHERE OBJECT_TYPE = v_object_type;
- COMMIT;
- OPEN cur_job;
- LOOP
- FETCH cur_job
- INTO rec_cur_job;
- EXIT WHEN cur_job%NOTFOUND;
- IF p_v_gen_drop_sql = 'T' THEN
- IF p_v_display_prompt_info = 'T' THEN
- v_sql := v_prompt || ' DROP job ' || rec_cur_job.job_name;
- insert_rec(n_line_no,
- v_object_type,
- v_username,
- rec_cur_job.job_name,
- v_sql);
- n_line_no := n_line_no + 1;
- END IF;
- v_sql := 'exec dbms_job.remove(' || to_char(rec_cur_job.job_no) || ');';
- insert_rec(n_line_no,
- v_object_type,
- v_username,
- rec_cur_job.job_name,
- v_sql);
- n_line_no := n_line_no + 1;
- v_sql := ' ';
- insert_rec(n_line_no,
- v_object_type,
- v_username,
- rec_cur_job.job_name,
- v_sql);
- n_line_no := n_line_no + 1;
- END IF;
- IF p_v_gen_create_sql = 'T' THEN
- IF p_v_display_prompt_info = 'T' THEN
- v_sql := v_prompt || ' CREATE job ' || rec_cur_job.job_name;
- insert_rec(n_line_no,
- v_object_type,
- v_username,
- rec_cur_job.job_name,
- v_sql);
- n_line_no := n_line_no + 1;
- END IF;
- v_sql := 'variable jobno number;';
- insert_rec(n_line_no,
- v_object_type,
- v_username,
- rec_cur_job.job_name,
- v_sql);
- n_line_no := n_line_no + 1;
- v_sql := 'begin';
- insert_rec(n_line_no,
- v_object_type,
- v_username,
- rec_cur_job.job_name,
- v_sql);
- n_line_no := n_line_no + 1;
- v_sql := rec_cur_job.sql_text;
- insert_rec(n_line_no,
- v_object_type,
- v_username,
- rec_cur_job.job_name,
- v_sql);
- n_line_no := n_line_no + 1;
- v_sql := 'end;';
- insert_rec(n_line_no,
- v_object_type,
- v_username,
- rec_cur_job.job_name,
- v_sql);
- n_line_no := n_line_no + 1;
- v_sql := '/';
- insert_rec(n_line_no,
- v_object_type,
- v_username,
- rec_cur_job.job_name,
- v_sql);
- n_line_no := n_line_no + 1;
- v_sql := ' ';
- insert_rec(n_line_no,
- v_object_type,
- v_username,
- rec_cur_job.job_name,
- v_sql);
- n_line_no := n_line_no + 1;
- END IF;
- END LOOP;
- CLOSE cur_job;
- COMMIT;
- END;
- PROCEDURE pro_dl_sql(p_v_gen_drop_sql VARCHAR2 default 'T',
- p_v_gen_create_sql VARCHAR2 default 'T',
- p_v_display_prompt_info VARCHAR2 default 'T') AS
- v_sql VARCHAR2(2000);
- n_max_id NUMBER(38, 0);
- v_max_val VARCHAR2(1000);
- v_object_type VARCHAR2(30);
- v_prompt VARCHAR2(30);
- v_username VARCHAR2(30);
- CURSOR cur_dl IS
- SELECT db_link,
- 'CREATE DATABASE LINK ' || db_link || ' CONNECT TO ' ||
- username || ' IDENTIFIED BY ' || password || ' USING ''' || HOST ||
- ''';' sql_text
- FROM user_db_links;
- rec_cur_dl cur_dl%rowtype;
- v_db_link VARCHAR2(50);
- n_line_no NUMBER(38, 0);
- PROCEDURE insert_rec(p_line_no INTEGER,
- p_object_type VARCHAR2,
- p_user_name VARCHAR2,
- p_object_name VARCHAR2,
- p_string VARCHAR2) IS
- BEGIN
- INSERT INTO temp_for_pkg_gen_sql2000_temp
- (line_no, object_type, user_name, object_name, sql_text)
- VALUES
- (p_line_no, p_object_type, p_user_name, p_object_name, p_string);
- END;
- BEGIN
- n_line_no := 1;
- v_object_type := upper('DL');
- v_prompt := '-- prompt ';
- SELECT username INTO v_username FROM user_users;
- DELETE temp_for_pkg_gen_sql2000_temp WHERE OBJECT_TYPE = v_object_type;
- COMMIT;
- OPEN cur_dl;
- LOOP
- FETCH cur_dl
- INTO rec_cur_dl;
- EXIT WHEN cur_dl%NOTFOUND;
- IF p_v_gen_drop_sql = 'T' THEN
- IF p_v_display_prompt_info = 'T' THEN
- v_sql := v_prompt || ' DROP DATABASE LIKE ' || rec_cur_dl.db_link;
- insert_rec(n_line_no,
- v_object_type,
- v_username,
- rec_cur_dl.db_link,
- v_sql);
- n_line_no := n_line_no + 1;
- END IF;
- v_sql := 'DROP DATABASE LIKE ' || rec_cur_dl.db_link || ';';
- insert_rec(n_line_no,
- v_object_type,
- v_username,
- rec_cur_dl.db_link,
- v_sql);
- n_line_no := n_line_no + 1;
- v_sql := ' ';
- insert_rec(n_line_no,
- v_object_type,
- v_username,
- rec_cur_dl.db_link,
- v_sql);
- n_line_no := n_line_no + 1;
- END IF;
- IF p_v_gen_create_sql = 'T' THEN
- IF p_v_display_prompt_info = 'T' THEN
- v_sql := v_prompt || ' CREATE DATABASE LINK ' ||
- rec_cur_dl.db_link;
- insert_rec(n_line_no,
- v_object_type,
- v_username,
- rec_cur_dl.db_link,
- v_sql);
- n_line_no := n_line_no + 1;
- END IF;
- v_sql := rec_cur_dl.sql_text;
- insert_rec(n_line_no,
- v_object_type,
- v_username,
- rec_cur_dl.db_link,
- v_sql);
- n_line_no := n_line_no + 1;
- v_sql := ' ';
- insert_rec(n_line_no,
- v_object_type,
- v_username,
- rec_cur_dl.db_link,
- v_sql);
- n_line_no := n_line_no + 1;
- END IF;
- END LOOP;
- CLOSE cur_dl;
- COMMIT;
- END;
- PROCEDURE pro_role_sql(p_v_gen_drop_sql VARCHAR2 default 'T',
- p_v_gen_create_sql VARCHAR2 default 'T',
- p_v_display_prompt_info VARCHAR2 default 'T') AS
- v_sql VARCHAR2(2000);
- v_option VARCHAR2(200);
- n_max_id NUMBER(38, 0);
- v_max_val VARCHAR2(1000);
- v_object_type VARCHAR2(30);
- v_prompt VARCHAR2(30);
- v_username VARCHAR2(30);
- CURSOR cur_role IS
- select granted_role role from user_role_privs;
- rec_cur_role cur_role%rowtype;
- CURSOR cur_role_pris(c_role_name VARCHAR2) IS
- SELECT type,
- role,
- owner,
- table_name,
- column_name,
- privilege,
- grantable
- FROM (SELECT 'TAB' type,
- role,
- owner,
- table_name,
- column_name,
- privilege,
- grantable
- FROM role_tab_privs
- WHERE role NOT IN ('CONNECT', 'RESOURCE', 'DBA')
- UNION
- SELECT 'SYS' type,
- role,
- '' owner,
- '' table_name,
- '' column_name,
- privilege,
- admin_option grantable
- FROM role_sys_privs
- WHERE role NOT IN ('CONNECT', 'RESOURCE', 'DBA'))
- where role = upper(c_role_name);
- rec_cur_role_pris cur_role_pris%rowtype;
- v_role VARCHAR2(50);
- n_line_no NUMBER(38, 0);
- PROCEDURE insert_rec(p_line_no INTEGER,
- p_object_type VARCHAR2,
- p_user_name VARCHAR2,
- p_object_name VARCHAR2,
- p_string VARCHAR2) IS
- BEGIN
- INSERT INTO temp_for_pkg_gen_sql2000_temp
- (line_no, object_type, user_name, object_name, sql_text)
- VALUES
- (p_line_no, p_object_type, p_user_name, p_object_name, p_string);
- END;
- BEGIN
- n_line_no := 1;
- v_object_type := UPPER('ROLE');
- v_prompt := '-- prompt ';
- SELECT username INTO v_username FROM user_users;
- DELETE temp_for_pkg_gen_sql2000_temp WHERE OBJECT_TYPE = v_object_type;
- COMMIT;
- OPEN cur_role;
- LOOP
- FETCH cur_role
- INTO rec_cur_role;
- EXIT WHEN cur_role%NOTFOUND;
- IF p_v_gen_drop_sql = 'T' THEN
- IF p_v_display_prompt_info = 'T' THEN
- v_sql := v_prompt || ' DROP ROLE ' || rec_cur_role.role;
- insert_rec(n_line_no,
- v_object_type,
- v_username,
- rec_cur_role.role,
- v_sql);
- n_line_no := n_line_no + 1;
- END IF;
- v_sql := 'DROP ROLE ' || rec_cur_role.role || ';';
- insert_rec(n_line_no,
- v_object_type,
- v_username,
- rec_cur_role.role,
- v_sql);
- n_line_no := n_line_no + 1;
- v_sql := ' ';
- insert_rec(n_line_no,
- v_object_type,
- v_username,
- rec_cur_role.role,
- v_sql);
- n_line_no := n_line_no + 1;
- END IF;
- IF p_v_gen_create_sql = 'T' THEN
- IF p_v_display_prompt_info = 'T' THEN
- v_sql := v_prompt || ' CREATE ROLE ' || rec_cur_role.role;
- insert_rec(n_line_no,
- v_object_type,
- v_username,
- rec_cur_role.role,
- v_sql);
- n_line_no := n_line_no + 1;
- END IF;
- v_sql := 'CREATE ROLE ' || rec_cur_role.role || ';';
- insert_rec(n_line_no,
- v_object_type,
- v_username,
- rec_cur_role.role,
- v_sql);
- n_line_no := n_line_no + 1;
- v_sql := v_prompt || ' GRANT PRIS TO ROLE : ' || rec_cur_role.role;
- insert_rec(n_line_no,
- v_object_type,
- v_username,
- rec_cur_role.role,
- v_sql);
- n_line_no := n_line_no + 1;
- OPEN cur_role_pris(rec_cur_role.role);
- LOOP
- FETCH cur_role_pris
- INTO rec_cur_role_pris;
- EXIT WHEN cur_role_pris%NOTFOUND;
- IF rec_cur_role_pris.type = 'SYS' THEN
- IF rec_cur_role_pris.grantable = 'NO' THEN
- v_option := '';
- ELSE
- v_option := ' WITH ADMIN OPTION';
- END IF;
- v_sql := 'GRANT ' || rec_cur_role_pris.privilege || ' TO ' ||
- rec_cur_role_pris.role || v_option || ';';
- insert_rec(n_line_no,
- v_object_type,
- v_username,
- rec_cur_role.role,
- v_sql);
- n_line_no := n_line_no + 1;
- ELSE
- IF rec_cur_role_pris.grantable = 'NO' THEN
- v_option := '';
- ELSE
- v_option := ' WITH GRANT OPTION';
- END IF;
- IF rec_cur_role_pris.column_name IS NOT NULL THEN
- v_sql := 'GRANT ' || rec_cur_role_pris.privilege || '(' ||
- rec_cur_role_pris.column_name || ') ON ' ||
- rec_cur_role_pris.owner || '.' ||
- rec_cur_role_pris.table_name || ' TO ' ||
- rec_cur_role_pris.role || v_option || ';';
- ELSE
- v_sql := 'GRANT ' || rec_cur_role_pris.privilege || ' ON ' ||
- rec_cur_role_pris.owner || '.' ||
- rec_cur_role_pris.table_name || ' TO ' ||
- rec_cur_role_pris.role || v_option || ';';
- END IF;
- insert_rec(n_line_no,
- v_object_type,
- v_username,
- rec_cur_role.role,
- v_sql);
- n_line_no := n_line_no + 1;
- END IF;
- END LOOP;
- CLOSE cur_role_pris;
- v_sql := ' ';
- insert_rec(n_line_no,
- v_object_type,
- v_username,
- rec_cur_role.role,
- v_sql);
- n_line_no := n_line_no + 1;
- END IF;
- END LOOP;
- CLOSE cur_role;
- COMMIT;
- END;
- PROCEDURE pro_priv_sql(p_v_gen_drop_sql VARCHAR2 default 'T',
- p_v_gen_create_sql VARCHAR2 default 'T',
- p_v_display_prompt_info VARCHAR2 default 'T') AS
- v_sql VARCHAR2(2000);
- v_option VARCHAR2(200);
- n_max_id NUMBER(38, 0);
- v_max_val VARCHAR2(1000);
- v_object_type VARCHAR2(30);
- v_prompt VARCHAR2(30);
- v_username VARCHAR2(30);
- n_count number(10, 0);
- CURSOR cur_priv IS
- SELECT privilege,
- owner,
- table_name,
- grantee,
- 'GRANT ' || privilege || ' ON ' || owner || '.' || table_name ||
- ' TO ' || grantee ||
- decode(grantable, 'NO', '', ' WITH GRANT OPTION') || ';' SQL_TEXT
- FROM user_tab_privs
- WHERE GRANTOR = (SELECT username FROM user_users)
- ORDER BY owner, table_name;
- rec_cur_priv cur_priv%rowtype;
- CURSOR cur_col_priv IS
- SELECT privilege,
- owner,
- column_name,
- table_name,
- grantee,
- 'GRANT ' || privilege || ' ' || column_name || ' ON ' || owner || '.' ||
- table_name || ' TO ' || grantee ||
- decode(grantable, 'NO', '', ' WITH GRANT OPTION') || ';' SQL_TEXT
- FROM user_col_privs
- WHERE GRANTOR = (SELECT username FROM user_users)
- ORDER BY owner, table_name;
- rec_cur_col_priv cur_col_priv%rowtype;
- CURSOR cur_sys_priv IS
- SELECT username,
- privilege,
- 'GRANT ' || privilege || ' TO ' || username ||
- decode(admin_option, 'NO', '', ' WITH ADMIN OPTION') || ';' SQL_TEXT
- FROM user_sys_privs
- ORDER BY username;
- rec_cur_sys_priv cur_sys_priv%rowtype;
- v_priv VARCHAR2(50);
- n_line_no NUMBER(38, 0);
- PROCEDURE insert_rec(p_line_no INTEGER,
- p_object_type VARCHAR2,
- p_user_name VARCHAR2,
- p_object_name VARCHAR2,
- p_string VARCHAR2) IS
- BEGIN
- INSERT INTO temp_for_pkg_gen_sql2000_temp
- (line_no, object_type, user_name, object_name, sql_text)
- VALUES
- (p_line_no, p_object_type, p_user_name, p_object_name, p_string);
- END;
- BEGIN
- n_line_no := 1;
- v_object_type := UPPER('PRIV');
- v_prompt := '-- prompt ';
- n_count := 1;
- SELECT USERNAME INTO v_username FROM USER_USERS;
- DELETE temp_for_pkg_gen_sql2000_temp WHERE OBJECT_TYPE = v_object_type;
- COMMIT;
- OPEN cur_priv;
- LOOP
- FETCH cur_priv
- INTO rec_cur_priv;
- EXIT WHEN cur_priv%NOTFOUND;
- IF p_v_gen_create_sql = 'T' THEN
- IF p_v_display_prompt_info = 'T' THEN
- v_sql := v_prompt || ' GRANT PRIVILEGE : ' ||
- rec_cur_priv.privilege || ' ON ' || rec_cur_priv.owner || '.' ||
- rec_cur_priv.table_name || ' TO ' ||
- rec_cur_priv.grantee;
- insert_rec(n_line_no,
- v_object_type,
- v_username,
- 'tab priv',
- v_sql);
- n_line_no := n_line_no + 1;
- END IF;
- v_sql := rec_cur_priv.sql_text;
- insert_rec(n_line_no, v_object_type, v_username, 'tab priv', v_sql);
- n_line_no := n_line_no + 1;
- v_sql := ' ';
- insert_rec(n_line_no, v_object_type, v_username, 'tab priv', v_sql);
- n_line_no := n_line_no + 1;
- END IF;
- END LOOP;
- CLOSE cur_priv;
- OPEN cur_col_priv;
- LOOP
- FETCH cur_col_priv
- INTO rec_cur_col_priv;
- EXIT WHEN cur_col_priv%NOTFOUND;
- IF n_count = 1 THEN
- v_sql := '-- *********************** ';
- insert_rec(n_line_no, v_object_type, v_username, 'tab priv', v_sql);
- n_line_no := n_line_no + 1;
- n_count := n_count + 1;
- END IF;
- v_sql := ' ';
- insert_rec(n_line_no, v_object_type, v_username, 'tab priv', v_sql);
- n_line_no := n_line_no + 1;
- IF p_v_display_prompt_info = 'T' THEN
- v_sql := v_prompt || ' GRANT COL PRIVILEGE : ' ||
- rec_cur_col_priv.privilege || ' ON ' ||
- rec_cur_col_priv.owner || '.' ||
- rec_cur_col_priv.table_name || ' TO ' ||
- rec_cur_col_priv.grantee;
- insert_rec(n_line_no, v_object_type, v_username, 'col priv', v_sql);
- n_line_no := n_line_no + 1;
- END IF;
- v_sql := rec_cur_col_priv.sql_text;
- insert_rec(n_line_no, v_object_type, v_username, 'col priv', v_sql);
- n_line_no := n_line_no + 1;
- v_sql := ' ';
- insert_rec(n_line_no, v_object_type, v_username, 'col priv', v_sql);
- n_line_no := n_line_no + 1;
- END LOOP;
- CLOSE cur_col_priv;
- n_count := 1;
- OPEN cur_sys_priv;
- LOOP
- FETCH cur_sys_priv
- INTO rec_cur_sys_priv;
- EXIT WHEN cur_sys_priv%NOTFOUND;
- IF n_count = 1 THEN
- v_sql := ' ';
- insert_rec(n_line_no, v_object_type, v_username, 'sys priv', v_sql);
- n_line_no := n_line_no + 1;
- v_sql := 'PROMPT *********** You must the following sql as a user with DBA priv, others you will get errors!
- ************ ';
- insert_rec(n_line_no, v_object_type, v_username, 'sys priv', v_sql);
- n_line_no := n_line_no + 1;
- v_sql := 'PROMPT *********** We comment the follow sql! ************ ';
- insert_rec(n_line_no, v_object_type, v_username, 'sys priv', v_sql);
- n_line_no := n_line_no + 1;
- v_sql := ' ';
- insert_rec(n_line_no, v_object_type, v_username, 'sys priv', v_sql);
- n_line_no := n_line_no + 1;
- n_count := n_count + 1;
- END IF;
- IF p_v_display_prompt_info = 'T' THEN
- v_sql := v_prompt || ' GRANT SYSTEM PRIVILEGE : ' ||
- rec_cur_sys_priv.privilege || ' TO ' ||
- rec_cur_sys_priv.username;
- insert_rec(n_line_no, v_object_type, v_username, 'sys priv', v_sql);
- n_line_no := n_line_no + 1;
- END IF;
- v_sql := '-- ' || rec_cur_sys_priv.sql_text;
- insert_rec(n_line_no, v_object_type, v_username, 'sys priv', v_sql);
- n_line_no := n_line_no + 1;
- v_sql := ' ';
- insert_rec(n_line_no, v_object_type, v_username, 'sys priv', v_sql);
- n_line_no := n_line_no + 1;
- END LOOP;
- CLOSE cur_sys_priv;
- COMMIT;
- END;
- PROCEDURE pro_pkgprofuntri_sql(p_v_gen_drop_sql VARCHAR2 default 'T',
- p_v_gen_create_sql VARCHAR2 default 'T',
- p_v_display_prompt_info VARCHAR2 default 'T',
- p_v_separ_file VARCHAR2 default 'T',
- p_v_file_path VARCHAR2 default 'C:/') AS
- v_sql VARCHAR2(2000);
- v_object_type VARCHAR2(30);
- v_prompt VARCHAR2(30);
- v_file_path VARCHAR2(600);
- v_notion char(1);
- v_username VARCHAR2(30);
- CURSOR cur_ProFunPkg_name IS
- SELECT distinct type, us.name
- FROM user_source us
- WHERE type <> 'PACKAGE BODY'
- AND us.name <> upper('pkg_gen_user_sql')
- ORDER BY us.type, us.name;
- CURSOR cur_ProFunPkg_code(c_obj_name VARCHAR2, c_obj_type VARCHAR2) IS
- SELECT line, type, text
- FROM user_source us
- WHERE NAME = c_obj_name
- AND type = c_obj_type
- ORDER BY type, line;
- v_object_name VARCHAR2(50);
- n_line_no NUMBER(38, 0);
- PROCEDURE insert_rec(p_line_no INTEGER,
- p_object_type VARCHAR2,
- p_user_name VARCHAR2,
- p_object_name VARCHAR2,
- p_string VARCHAR2) IS
- BEGIN
- INSERT INTO temp_for_pkg_gen_sql4000_temp
- (line_no, object_type, user_name, object_name, sql_text)
- VALUES
- (p_line_no, p_object_type, p_user_name, p_object_name, p_string);
- END;
- BEGIN
- n_line_no := 1;
- v_file_path := p_v_file_path;
- v_prompt := '-- prompt ';
- SELECT username INTO v_username FROM user_users;
- -- find the notion between the dictionary
- IF instr(p_v_file_path, '/') > 0 THEN
- v_notion := '/';
- ELSE
- v_notion := '/';
- END IF;
- IF substr(v_file_path, length(v_file_path)) <> v_notion THEN
- v_file_path := v_file_path || v_notion;
- END IF;
- DELETE temp_for_pkg_gen_sql4000_temp
- WHERE OBJECT_TYPE IN
- ('PACKAGE BODY', 'PACKAGE', 'PROCEDURE', 'FUNCTION',
- 'SEPAR_PROCS', 'SEPAR_FUNCS', 'SEPAR_PKG_HEADS',
- 'SEPAR_PKG_BODYS', 'SEPAR_PKGS', 'TRIGGER', 'SEPAR_TRIS');
- COMMIT;
- FOR rec_ProFunPkg_name IN cur_ProFunPkg_name LOOP
- v_object_type := rec_ProFunPkg_name.type;
- v_sql := '-- ~~~~~~~~~~~~~~~~~~~~ ' || rec_ProFunPkg_name.type ||
- ' : ' || rec_ProFunPkg_name.name ||
- ' START; ~~~~~~~~~~~~~~~~~~~~';
- insert_rec(n_line_no,
- v_object_type,
- v_username,
- rec_ProFunPkg_name.name,
- v_sql);
- n_line_no := n_line_no + 1;
- v_sql := ' ';
- insert_rec(n_line_no,
- v_object_type,
- v_username,
- rec_ProFunPkg_name.name,
- v_sql);
- n_line_no := n_line_no + 1;
- IF p_v_gen_drop_sql = 'T' AND v_object_type <> 'PACKAGE BODY' THEN
- IF p_v_display_prompt_info = 'T' THEN
- v_sql := v_prompt || ' DROP ' || rec_ProFunPkg_name.type || ' ' ||
- rec_ProFunPkg_name.name;
- insert_rec(n_line_no,
- v_object_type,
- v_username,
- rec_ProFunPkg_name.name,
- v_sql);
- n_line_no := n_line_no + 1;
- END IF;
- v_sql := 'DROP ' || rec_ProFunPkg_name.type || ' ' ||
- rec_ProFunPkg_name.type || ' ' || rec_ProFunPkg_name.name || ';';
- insert_rec(n_line_no,
- v_object_type,
- v_username,
- rec_ProFunPkg_name.name,
- v_sql);
- n_line_no := n_line_no + 1;
- v_sql := ' ';
- insert_rec(n_line_no,
- v_object_type,
- v_username,
- rec_ProFunPkg_name.name,
- v_sql);
- n_line_no := n_line_no + 1;
- END IF;
- IF p_v_gen_create_sql = 'T' THEN
- IF p_v_display_prompt_info = 'T' THEN
- v_sql := v_prompt || ' CREATE ' || rec_ProFunPkg_name.type || ' ' ||
- rec_ProFunPkg_name.name;
- insert_rec(n_line_no,
- v_object_type,
- v_username,
- rec_ProFunPkg_name.name,
- v_sql);
- n_line_no := n_line_no + 1;
- END IF;
- FOR rec_ProFunPkg_code IN cur_ProFunPkg_code(rec_ProFunPkg_name.name,
- rec_ProFunPkg_name.type) LOOP
- IF rec_ProFunPkg_code.line = 1 THEN
- v_sql := 'CREATE OR REPLACE ' || rec_ProFunPkg_code.text;
- ELSE
- v_sql := rec_ProFunPkg_code.text;
- END IF;
- insert_rec(n_line_no,
- v_object_type,
- v_username,
- rec_ProFunPkg_name.name,
- v_sql);
- n_line_no := n_line_no + 1;
- END LOOP;
- v_sql := '/';
- insert_rec(n_line_no,
- v_object_type,
- v_username,
- rec_ProFunPkg_name.name,
- v_sql);
- n_line_no := n_line_no + 1;
- v_sql := '@' || lower(rec_ProFunPkg_name.name) || '.sql';
- IF v_object_type = 'PROCEDURE' THEN
- insert_rec(n_line_no,
- v_object_type,
- v_username,
- 'START_PROCS',
- v_sql);
- ELSIF v_object_type = 'FUNCTION' THEN
- insert_rec(n_line_no,
- v_object_type,
- v_username,
- 'START_FUNCS',
- v_sql);
- ELSIF v_object_type = 'PACKAGE' or v_object_type = 'PACKAGE BODY' THEN
- insert_rec(n_line_no,
- v_object_type,
- v_username,
- 'START_PKGS',
- v_sql);
- n_line_no := n_line_no + 1;
- v_sql := '@' || lower(rec_ProFunPkg_name.name) || '.haad.sql';
- insert_rec(n_line_no,
- v_object_type,
- v_username,
- 'START_PKG_HS',
- v_sql);
- n_line_no := n_line_no + 1;
- v_sql := '@' || lower(rec_ProFunPkg_name.name) || '.body.sql';
- insert_rec(n_line_no,
- v_object_type,
- v_username,
- 'START_PKG_BS',
- v_sql);
- ELSIF v_object_type = 'TRIGGER' THEN
- insert_rec(n_line_no,
- v_object_type,
- v_username,
- 'START_TRIS',
- v_sql);
- ELSIF v_object_type = 'TYPE' or v_object_type = 'TYPE BODY' THEN
- insert_rec(n_line_no,
- v_object_type,
- v_username,
- 'START_TYPES',
- v_sql);
- n_line_no := n_line_no + 1;
- v_sql := '@' || lower(rec_ProFunPkg_name.name) || '.haad.sql';
- insert_rec(n_line_no,
- v_object_type,
- v_username,
- 'START_TYPE_HS',
- v_sql);
- n_line_no := n_line_no + 1;
- v_sql := '@' || lower(rec_ProFunPkg_name.name) || '.body.sql';
- insert_rec(n_line_no,
- v_object_type,
- v_username,
- 'START_TYPE_BS',
- v_sql);
- END IF;
- n_line_no := n_line_no + 1;
- v_sql := ' ';
- insert_rec(n_line_no,
- 'START_PROCS',
- v_username,
- rec_ProFunPkg_name.name,
- v_sql);
- n_line_no := n_line_no + 1;
- v_sql := ' ';
- insert_rec(n_line_no,
- v_object_type,
- v_username,
- rec_ProFunPkg_name.name,
- v_sql);
- n_line_no := n_line_no + 1;
- IF rec_ProFunPkg_name.type = 'PACKAGE' THEN
- FOR rec_ProFunPkg_code IN cur_ProFunPkg_code(rec_ProFunPkg_name.name,
- rec_ProFunPkg_name.type ||
- ' BODY') LOOP
- IF rec_ProFunPkg_code.line = 1 THEN
- v_sql := 'CREATE OR REPLACE ' || rec_ProFunPkg_code.text;
- ELSE
- v_sql := rec_ProFunPkg_code.text;
- END IF;
- insert_rec(n_line_no,
- rec_ProFunPkg_name.type || ' BODY',
- v_username,
- rec_ProFunPkg_name.name,
- v_sql);
- n_line_no := n_line_no + 1;
- END LOOP;
- v_sql := '/';
- insert_rec(n_line_no,
- rec_ProFunPkg_name.type || ' BODY',
- v_username,
- rec_ProFunPkg_name.name,
- v_sql);
- n_line_no := n_line_no + 1;
- v_sql := ' ';
- insert_rec(n_line_no,
- rec_ProFunPkg_name.type || ' BODY',
- v_username,
- rec_ProFunPkg_name.name,
- v_sql);
- n_line_no := n_line_no + 1;
- END IF;
- v_sql := '-- ~~~~~~~~~~~~~~~~~~~~ ' || rec_ProFunPkg_name.type ||
- ' : ' || rec_ProFunPkg_name.name ||
- ' END; ~~~~~~~~~~~~~~~~~~~~';
- insert_rec(n_line_no,
- v_object_type,
- v_username,
- rec_ProFunPkg_name.name,
- v_sql);
- n_line_no := n_line_no + 1;
- v_sql := ' ';
- insert_rec(n_line_no,
- v_object_type,
- v_username,
- rec_ProFunPkg_name.name,
- v_sql);
- n_line_no := n_line_no + 1;
- END IF;
- IF v_object_type = 'PROCEDURE' THEN
- v_sql := 'spool ' || v_file_path || 'procedures' || v_notion ||
- 'separ_files' || v_notion ||
- lower(rec_ProFunPkg_name.name) || '.sql';
- insert_rec(n_line_no,
- 'SEPAR_PROCS',
- v_username,
- rec_ProFunPkg_name.name,
- v_sql);
- n_line_no := n_line_no + 1;
- v_sql := 'SELECT rtrim(sql_text) FROM temp_for_pkg_gen_sql4000_temp ';
- insert_rec(n_line_no,
- 'SEPAR_PROCS',
- v_username,
- rec_ProFunPkg_name.name,
- v_sql);
- n_line_no := n_line_no + 1;
- v_sql := 'WHERE OBJECT_TYPE = ''PROCEDURE'' AND OBJECT_NAME = ''' ||
- rec_ProFunPkg_name.name || ''' ORDER BY line_no ; ';
- insert_rec(n_line_no,
- 'SEPAR_PROCS',
- v_username,
- rec_ProFunPkg_name.name,
- v_sql);
- n_line_no := n_line_no + 1;
- v_sql := 'spool off';
- insert_rec(n_line_no,
- 'SEPAR_PROCS',
- v_username,
- rec_ProFunPkg_name.name,
- v_sql);
- n_line_no := n_line_no + 1;
- v_sql := ' ';
- insert_rec(n_line_no,
- 'SEPAR_PROCS',
- v_username,
- rec_ProFunPkg_name.name,
- v_sql);
- n_line_no := n_line_no + 1;
- ELSIF v_object_type = 'FUNCTION' THEN
- v_sql := 'spool ' || v_file_path || 'functions' || v_notion ||
- 'separ_files' || v_notion ||
- lower(rec_ProFunPkg_name.name) || '.sql';
- insert_rec(n_line_no,
- 'SEPAR_FUNCS',
- v_username,
- rec_ProFunPkg_name.name,
- v_sql);
- n_line_no := n_line_no + 1;
- v_sql := 'SELECT rtrim(sql_text) FROM temp_for_pkg_gen_sql4000_temp ';
- insert_rec(n_line_no,
- 'SEPAR_FUNCS',
- v_username,
- rec_ProFunPkg_name.name,
- v_sql);
- n_line_no := n_line_no + 1;
- v_sql := 'WHERE OBJECT_TYPE = ''FUNCTION'' AND OBJECT_NAME = ''' ||
- rec_ProFunPkg_name.name || ''' ORDER BY line_no ; ';
- insert_rec(n_line_no,
- 'SEPAR_FUNCS',
- v_username,
- rec_ProFunPkg_name.name,
- v_sql);
- n_line_no := n_line_no + 1;
- v_sql := 'spool off';
- insert_rec(n_line_no,
- 'SEPAR_FUNCS',
- v_username,
- rec_ProFunPkg_name.name,
- v_sql);
- n_line_no := n_line_no + 1;
- v_sql := ' ';
- insert_rec(n_line_no,
- 'SEPAR_FUNCS',
- v_username,
- rec_ProFunPkg_name.name,
- v_sql);
- n_line_no := n_line_no + 1;
- ELSIF v_object_type = 'TRIGGER' THEN
- v_sql := 'spool ' || v_file_path || 'triggers' || v_notion ||
- 'separ_files' || v_notion ||
- lower(rec_ProFunPkg_name.name) || '.sql';
- insert_rec(n_line_no,
- 'SEPAR_TRIS',
- v_username,
- rec_ProFunPkg_name.name,
- v_sql);
- n_line_no := n_line_no + 1;
- v_sql := 'SELECT rtrim(sql_text) FROM temp_for_pkg_gen_sql4000_temp ';
- insert_rec(n_line_no,
- 'SEPAR_TRIS',
- v_username,
- rec_ProFunPkg_name.name,
- v_sql);
- n_line_no := n_line_no + 1;
- v_sql := 'WHERE OBJECT_TYPE = ''TRIGGER'' AND OBJECT_NAME = ''' ||
- rec_ProFunPkg_name.name || ''' ORDER BY line_no ; ';
- insert_rec(n_line_no,
- 'SEPAR_TRIS',
- v_username,
- rec_ProFunPkg_name.name,
- v_sql);
- n_line_no := n_line_no + 1;
- v_sql := 'spool off';
- insert_rec(n_line_no,
- 'SEPAR_TRIS',
- v_username,
- rec_ProFunPkg_name.name,
- v_sql);
- n_line_no := n_line_no + 1;
- v_sql := ' ';
- insert_rec(n_line_no,
- 'SEPAR_TRIS',
- v_username,
- rec_ProFunPkg_name.name,
- v_sql);
- n_line_no := n_line_no + 1;
- ELSIF v_object_type = 'PACKAGE' THEN
- --生成可以将包头放在一个文件中的批处理文件
- v_sql := 'spool ' || v_file_path || 'packages' || v_notion ||
- 'separ_headbobdy_file' || v_notion ||
- lower(rec_ProFunPkg_name.name) || '.head.sql;';
- insert_rec(n_line_no,
- 'SEPAR_PKG_HEADS',
- v_username,
- rec_ProFunPkg_name.name,
- v_sql);
- n_line_no := n_line_no + 1;
- v_sql := 'SELECT rtrim(sql_text) FROM temp_for_pkg_gen_sql4000_temp ';
- insert_rec(n_line_no,
- 'SEPAR_PKG_HEADS',
- v_username,
- rec_ProFunPkg_name.name,
- v_sql);
- n_line_no := n_line_no + 1;
- v_sql := 'WHERE OBJECT_TYPE = ''PACKAGE'' AND OBJECT_NAME = ''' ||
- rec_ProFunPkg_name.name || ''' ORDER BY line_no ; ';
- insert_rec(n_line_no,
- 'SEPAR_PKG_HEADS',
- v_username,
- rec_ProFunPkg_name.name,
- v_sql);
- n_line_no := n_line_no + 1;
- v_sql := 'spool off';
- insert_rec(n_line_no,
- 'SEPAR_PKG_HEADS',
- v_username,
- rec_ProFunPkg_name.name,
- v_sql);
- n_line_no := n_line_no + 1;
- v_sql := ' ';
- insert_rec(n_line_no,
- 'SEPAR_PKG_HEADS',
- v_username,
- rec_ProFunPkg_name.name,
- v_sql);
- n_line_no := n_line_no + 1;
- --生成可以将包体放在一个文件中的批处理文件
- v_sql := 'spool ' || v_file_path || 'packages' || v_notion ||
- 'separ_headbobdy_file' || v_notion ||
- lower(rec_ProFunPkg_name.name) || '.body.sql;';
- insert_rec(n_line_no,
- 'SEPAR_PKG_BODYS',
- v_username,
- rec_ProFunPkg_name.name,
- v_sql);
- n_line_no := n_line_no + 1;
- v_sql := 'SELECT rtrim(sql_text) FROM temp_for_pkg_gen_sql4000_temp ';
- insert_rec(n_line_no,
- 'SEPAR_PKG_BODYS',
- v_username,
- rec_ProFunPkg_name.name,
- v_sql);
- n_line_no := n_line_no + 1;
- v_sql := 'WHERE OBJECT_TYPE = ''PACKAGE BODY'' AND OBJECT_NAME = ''' ||
- rec_ProFunPkg_name.name || ''' ORDER BY line_no ; ';
- insert_rec(n_line_no,
- 'SEPAR_PKG_BODYS',
- v_username,
- rec_ProFunPkg_name.name,
- v_sql);
- n_line_no := n_line_no + 1;
- v_sql := 'spool off;';
- insert_rec(n_line_no,
- 'SEPAR_PKG_BODYS',
- v_username,
- rec_ProFunPkg_name.name,
- v_sql);
- n_line_no := n_line_no + 1;
- v_sql := ' ';
- insert_rec(n_line_no,
- 'SEPAR_PKG_BODYS',
- v_username,
- rec_ProFunPkg_name.name,
- v_sql);
- n_line_no := n_line_no + 1;
- v_sql := ' ';
- insert_rec(n_line_no,
- 'SEPAR_PKG_HEADS',
- v_username,
- rec_ProFunPkg_name.name,
- v_sql);
- n_line_no := n_line_no + 1;
- -- the package head and package body allow in the same file
- v_sql := 'spool ' || v_file_path || 'packages' || v_notion ||
- 'separ_files' || v_notion ||
- lower(rec_ProFunPkg_name.name) || '.sql;';
- insert_rec(n_line_no,
- 'SEPAR_PKGS',
- v_username,
- rec_ProFunPkg_name.name,
- v_sql);
- n_line_no := n_line_no + 1;
- v_sql := 'SELECT rtrim(sql_text) FROM temp_for_pkg_gen_sql4000_temp ';
- insert_rec(n_line_no,
- 'SEPAR_PKGS',
- v_username,
- rec_ProFunPkg_name.name,
- v_sql);
- n_line_no := n_line_no + 1;
- v_sql := 'WHERE OBJECT_TYPE like ''%PACKAGE%'' AND OBJECT_NAME = ''' ||
- rec_ProFunPkg_name.name || ''' ORDER BY line_no ; ';
- insert_rec(n_line_no,
- 'SEPAR_PKGS',
- v_username,
- rec_ProFunPkg_name.name,
- v_sql);
- n_line_no := n_line_no + 1;
- v_sql := 'spool off;';
- insert_rec(n_line_no,
- 'SEPAR_PKGS',
- v_username,
- rec_ProFunPkg_name.name,
- v_sql);
- n_line_no := n_line_no + 1;
- v_sql := ' ';
- insert_rec(n_line_no,
- 'SEPAR_PKGS',
- v_username,
- rec_ProFunPkg_name.name,
- v_sql);
- n_line_no := n_line_no + 1;
- END IF;
- END LOOP;
- -- 生成批量运行生成各个文件的批文件
- v_sql := 'spool ' || v_file_path || 'procedures' || v_notion ||
- 'separ_files' || v_notion || 'start_procs.sql';
- insert_rec(n_line_no, 'SEPAR_PROCS', v_username, 'SEPAR_PROCS', v_sql);
- n_line_no := n_line_no + 1;
- v_sql := 'SELECT rtrim(sql_text) FROM temp_for_pkg_gen_sql4000_temp ';
- insert_rec(n_line_no, 'SEPAR_PROCS', v_username, 'SEPAR_PROCS', v_sql);
- n_line_no := n_line_no + 1;
- v_sql := 'WHERE OBJECT_TYPE = ''PROCEDURE'' AND OBJECT_NAME = ''START_PROCS'' ORDER BY line_no ; ';
- insert_rec(n_line_no, 'SEPAR_PROCS', v_username, 'SEPAR_PROCS', v_sql);
- n_line_no := n_line_no + 1;
- v_sql := 'spool off';
- insert_rec(n_line_no, 'SEPAR_PROCS', v_username, 'SEPAR_PROCS', v_sql);
- n_line_no := n_line_no + 1;
- v_sql := ' ';
- insert_rec(n_line_no, 'SEPAR_PROCS', v_username, 'SEPAR_PROCS', v_sql);
- n_line_no := n_line_no + 1;
- v_sql := 'spool ' || v_file_path || 'functions' || v_notion ||
- 'separ_files' || v_notion || 'start_funcs.sql';
- insert_rec(n_line_no, 'SEPAR_FUNCS', v_username, 'SEPAR_FUNCS', v_sql);
- n_line_no := n_line_no + 1;
- v_sql := 'SELECT rtrim(sql_text) FROM temp_for_pkg_gen_sql4000_temp ';
- insert_rec(n_line_no, 'SEPAR_FUNCS', v_username, 'SEPAR_FUNCS', v_sql);
- n_line_no := n_line_no + 1;
- v_sql := 'WHERE OBJECT_TYPE = ''FUNCTION'' AND OBJECT_NAME = ''START_FUNCS'' ORDER BY line_no ; ';
- insert_rec(n_line_no, 'SEPAR_FUNCS', v_username, 'SEPAR_FUNCS', v_sql);
- n_line_no := n_line_no + 1;
- v_sql := 'spool off';
- insert_rec(n_line_no, 'SEPAR_FUNCS', v_username, 'SEPAR_FUNCS', v_sql);
- n_line_no := n_line_no + 1;
- v_sql := ' ';
- insert_rec(n_line_no, 'SEPAR_FUNCS', v_username, 'SEPAR_FUNCS', v_sql);
- n_line_no := n_line_no + 1;
- v_sql := 'spool ' || v_file_path || 'triggers' || v_notion ||
- 'separ_files' || v_notion || 'start_tris.sql';
- insert_rec(n_line_no, 'SEPAR_TRIS', v_username, 'SEPAR_TRIS', v_sql);
- n_line_no := n_line_no + 1;
- v_sql := 'SELECT rtrim(sql_text) FROM temp_for_pkg_gen_sql4000_temp ';
- insert_rec(n_line_no, 'SEPAR_TRIS', v_username, 'SEPAR_TRIS', v_sql);
- n_line_no := n_line_no + 1;
- v_sql := 'WHERE OBJECT_TYPE = ''TRIGGER'' AND OBJECT_NAME = ''SEPAR_TRIS'' ORDER BY line_no ; ';
- insert_rec(n_line_no, 'SEPAR_TRIS', v_username, 'SEPAR_TRIS', v_sql);
- n_line_no := n_line_no + 1;
- v_sql := 'spool off';
- insert_rec(n_line_no, 'SEPAR_TRIS', v_username, 'SEPAR_TRIS', v_sql);
- n_line_no := n_line_no + 1;
- v_sql := ' ';
- insert_rec(n_line_no, 'SEPAR_TRIS', v_username, 'SEPAR_TRIS', v_sql);
- n_line_no := n_line_no + 1;
- v_sql := 'spool ' || v_file_path || 'packages' || v_notion ||
- 'separ_headbobdy_file' || v_notion || 'start_pkg_heads.sql;';
- insert_rec(n_line_no,
- 'SEPAR_PKG_HEADS',
- v_username,
- 'SEPAR_PKG_HEADS',
- v_sql);
- n_line_no := n_line_no + 1;
- v_sql := 'SELECT rtrim(sql_text) FROM temp_for_pkg_gen_sql4000_temp ';
- insert_rec(n_line_no,
- 'SEPAR_PKG_HEADS',
- v_username,
- 'SEPAR_PKG_HEADS',
- v_sql);
- n_line_no := n_line_no + 1;
- v_sql := 'WHERE OBJECT_TYPE = ''PACKAGE'' AND OBJECT_NAME = ''START_PKG_HS'' ORDER BY line_no ; ';
- insert_rec(n_line_no,
- 'SEPAR_PKG_HEADS',
- v_username,
- 'SEPAR_PKG_HEADS',
- v_sql);
- n_line_no := n_line_no + 1;
- v_sql := 'spool off';
- insert_rec(n_line_no,
- 'SEPAR_PKG_HEADS',
- v_username,
- 'SEPAR_PKG_HEADS',
- v_sql);
- n_line_no := n_line_no + 1;
- v_sql := ' ';
- insert_rec(n_line_no,
- 'SEPAR_PKG_HEADS',
- v_username,
- 'SEPAR_PKG_HEADS',
- v_sql);
- n_line_no := n_line_no + 1;
- v_sql := 'spool ' || v_file_path || 'packages' || v_notion ||
- 'separ_headbobdy_file' || v_notion || 'start_pkg_bodys.sql;';
- insert_rec(n_line_no,
- 'SEPAR_PKG_BODYS',
- v_username,
- 'SEPAR_PKG_BODYS',
- v_sql);
- n_line_no := n_line_no + 1;
- v_sql := 'SELECT rtrim(sql_text) FROM temp_for_pkg_gen_sql4000_temp ';
- insert_rec(n_line_no,
- 'SEPAR_PKG_BODYS',
- v_username,
- 'SEPAR_PKG_BODYS',
- v_sql);
- n_line_no := n_line_no + 1;
- v_sql := 'WHERE OBJECT_TYPE = ''PACKAGE'' AND OBJECT_NAME = ''START_PKG_BS'' ORDER BY line_no ; ';
- insert_rec(n_line_no,
- 'SEPAR_PKG_BODYS',
- v_username,
- 'SEPAR_PKG_BODYS',
- v_sql);
- n_line_no := n_line_no + 1;
- v_sql := 'spool off';
- insert_rec(n_line_no,
- 'SEPAR_PKG_BODYS',
- v_username,
- 'SEPAR_PKG_BODYS',
- v_sql);
- n_line_no := n_line_no + 1;
- v_sql := ' ';
- insert_rec(n_line_no, 'SEPAR_PKGS', v_username, 'SEPAR_PKGS', v_sql);
- n_line_no := n_line_no + 1;
- v_sql := 'spool ' || v_file_path || 'packages' || v_notion ||
- 'separ_files' || v_notion || 'start_pkgs.sql;';
- insert_rec(n_line_no, 'SEPAR_PKGS', v_username, 'SEPAR_PKGS', v_sql);
- n_line_no := n_line_no + 1;
- v_sql := 'SELECT rtrim(sql_text) FROM temp_for_pkg_gen_sql4000_temp ';
- insert_rec(n_line_no, 'SEPAR_PKGS', v_username, 'SEPAR_PKGS', v_sql);
- n_line_no := n_line_no + 1;
- v_sql := 'WHERE OBJECT_TYPE = ''PACKAGE'' AND OBJECT_NAME = ''START_PKGS'' ORDER BY line_no ; ';
- insert_rec(n_line_no, 'SEPAR_PKGS', v_username, 'SEPAR_PKGS', v_sql);
- n_line_no := n_line_no + 1;
- v_sql := 'spool off';
- insert_rec(n_line_no, 'SEPAR_PKGS', v_username, 'SEPAR_PKGS', v_sql);
- n_line_no := n_line_no + 1;
- v_sql := ' ';
- insert_rec(n_line_no, 'SEPAR_PKGS', v_username, 'SEPAR_PKGS', v_sql);
- n_line_no := n_line_no + 1;
- COMMIT;
- END;
- END pkg_gen_user_sql;
- /
- show err
- set echo off
- set feedback off
- set newpage none
- set pagesize 0
- set verify off
- set pagesize 0
- set term off
- set trims on
- set linesize 5005
- set heading off
- set timing off
- set verify off
- set numwidth 38
- -- 生成start
- exec pkg_gen_user_sql.pro_gen_start_sql('&&file_dic')
- spool &&file_dic/start_all.sql
- SELECT rtrim(sql_text)
- FROM temp_for_pkg_gen_sql2000_temp
- WHERE OBJECT_TYPE = 'START_SQL'
- ORDER BY line_no ;
- spool off
- -- 生成创建表的sql语句
- exec pkg_gen_user_sql.pro_tab_sql_tab8('F','T','F','T');
- spool &&file_dic/cre_tables.sql
- SELECT rtrim(sql_text)
- FROM temp_for_pkg_gen_sql2000_temp
- WHERE OBJECT_TYPE = 'TABLE_8'
- ORDER BY line_no ;
- spool off
- -- 生成创建索引的sql语句
- exec pkg_gen_user_sql.pro_indx_sql('F','T','F','T')
- spool &&file_dic/cre_indexes.sql
- SELECT sql_text
- FROM temp_for_pkg_gen_sql2000_temp
- WHERE OBJECT_TYPE = 'INDEX'
- ORDER BY line_no;
- spool off
- -- 生成创建主键约束的sql语句
- exec pkg_gen_user_sql.pro_con_sql('P','F','T','T','T');
- spool &&file_dic/cre_pri_constraint.sql
- SELECT rtrim(sql_text)
- FROM temp_for_pkg_gen_sql2000_temp
- WHERE OBJECT_TYPE = 'CONSTRAINT'
- ORDER BY line_no;
- spool off
- -- 生成创建出主键约束的其它约束的sql语句
- exec pkg_gen_user_sql.pro_con_sql('NOT_PRI','F','T','F','T');
- spool &&file_dic/cre_not_pri_constraint.sql
- SELECT rtrim(sql_text)
- FROM temp_for_pkg_gen_sql2000_temp
- WHERE OBJECT_TYPE = 'CONSTRAINT'
- ORDER BY line_no;
- spool off
- -- 生成创建所有约束的sql语句
- exec pkg_gen_user_sql.pro_con_sql('A','F','T','T','T');
- spool &&file_dic/cre_constraints.sql
- SELECT rtrim(sql_text)
- FROM temp_for_pkg_gen_sql2000_temp
- WHERE OBJECT_TYPE = 'CONSTRAINT'
- ORDER BY line_no;
- spool off
- -- 生成重建索引的sql语句
- exec pkg_gen_user_sql.pro_reb_indx_sql('F','F')
- spool &&file_dic/reb_indexes.sql
- SELECT sql_text
- FROM temp_for_pkg_gen_sql2000_temp
- WHERE OBJECT_TYPE = 'REBUILD_INDEX'
- ORDER BY line_no;
- spool off
- -- 生成创建视图的sql语句
- exec pkg_gen_user_sql.pro_view_sql('F','T','T');
- spool &&file_dic/cre_views.sql
- SELECT sql_text
- FROM temp_for_pkg_gen_sql4000_temp
- WHERE OBJECT_TYPE = 'VIEW'
- ORDER BY line_no;
- spool off
- -- 生成创建序列的sql语句
- exec pkg_gen_user_sql.pro_seq_next_val_sql('F');
- spool &&file_dic/cre_sequences.sql
- SELECT sql_text
- FROM temp_for_pkg_gen_sql2000_temp
- WHERE OBJECT_TYPE = 'SEQUENCE'
- ORDER BY line_no;
- spool off
- -- 生成创建初始序列的sql语句, 每个序列的开始值为1
- exec pkg_gen_user_sql.pro_seq_init_val_sql('F');
- spool &&file_dic/cre_sequences_init.sql
- SELECT sql_text
- FROM temp_for_pkg_gen_sql2000_temp
- WHERE OBJECT_TYPE = 'SEQUENCE_INIT'
- ORDER BY line_no;
- spool off
- -- 生成创建同义词的sql语句
- exec pkg_gen_user_sql.pro_synonym_sql('F')
- spool &&file_dic/cre_synonyms.sql
- SELECT rtrim(sql_text)
- FROM temp_for_pkg_gen_sql2000_temp
- WHERE OBJECT_TYPE = 'SYNONYM'
- ORDER BY line_no ;
- spool off
- -- 生成创建job的sql语句
- exec pkg_gen_user_sql.pro_job_sql('F')
- spool &&file_dic/cre_jobs.sql
- SELECT rtrim(sql_text)
- FROM temp_for_pkg_gen_sql4000_temp
- WHERE OBJECT_TYPE = 'JOB'
- ORDER BY line_no ;
- spool off
- -- 生成创建数据库链的sql语句
- exec pkg_gen_user_sql.pro_dl_sql('F')
- spool &&file_dic/cre_db_links.sql
- SELECT rtrim(sql_text)
- FROM temp_for_pkg_gen_sql2000_temp
- WHERE OBJECT_TYPE = 'DL'
- ORDER BY line_no ;
- spool off
- -- 生成创建角色的sql语句
- exec pkg_gen_user_sql.pro_role_sql('F')
- spool &&file_dic/cre_roles.sql
- SELECT rtrim(sql_text)
- FROM temp_for_pkg_gen_sql2000_temp
- WHERE OBJECT_TYPE = 'ROLE'
- ORDER BY line_no ;
- spool off
- -- 生成创建授权的sql语句
- exec pkg_gen_user_sql.pro_priv_sql('F')
- spool &&file_dic/cre_privs.sql
- SELECT rtrim(sql_text)
- FROM temp_for_pkg_gen_sql2000_temp
- WHERE OBJECT_TYPE = 'PRIV'
- ORDER BY line_no ;
- spool off
- -- 生成创建存储过程的sql语句,所有存储过程放在一个文件中
- exec pkg_gen_user_sql.pro_pkgprofuntri_sql('F','T','T','T','&&file_dic')
- spool &&file_dic/procedures/procedures.sql
- SELECT rtrim(sql_text)
- FROM temp_for_pkg_gen_sql4000_temp
- WHERE OBJECT_TYPE = 'PROCEDURE'
- AND lower(rtrim(sql_text)) not like '@%.sql'
- ORDER BY line_no ;
- spool off
- -- 生成创建函数的sql语句,所有函数放在一个文件中
- spool &&file_dic/functions/functions.sql
- SELECT rtrim(sql_text)
- FROM temp_for_pkg_gen_sql4000_temp
- WHERE OBJECT_TYPE = 'FUNCTION'
- AND lower(rtrim(sql_text)) not like '@%.sql'
- ORDER BY line_no ;
- spool off
- -- 生成创建包的sql语句,所有包放在一个文件中
- spool &&file_dic/packages/packages.sql
- SELECT rtrim(sql_text)
- FROM temp_for_pkg_gen_sql4000_temp
- WHERE OBJECT_TYPE like '%PACKAGE%'
- AND lower(rtrim(sql_text)) not like '@%.sql'
- ORDER BY line_no ;
- spool off
- -- 生成创建触发器的sql语句
- spool &&file_dic/triggers/triggers.sql
- SELECT rtrim(sql_text)
- FROM temp_for_pkg_gen_sql4000_temp
- WHERE OBJECT_TYPE = 'TRIGGER'
- ORDER BY line_no ;
- spool off
- -- 生成创建存储过程的sql语句,每个存储过程放在单独的文件中
- spool &&file_dic/temp_sql/separ_pros.sql
- SELECT rtrim(sql_text)
- FROM temp_for_pkg_gen_sql4000_temp
- WHERE OBJECT_TYPE = 'SEPAR_PROCS'
- ORDER BY line_no ;
- spool off
- @ &&file_dic/temp_sql/separ_pros.sql
- -- 生成创建函数的sql语句,每个函数放在单独的文件中
- spool &&file_dic/temp_sql/separ_funcs.sql
- SELECT rtrim(sql_text)
- FROM temp_for_pkg_gen_sql4000_temp
- WHERE OBJECT_TYPE = 'SEPAR_FUNCS'
- ORDER BY line_no ;
- spool off
- @ &&file_dic/temp_sql/separ_funcs.sql
- -- 生成创建包的sql语句,每个包放在单独的文件中
- spool &&file_dic/temp_sql/separ_pkgs.sql
- SELECT rtrim(sql_text)
- FROM temp_for_pkg_gen_sql4000_temp
- WHERE OBJECT_TYPE like '%SEPAR_PKGS%'
- ORDER BY line_no ;
- spool off
- @ &&file_dic/temp_sql/separ_pkgs.sql
- -- 生成创建存储过程的sql语句,每个包的声明与包体各放在单独的文件中
- spool &&file_dic/temp_sql/separ_hb_pkgs.sql
- SELECT rtrim(sql_text)
- FROM temp_for_pkg_gen_sql4000_temp
- WHERE OBJECT_TYPE in ('SEPAR_PKG_HEADS','SEPAR_PKG_BODYS')
- ORDER BY object_name,OBJECT_TYPE desc, line_no ;
- spool off
- @ &&file_dic/temp_sql/separ_hb_pkgs.sql
- -- 生成创建触发器的sql语句,每个触发器放在单独的文件中
- spool &&file_dic/temp_sql/separ_tris.sql
- SELECT rtrim(sql_text)
- FROM temp_for_pkg_gen_sql4000_temp
- WHERE OBJECT_TYPE = 'SEPAR_TRIS'
- ORDER BY line_no ;
- spool off
- @ &&file_dic/temp_sql/separ_tris.sql
- set echo on
- set feedback on
- set newpage 1
- set pagesize 500
- set linesize 80
- set verify on
- set term on
- set trims on
- set linesize 600
- set heading on
- set timing off
- set verify on
- set numwidth 15
- drop table temp_for_pkg_gen_sql2000_temp;
- drop table temp_for_pkg_gen_sql4000_temp;
- drop package pkg_gen_user_sql;