导出创建用户下各个对象数据结构的sql语句的脚本,包括表、视图、索引、约束等等
前言:
这是我用很长时间才写的存储包,其间经历了多次修改,以适应多种情况,今将其贡献出来,如果能读懂这个存储包,恭喜你,你的oracle知识已经达到一定程度了,而且这不失为一个学习oracle存储过程的模板,掌握它之后你可以自如的写存储包,存储过程,和函数了。
在我的实际工作中我发现它的功能很强,可以生成我们常用的对象的创建语句,这在很多情况下比较好用
1。想导出创建用户下的对象的sql语句。
2。有时我们用copy命令与create table as .... 命令在2个数据库之间建立一个用户的所有数据的拷贝时,只能拷贝数据,而如各个约束,索引则不能导过来,此时,该脚本生成的sql语句正好可以弥补这一缺点。
不好意思独享该脚本,共享出来,忘大家共同进步。
版权所有人: 徐玉金
备注:用户可以根据实际需要修改、使用、发布该脚本,但是不能修改版权所有人
适用的数据库:8i, 9i数据库下该脚本通用
功能:导出一个用户的数据结构,包括表、视图、索引、约束、存储过程、触发器、函数、序列等等的定义,并且每个定义为一个文件
导出的各个对象的定义格式比较规范。
如表的定义为:
promptCreate 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数据库下该脚本通用
功能:导出一个用户的数据结构,包括表、视图、索引、约束、存储过程、触发器、函数、序列等等的定义,并且每个定义为一个文件
导出的各个对象的定义格式比较规范。
如表的定义为:
promptCreate 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:存放生成的临时文件
- DEFINEfile_dic=1
- CREATETABLEtemp_for_pkg_gen_sql4000_temp
- (line_noNUMBER(38,0),
- object_typeVARCHAR2(30),
- user_nameVARCHAR2(30),
- object_nameVARCHAR2(200),
- sql_textVARCHAR2(4000)
- );
- --synonym,job,db_link,role,user_type
- CREATETABLEtemp_for_pkg_gen_sql2000_temp
- (line_noNUMBER(38,0),
- object_typeVARCHAR2(30),
- user_nameVARCHAR2(30),
- object_nameVARCHAR2(200),
- sql_textVARCHAR2(2000)
- );
- DELETEtemp_for_pkg_gen_sql4000_temp;
- DELETEtemp_for_pkg_gen_sql2000_temp;
- COMMIT;
- CREATEORREPLACEPACKAGEpkg_gen_user_sqlAS
- --产生start脚本
- PROCEDUREpro_gen_start_sql(p_v_file_pathVARCHAR2default'C:/');
- FUNCTIONfun_return_table_name_tab4(p_v_table_nameVARCHAR2,
- p_n_col_max_lenNUMBER)RETURNVARCHAR2;
- FUNCTIONfun_return_table_name_tab8(p_v_table_nameVARCHAR2,
- p_n_col_max_lenNUMBER)RETURNVARCHAR2;
- --generatesqlforcreatetables;
- PROCEDUREpro_tab_sql_tab4(p_v_gen_drop_sqlVARCHAR2default'T',
- p_v_gen_create_sqlVARCHAR2default'T',
- p_v_gen_store_clauseVARCHAR2default'T',
- p_v_display_prompt_infoVARCHAR2default'T');
- PROCEDUREpro_tab_sql_tab8(p_v_gen_drop_sqlVARCHAR2default'T',
- p_v_gen_create_sqlVARCHAR2default'T',
- p_v_gen_store_clauseVARCHAR2default'T',
- p_v_display_prompt_infoVARCHAR2default'T');
- PROCEDUREpro_con_sql(p_v_con_typeVARCHAR2default'ALL',
- p_v_gen_drop_sqlVARCHAR2default'T',
- p_v_gen_create_sqlVARCHAR2default'T',
- p_v_gen_null_chkVARCHAR2default'T',
- p_v_display_prompt_infoVARCHAR2default'T');
- PROCEDUREpro_indx_sql(p_v_gen_drop_sqlVARCHAR2default'T',
- p_v_gen_create_sqlVARCHAR2default'T',
- p_v_gen_store_clauseVARCHAR2default'T',
- p_v_gen_ts_onlyVARCHAR2default'F',
- p_v_display_prompt_infoVARCHAR2default'T');
- --重建索引
- PROCEDUREpro_reb_indx_sql(p_v_gen_store_clauseVARCHAR2default'T',
- p_v_rebuild_onlineVARCHAR2default'T',
- p_v_display_prompt_infoVARCHAR2default'T');
- PROCEDUREpro_view_sql(p_v_gen_drop_sqlVARCHAR2default'T',
- p_v_gen_create_sqlVARCHAR2default'T',
- p_v_display_prompt_infoVARCHAR2default'T');
- PROCEDUREpro_seq_max_val_sql(p_v_gen_drop_sqlVARCHAR2default'T',
- p_v_gen_create_sqlVARCHAR2default'T',
- p_v_display_prompt_infoVARCHAR2default'T');
- PROCEDUREpro_seq_next_val_sql(p_v_gen_drop_sqlVARCHAR2default'T',
- p_v_gen_create_sqlVARCHAR2default'T',
- p_v_display_prompt_infoVARCHAR2default'T');
- PROCEDUREpro_seq_init_val_sql(p_v_gen_drop_sqlVARCHAR2default'T',
- p_v_gen_create_sqlVARCHAR2default'T',
- p_v_display_prompt_infoVARCHAR2default'T');
- PROCEDUREpro_synonym_sql(p_v_gen_drop_sqlVARCHAR2default'T',
- p_v_gen_create_sqlVARCHAR2default'T',
- p_v_display_prompt_infoVARCHAR2default'T');
- PROCEDUREpro_job_sql(p_v_gen_drop_sqlVARCHAR2default'T',
- p_v_gen_create_sqlVARCHAR2default'T',
- p_v_display_prompt_infoVARCHAR2default'T');
- PROCEDUREpro_dl_sql(p_v_gen_drop_sqlVARCHAR2default'T',
- p_v_gen_create_sqlVARCHAR2default'T',
- p_v_display_prompt_infoVARCHAR2default'T');
- PROCEDUREpro_role_sql(p_v_gen_drop_sqlVARCHAR2default'T',
- p_v_gen_create_sqlVARCHAR2default'T',
- p_v_display_prompt_infoVARCHAR2default'T');
- PROCEDUREpro_priv_sql(p_v_gen_drop_sqlVARCHAR2default'T',
- p_v_gen_create_sqlVARCHAR2default'T',
- p_v_display_prompt_infoVARCHAR2default'T');
- PROCEDUREpro_pkgprofuntri_sql(p_v_gen_drop_sqlVARCHAR2default'T',
- p_v_gen_create_sqlVARCHAR2default'T',
- p_v_display_prompt_infoVARCHAR2default'T',
- p_v_separ_fileVARCHAR2default'T',
- p_v_file_pathVARCHAR2default'C:/');
- ENDpkg_gen_user_sql;
- /
- showerr
- showerr
- CREATEORREPLACEPACKAGEBODYpkg_gen_user_sqlAS
- PROCEDUREpro_gen_start_sql(p_v_file_pathVARCHAR2default'C:/')AS
- v_usernameVARCHAR2(30);
- v_object_typeVARCHAR2(30);
- n_line_noNUMBER(10,0);
- v_sqlVARCHAR2(2000);
- v_promptVARCHAR2(30);
- v_file_pathVARCHAR2(600);
- v_notionchar(1);
- PROCEDUREinsert_rec(p_line_noINTEGER,
- p_object_typeVARCHAR2,
- p_user_nameVARCHAR2,
- p_view_nameVARCHAR2,
- p_stringVARCHAR2)IS
- BEGIN
- INSERTINTOtemp_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;
- --findthenotionbetweenthedictionary
- IFinstr(p_v_file_path,'/')>0THEN
- v_notion:='/';
- ELSE
- v_notion:='/';
- ENDIF;
- IFsubstr(v_file_path,length(v_file_path))<>v_notionTHEN
- v_file_path:=v_file_path||v_notion;
- ENDIF;
- SELECTusernameINTOv_usernameFROMuser_users;
- DELETEtemp_for_pkg_gen_sql2000_tempWHEREobject_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:='--*****importdata*****--';
- 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;
- FUNCTIONfun_return_table_name_tab4(p_v_table_nameVARCHAR2,
- p_n_col_max_lenNUMBER)RETURNVARCHAR2AS
- v_table_nameVARCHAR2(100);
- v_tempVARCHAR2(100);
- n_col_max_lenNUMBER;
- BEGIN
- v_table_name:=trim(p_v_table_name);
- n_col_max_len:=p_n_col_max_len;
- v_temp:=v_table_name;
- WHILEmod(length(v_temp),4)<>0LOOP
- v_temp:=v_temp||'';
- ENDLOOP;
- IFmod(length(v_table_name),4)<>0THEN
- v_table_name:=v_table_name||chr(9);
- ENDIF;
- WHILElength(v_temp)<n_col_max_lenLOOP
- v_table_name:=v_table_name||chr(9);
- v_temp:=v_temp||'';
- ENDLOOP;
- RETURNv_table_name;
- END;
- FUNCTIONfun_return_table_name_tab8(p_v_table_nameVARCHAR2,
- p_n_col_max_lenNUMBER)RETURNVARCHAR2AS
- v_table_nameVARCHAR2(100);
- v_tempVARCHAR2(100);
- n_col_max_lenNUMBER;
- BEGIN
- v_table_name:=trim(p_v_table_name);
- n_col_max_len:=p_n_col_max_len;
- v_temp:=v_table_name;
- WHILEmod(length(v_temp),8)<>0LOOP
- v_temp:=v_temp||'';
- ENDLOOP;
- IFmod(length(v_table_name),8)<>0THEN
- v_table_name:=v_table_name||chr(9);
- ENDIF;
- WHILElength(v_temp)<n_col_max_lenLOOP
- v_table_name:=v_table_name||chr(9);
- v_temp:=v_temp||'';
- ENDLOOP;
- RETURNv_table_name;
- END;
- PROCEDUREpro_tab_sql_tab4(p_v_gen_drop_sqlVARCHAR2default'T',
- p_v_gen_create_sqlVARCHAR2default'T',
- p_v_gen_store_clauseVARCHAR2default'T',
- p_v_display_prompt_infoVARCHAR2default'T')AS
- CURSORcur_tablesis
- SELECTtable_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
- FROMuser_tables
- WHERElower(TABLE_NAME)NOTIN
- ('temp_for_pkg_gen_sql2000_temp',
- 'temp_for_pkg_gen_sql4000_temp')
- ORDERBYtable_name;
- CURSORcur_cols(t_nameVARCHAR2)is
- SELECTtable_name,
- column_name,
- data_type,
- data_length,
- data_precision,
- data_scale,
- nullable,
- data_default
- FROMuser_tab_columns
- WHEREtable_name=t_name
- ORDERBYcolumn_id;
- v_tab_nameVARCHAR2(40);
- v_tabsp_nameVARCHAR2(40);
- n_mpct_freeuser_tables.pct_free%TYPE;
- n_mpct_useduser_tables.pct_used%TYPE;
- n_mini_transuser_tables.ini_trans%TYPE;
- n_mmax_transuser_tables.max_trans%TYPE;
- n_mini_extuser_tables.initial_extent%TYPE;
- n_mnext_extuser_tables.next_extent%TYPE;
- n_mmin_extuser_tables.min_extents%TYPE;
- n_mmax_extuser_tables.max_extents%TYPE;
- n_mpct_incuser_tables.pct_increase%TYPE;
- n_freelistsuser_tables.freelists%TYPE;
- n_freelist_groupsuser_tables.freelist_groups%TYPE;
- v_buffer_pooluser_tables.buffer_pool%TYPE;
- v_loggingVARCHAR2(15);
- col_nameVARCHAR2(40);
- ctNUMBER:=0;
- n_line_noNUMBER:=0;
- col_contentVARCHAR2(120);
- n_col_max_lenNUMBER(10,0);
- v_default_valVARCHAR2(4000);
- v_gen_drop_tab_sqlVARCHAR2(10);
- v_gen_create_tab_sqlVARCHAR2(10);
- v_gen_store_clauseVARCHAR2(10);
- v_display_prompt_infoVARCHAR2(10);
- v_usernameVARCHAR2(30);
- v_sqlVARCHAR2(2000);
- n_positionNUMBER(6,0);
- v_object_typeVARCHAR2(10);
- v_promptVARCHAR2(10);
- PROCEDUREinsert_rec(p_line_noINTEGER,
- p_object_typeVARCHAR2,
- p_user_nameVARCHAR2,
- p_object_nameVARCHAR2,
- p_stringVARCHAR2)IS
- BEGIN
- INSERTINTOtemp_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;
- SELECTusernameINTOv_usernameFROMuser_users;
- DELETEtemp_for_pkg_gen_sql2000_tempWHEREOBJECT_TYPE=v_object_type;
- COMMIT;
- FORcur_tables_recINcur_tablesLOOP
- 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;
- IFv_gen_drop_tab_sql='T'THEN
- IFupper(v_display_prompt_info)='T'THEN
- v_sql:=v_prompt||'DropTable'||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;
- ENDIF;
- v_sql:='ALTERTABLE'||v_tab_name||
- 'dropprimarykeycascade;';
- insert_rec(n_line_no,v_object_type,v_username,v_tab_name,v_sql);
- n_line_no:=n_line_no+1;
- v_sql:='DROPTABLE'||v_tab_name||'cascadeconstraint;';
- 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;
- ENDIF;
- IFupper(v_gen_create_tab_sql)='T'THEN
- IFupper(v_display_prompt_info)='T'THEN
- v_sql:=v_prompt||'CreateTable'||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;
- ENDIF;
- v_sql:='CREATETABLE'||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;
- FORcur_cols_recINcur_cols(v_tab_name)LOOP
- IFn_col_max_len<length(trim(cur_cols_rec.column_name))THEN
- n_col_max_len:=length(trim(cur_cols_rec.column_name));
- ENDIF;
- ENDLOOP;
- ct:=0;
- FORcur_cols_recINcur_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);
- WHILEn_position>0LOOP
- IFn_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);
- ENDIF;
- n_position:=instr(v_default_val,chr(10),-1);
- ENDLOOP;
- n_position:=instr(v_default_val,chr(9),-1);
- IFn_position=length(v_default_val)THEN
- v_default_val:=substr(v_default_val,1,n_position-1);
- ENDIF;
- IFct=1THEN
- INSERTINTOtemp_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)||'NOTNULL,',
- chr(9)||'default'||chr(9)||v_default_val||
- chr(9)||chr(9)||'NOTNULL,')));
- n_line_no:=n_line_no+1;
- ELSE
- INSERTINTOtemp_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)||'NOTNULL,',
- chr(9)||'default'||chr(9)||v_default_val||
- chr(9)||chr(9)||'NOTNULL,')));
- n_line_no:=n_line_no+1;
- ENDIF;
- ENDLOOP;
- SELECTrtrim(sql_text)
- intocol_content
- FROMtemp_for_pkg_gen_sql2000_temp
- WHEREline_no=n_line_no-1
- ANDobject_type=v_object_type;
- col_content:=substr(col_content,1,length(col_content)-1);
- UPDATEtemp_for_pkg_gen_sql2000_temp
- SETsql_text=col_content
- WHEREline_no=n_line_no-1
- ANDobject_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;
- IFv_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;
- IFn_mnext_extISNOTNULLTHEN
- UPDATEtemp_for_pkg_gen_sql2000_temp
- SETsql_text=sql_text||chr(9)||'NEXT'||
- to_char(n_mnext_ext)
- WHEREline_no=n_line_no-1
- ANDobject_type=v_object_type;
- ENDIF;
- UPDATEtemp_for_pkg_gen_sql2000_temp
- SETsql_text=sql_text||chr(9)||'PCTINCREASE'||
- to_char(n_mpct_inc)
- WHEREline_no=n_line_no-1
- ANDobject_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;
- UPDATEtemp_for_pkg_gen_sql2000_temp
- SETsql_text=sql_text||chr(9)||'FREELISTGROUPS'||
- to_char(n_freelist_groups)
- WHEREline_no=n_line_no-1
- ANDobject_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;
- UPDATEtemp_for_pkg_gen_sql2000_temp
- SETsql_text=sql_text||');'
- WHEREline_no=n_line_no-1
- ANDobject_type=v_object_type;
- ELSE
- UPDATEtemp_for_pkg_gen_sql2000_temp
- SETsql_text=sql_text||';'
- WHEREline_no=n_line_no-1
- ANDobject_type=v_object_type;
- ENDIF;
- v_sql:='';
- insert_rec(n_line_no,v_object_type,v_username,v_tab_name,v_sql);
- n_line_no:=n_line_no+1;
- ENDIF;
- ENDLOOP;
- COMMIT;
- END;
- PROCEDUREpro_tab_sql_tab8(p_v_gen_drop_sqlVARCHAR2default'T',
- p_v_gen_create_sqlVARCHAR2default'T',
- p_v_gen_store_clauseVARCHAR2default'T',
- p_v_display_prompt_infoVARCHAR2default'T')AS
- CURSORcur_tablesIS
- SELECTtable_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
- FROMuser_tables
- WHERElower(TABLE_NAME)NOTIN
- ('temp_for_pkg_gen_sql2000_temp',
- 'temp_for_pkg_gen_sql4000_temp')
- ORDERBYtable_name;
- CURSORcur_cols(t_nameVARCHAR2)IS
- SELECTtable_name,
- column_name,
- data_type,
- data_length,
- data_precision,
- data_scale,
- nullable,
- data_default
- FROMuser_tab_columns
- WHEREtable_name=t_name
- ORDERBYcolumn_id;
- v_tab_nameVARCHAR2(40);
- v_tabsp_nameVARCHAR2(40);
- n_mpct_freeuser_tables.pct_free%TYPE;
- n_mpct_useduser_tables.pct_used%TYPE;
- n_mini_transuser_tables.ini_trans%TYPE;
- n_mmax_transuser_tables.max_trans%TYPE;
- n_mini_extuser_tables.initial_extent%TYPE;
- n_mnext_extuser_tables.next_extent%TYPE;
- n_mmin_extuser_tables.min_extents%TYPE;
- n_mmax_extuser_tables.max_extents%TYPE;
- n_mpct_incuser_tables.pct_increase%TYPE;
- n_freelistsuser_tables.freelists%TYPE;
- n_freelist_groupsuser_tables.freelist_groups%TYPE;
- v_buffer_pooluser_tables.buffer_pool%TYPE;
- v_loggingVARCHAR2(15);
- col_nameVARCHAR2(40);
- ctNUMBER:=0;
- n_line_noNUMBER:=0;
- col_contentVARCHAR2(120);
- n_col_max_lenNUMBER(10,0);
- v_default_valVARCHAR2(4000);
- v_gen_drop_tab_sqlVARCHAR2(10);
- v_gen_create_tab_sqlVARCHAR2(10);
- v_gen_store_clauseVARCHAR2(10);
- v_display_prompt_infoVARCHAR2(10);
- v_usernameVARCHAR2(30);
- v_sqlVARCHAR2(2000);
- n_positionNUMBER(6,0);
- v_object_typeVARCHAR2(10);
- v_promptVARCHAR2(10);
- PROCEDUREinsert_rec(p_line_noINTEGER,
- p_object_typeVARCHAR2,
- p_user_nameVARCHAR2,
- p_object_nameVARCHAR2,
- p_stringVARCHAR2)IS
- BEGIN
- INSERTINTOtemp_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;
- SELECTusernameINTOv_usernameFROMuser_users;
- DELETEtemp_for_pkg_gen_sql2000_tempWHEREOBJECT_TYPE=v_object_type;
- COMMIT;
- FORcur_tables_recINcur_tablesLOOP
- 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;
- IFv_gen_drop_tab_sql='T'THEN
- IFupper(v_display_prompt_info)='T'THEN
- v_sql:=v_prompt||'DropTable'||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;
- ENDIF;
- v_sql:='ALTERTABLE'||v_tab_name||
- 'dropprimarykeycascade;';
- insert_rec(n_line_no,v_object_type,v_username,v_tab_name,v_sql);
- n_line_no:=n_line_no+1;
- v_sql:='DROPTABLE'||v_tab_name||'cascadeconstraint;';
- 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;
- ENDIF;
- IFupper(v_gen_create_tab_sql)='T'THEN
- IFupper(v_display_prompt_info)='T'THEN
- v_sql:=v_prompt||'CreateTable'||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;
- ENDIF;
- v_sql:='CREATETABLE'||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;
- FORcur_cols_recINcur_cols(v_tab_name)LOOP
- IFn_col_max_len<length(trim(cur_cols_rec.column_name))THEN
- n_col_max_len:=length(trim(cur_cols_rec.column_name));
- ENDIF;
- ENDLOOP;
- ct:=0;
- FORcur_cols_recINcur_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);
- WHILEn_position>0LOOP
- IFn_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);
- ENDIF;
- n_position:=instr(v_default_val,chr(10),-1);
- ENDLOOP;
- n_position:=instr(v_default_val,chr(9),-1);
- IFn_position=length(v_default_val)THEN
- v_default_val:=substr(v_default_val,1,n_position-1);
- ENDIF;
- IFct=1THEN
- INSERTINTOtemp_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)||'NOTNULL,',
- chr(9)||'default'||chr(9)||v_default_val||
- chr(9)||chr(9)||'NOTNULL,')));
- n_line_no:=n_line_no+1;
- ELSE
- INSERTINTOtemp_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)||'NOTNULL,',
- chr(9)||'default'||chr(9)||v_default_val||
- chr(9)||chr(9)||'NOTNULL,')));
- n_line_no:=n_line_no+1;
- ENDIF;
- ENDLOOP;
- SELECTrtrim(sql_text)
- intocol_content
- FROMtemp_for_pkg_gen_sql2000_temp
- WHEREline_no=n_line_no-1
- ANDobject_type=v_object_type;
- col_content:=substr(col_content,1,length(col_content)-1);
- UPDATEtemp_for_pkg_gen_sql2000_temp
- SETsql_text=col_content
- WHEREline_no=n_line_no-1
- ANDobject_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;
- IFv_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;
- IFn_mnext_extISNOTNULLTHEN
- UPDATEtemp_for_pkg_gen_sql2000_temp
- SETsql_text=sql_text||chr(9)||'NEXT'||
- to_char(n_mnext_ext)
- WHEREline_no=n_line_no-1
- ANDobject_type=v_object_type;
- ENDIF;
- UPDATEtemp_for_pkg_gen_sql2000_temp
- SETsql_text=sql_text||chr(9)||'PCTINCREASE'||
- to_char(n_mpct_inc)
- WHEREline_no=n_line_no-1
- ANDobject_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;
- UPDATEtemp_for_pkg_gen_sql2000_temp
- SETsql_text=sql_text||chr(9)||'FREELISTGROUPS'||
- to_char(n_freelist_groups)
- WHEREline_no=n_line_no-1
- ANDobject_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;
- UPDATEtemp_for_pkg_gen_sql2000_temp
- SETsql_text=sql_text||');'
- WHEREline_no=n_line_no-1
- ANDobject_type=v_object_type;
- ELSE
- UPDATEtemp_for_pkg_gen_sql2000_temp
- SETsql_text=sql_text||';'
- WHEREline_no=n_line_no-1
- ANDobject_type=v_object_type;
- ENDIF;
- v_sql:='';
- insert_rec(n_line_no,v_object_type,v_username,v_tab_name,v_sql);
- n_line_no:=n_line_no+1;
- ENDIF;
- ENDLOOP;
- COMMIT;
- END;
- PROCEDUREpro_con_sql(p_v_con_typeVARCHAR2default'ALL',
- p_v_gen_drop_sqlVARCHAR2default'T',
- p_v_gen_create_sqlVARCHAR2default'T',
- p_v_gen_null_chkVARCHAR2default'T',
- p_v_display_prompt_infoVARCHAR2default'T')AS
- CURSORcur_tablesis
- SELECTtable_nameFROMuser_tablesORDERBYtable_name;
- CURSORcur_con_cols(c_nameVARCHAR2)IS
- SELECTcolumn_name
- FROMuser_cons_columns
- WHEREconstraint_name=c_name
- ORDERBYposition;
- typeref_curisREFCURSOR;--定义一个ref类型的游标
- cur_consref_cur;--定义游标变量
- TYPEtype_conISRECORD(
- constraint_nameuser_constraints.constraint_name%type,
- r_constraint_nameuser_constraints.r_constraint_name%type,
- constraint_typeuser_constraints.constraint_type%type,
- search_conditionuser_constraints.search_condition%type);
- cur_cons_rectype_con;
- v_tab_nameVARCHAR2(40);
- v_table_nameVARCHAR2(40);
- v_typeVARCHAR2(1);
- n_ctNUMBER:=0;
- n_line_noNUMBER:=0;
- v_con_typeVARCHAR2(10);
- v_con_sqlVARCHAR2(500);
- v_sqlVARCHAR2(2000);
- v_gen_drop_con_sqlVARCHAR2(10);
- v_display_prompt_infoVARCHAR2(10);
- v_gen_create_con_sqlVARCHAR2(10);
- v_gen_null_chkVARCHAR2(10);
- v_usernameVARCHAR2(30);
- v_object_typeVARCHAR2(30);
- v_promptVARCHAR2(30);
- v_search_conditionVARCHAR2(1000);
- PROCEDUREinsert_rec(p_line_noINTEGER,
- p_object_typeVARCHAR2,
- p_user_nameVARCHAR2,
- p_con_nameVARCHAR2,
- p_stringVARCHAR2)IS
- BEGIN
- INSERTINTOtemp_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;
- SELECTusernameINTOv_usernameFROMuser_users;
- DELETEFROMtemp_for_pkg_gen_sql2000_temp
- WHEREobject_type=v_object_type;
- COMMIT;
- FORcur_tables_recINcur_tablesLOOP
- v_tab_name:=trim(cur_tables_rec.table_name);
- --Gettheconstraintinfoforspecifiedtable
- v_con_sql:='SELECTconstraint_name,r_constraint_name,';
- v_con_sql:=v_con_sql||'constraint_type,search_condition';
- v_con_sql:=v_con_sql||'FROMuser_constraints';
- IFupper(v_con_type)<>'ALL'ANDupper(v_con_type)<>'A'AND
- upper(v_con_type)<>'NOT_PRI'THEN
- v_con_sql:=v_con_sql||'WHEREtable_name='''||v_tab_name||
- '''ANDconstraint_type='''||upper(v_con_type)||
- '''';
- ELSIFupper(v_con_type)='NOT_PRI'THEN
- v_con_sql:=v_con_sql||'WHEREtable_name='''||v_tab_name||
- '''ANDconstraint_type<>''P''';
- ELSE
- v_con_sql:=v_con_sql||'WHEREtable_name='''||v_tab_name||
- '''';
- ENDIF;
- v_con_sql:=v_con_sql||'ORDERBYconstraint_name';
- OPENcur_consFORv_con_sql;
- LOOP
- FETCHcur_cons
- INTOcur_cons_rec;
- EXITWHENcur_cons%NOTFOUND;
- v_type:=cur_cons_rec.constraint_type;
- v_search_condition:=cur_cons_rec.search_condition;
- IFupper(v_gen_drop_con_sql)='T'THEN
- IFv_gen_null_chk='F'ANDv_type='C'AND
- instr(v_search_condition,'ISNOTNULL')>0THEN
- --donull
- v_gen_null_chk:=v_gen_null_chk;
- ELSE
- IFupper(v_display_prompt_info)='T'THEN
- --insertpromptinfo
- INSERTINTOtemp_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||'Dropconstraints:'||v_tab_name||'.'||
- trim(cur_cons_rec.constraint_name)||';Type:'||
- decode(v_type,
- 'C',
- 'CHECK',
- 'P',
- 'PRIMARYKEY',
- 'U',
- 'UNIQUE',
- 'R',
- 'FROEIGNRELATION',
- v_type));
- n_line_no:=n_line_no+1;
- ENDIF;
- v_sql:='altertable'||v_tab_name||'dropconstraint'||
- 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;
- ENDIF;
- ENDIF;
- IFupper(v_gen_create_con_sql)='T'THEN
- IFv_gen_null_chk='F'ANDv_type='C'AND
- instr(v_search_condition,'ISNOTNULL')>0THEN
- --donull
- v_gen_null_chk:=v_gen_null_chk;
- ELSE
- IFupper(v_display_prompt_info)='T'THEN
- --insertpromptinfo
- INSERTINTOtemp_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||'Addconstraints:'||v_tab_name||'.'||
- trim(cur_cons_rec.constraint_name)||';Type:'||
- decode(v_type,
- 'C',
- 'CHECK',
- 'P',
- 'PRIMARYKEY',
- 'U',
- 'UNIQUE',
- 'R',
- 'FROEIGNRELATION',
- v_type));
- n_line_no:=n_line_no+1;
- ENDIF;
- v_sql:='altertable'||v_tab_name||'addconstraint'||
- 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;
- IFv_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;
- ENDIF;
- n_ct:=0;
- FORcur_con_cols_recINcur_con_cols(cur_cons_rec.constraint_name)LOOP
- n_ct:=n_ct+1;
- IFn_ct=1THEN
- IFv_type='R'THEN
- v_sql:='foreignkey('||
- 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;
- ENDIF;
- IFv_type='P'THEN
- v_sql:='primarykey('||
- 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;
- ENDIF;
- IFv_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;
- ENDIF;
- ELSE
- UPDATEtemp_for_pkg_gen_sql2000_temp
- SETsql_text=rtrim(sql_text)||','||
- trim(cur_con_cols_rec.column_name)
- WHEREline_no=n_line_no-1
- ANDobject_type=v_object_type;
- ENDIF;
- ENDLOOP;
- UPDATEtemp_for_pkg_gen_sql2000_temp
- SETsql_text=rtrim(sql_text)||')'
- WHEREline_no=n_line_no-1
- ANDobject_type=v_object_type;
- IFv_type='R'THEN
- SELECTtable_name
- intov_table_name
- FROMuser_constraints
- WHEREconstraint_name=cur_cons_rec.r_constraint_name;
- n_ct:=0;
- FORcur_con_cols_recINcur_con_cols(cur_cons_rec.r_constraint_name)LOOP
- n_ct:=n_ct+1;
- IFn_ct=1THEN
- 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;
- UPDATEtemp_for_pkg_gen_sql2000_temp
- SETsql_text=rtrim(sql_text)||
- trim(cur_con_cols_rec.column_name)
- WHEREline_no=n_line_no-1
- ANDobject_type=v_object_type;
- ELSE
- UPDATEtemp_for_pkg_gen_sql2000_temp
- SETsql_text=rtrim(sql_text)||','||
- trim(cur_con_cols_rec.column_name)
- WHEREline_no=n_line_no-1
- ANDobject_type=v_object_type;
- ENDIF;
- ENDLOOP;
- UPDATEtemp_for_pkg_gen_sql2000_temp
- SETsql_text=rtrim(sql_text)||')'
- WHEREline_no=n_line_no-1
- ANDobject_type=v_object_type;
- ELSE
- IFv_type='P'orv_type='U'THEN
- UPDATEtemp_for_pkg_gen_sql2000_temp
- SETsql_text=rtrim(sql_text)||'USINGINDEX'
- WHEREline_no=n_line_no-1
- ANDobject_type=v_object_type;
- ENDIF;
- ENDIF;
- UPDATEtemp_for_pkg_gen_sql2000_temp
- SETsql_text=sql_text||';'
- WHEREline_no=n_line_no-1
- ANDobject_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;
- ENDIF;
- ENDIF;
- ENDLOOP;
- CLOSEcur_cons;
- ENDLOOP;
- COMMIT;
- END;
- PROCEDUREpro_indx_sql(p_v_gen_drop_sqlVARCHAR2default'T',
- p_v_gen_create_sqlVARCHAR2default'T',
- p_v_gen_store_clauseVARCHAR2default'T',
- p_v_gen_ts_onlyVARCHAR2default'F',
- p_v_display_prompt_infoVARCHAR2default'T')AS
- CURSORcur_indxesIS
- SELECTindex_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
- FROMuser_indexes
- WHEREindex_type<>'LOB'
- ORDERBYindex_name;
- CURSORcur_cols(c_indVARCHAR2,c_tabVARCHAR2)IS
- SELECTcolumn_name
- FROMuser_ind_columns
- WHEREindex_name=c_ind
- ANDtable_name=c_tab
- ORDERBYcolumn_position;
- CURSORcur_fun_expression(c_indVARCHAR2,c_tabVARCHAR2)IS
- SELECTcolumn_expression
- FROMuser_ind_expressions
- WHEREindex_name=c_ind
- andtable_name=c_tab;
- v_index_nameuser_indexes.index_name%TYPE;
- v_table_owneruser_indexes.table_owner%TYPE;
- v_table_nameuser_indexes.table_name%TYPE;
- v_index_typeuser_indexes.index_type%TYPE;
- v_uniquenessuser_indexes.uniqueness%TYPE;
- v_tablespace_nameuser_indexes.tablespace_name%TYPE;
- n_ini_transuser_indexes.ini_trans%TYPE;
- n_max_transuser_indexes.max_trans%TYPE;
- n_initial_extentuser_indexes.initial_extent%TYPE;
- n_next_extentuser_indexes.next_extent%TYPE;
- n_min_extentsuser_indexes.min_extents%TYPE;
- n_max_extentsuser_indexes.max_extents%TYPE;
- n_pct_increaseuser_indexes.pct_increase%TYPE;
- n_pct_freeuser_indexes.pct_free%TYPE;
- n_freelistsuser_indexes.freelists%TYPE;
- n_freelist_groupsuser_indexes.freelist_groups%TYPE;
- v_buffer_pooluser_indexes.buffer_pool%TYPE;
- v_loggingVARCHAR2(15);
- lv_column_nameuser_ind_columns.column_name%TYPE;
- b_first_recBOOLEAN;
- v_stringVARCHAR2(800);
- n_line_noNUMBER:=0;
- v_gen_drop_indx_sqlVARCHAR2(10);
- v_gen_create_indx_sqlVARCHAR2(10);
- v_gen_store_clauseVARCHAR2(10);
- v_display_prompt_infoVARCHAR2(10);
- v_gen_ts_onlyVARCHAR2(10);
- n_tempNUMBER(10,0);
- v_object_typeVARCHAR2(30);
- v_promptVARCHAR2(30);
- v_usernameVARCHAR2(30);
- procedureinsert_rec(p_line_noINTEGER,
- p_object_typeVARCHAR2,
- p_user_nameVARCHAR2,
- p_index_nameVARCHAR2,
- p_stringVARCHAR2)IS
- BEGIN
- INSERTINTOtemp_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';
- SELECTusernameINTOv_usernameFROMuser_users;
- DELETEFROMtemp_for_pkg_gen_sql2000_temp
- WHEREobject_type=v_object_type;
- COMMIT;
- n_line_no:=1;
- OPENcur_indxes;
- LOOP
- FETCHcur_indxes
- INTOv_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;
- EXITWHENcur_indxes%NOTFOUND;
- b_first_rec:=TRUE;
- IFupper(v_gen_drop_indx_sql)='T'THEN
- IFupper(v_display_prompt_info)='T'THEN
- IFv_uniqueness='UNIQUE'ANDv_index_type='NORMAL'THEN
- v_string:=v_prompt||'DROPUNIQUEINDEX'||
- lower(v_index_name);
- ELSIFv_uniqueness<>'UNIQUE'ANDv_index_type='NORMAL'THEN
- v_string:=v_prompt||'DROPINDEX'||lower(v_index_name);
- ELSIFv_index_type='BITMAP'THEN
- v_string:=v_prompt||'DROPBITMAPINDEX'||
- lower(v_index_name);
- ELSIFv_uniqueness='UNIQUE'ANDv_index_type='NORMAL/REV'THEN
- v_string:=v_prompt||'DROPUNIQUE,REVERSEINDEX'||
- lower(v_index_name);
- ELSIFv_uniqueness<>'UNIQUE'ANDv_index_type='NORMAL/REV'THEN
- v_string:=v_prompt||'DROPREVERSEINDEX'||
- lower(v_index_name);
- ELSIFv_uniqueness='UNIQUE'AND
- v_index_type='FUNCTION-BASEDNORMAL'THEN
- v_string:=v_prompt||'DROPUNIQUE,FUNCTIONINDEX'||
- lower(v_index_name);
- ELSIFv_uniqueness<>'UNIQUE'AND
- v_index_type='FUNCTION-BASEDNORMAL'THEN
- v_string:=v_prompt||'DROPFUNCTIONINDEX'||
- lower(v_index_name);
- ENDIF;
- insert_rec(n_line_no,
- v_object_type,
- v_username,
- v_index_name,
- v_string);
- n_line_no:=n_line_no+1;
- ENDIF;
- v_string:='DROPINDEX'||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;
- ENDIF;
- IFupper(v_gen_create_indx_sql)='T'THEN
- IFupper(p_v_display_prompt_info)='T'THEN
- IFv_uniqueness='UNIQUE'ANDv_index_type='NORMAL'THEN
- v_string:=v_prompt||'CREATEUNIQUEINDEX'||
- lower(v_index_name);
- ELSIFv_uniqueness<>'UNIQUE'ANDv_index_type='NORMAL'THEN
- v_string:=v_prompt||'CREATEINDEX'||lower(v_index_name);
- ELSIFv_index_type='BITMAP'THEN
- v_string:=v_prompt||'CREATEBITMAPINDEX'||
- lower(v_index_name);
- ELSIFv_uniqueness='UNIQUE'ANDv_index_type='NORMAL/REV'THEN
- v_string:=v_prompt||'CREATEUNIQUE,REVERSEINDEX'||
- lower(v_index_name);
- ELSIFv_uniqueness<>'UNIQUE'ANDv_index_type='NORMAL/REV'THEN
- v_string:=v_prompt||'CREATEREVERSEINDEX'||
- lower(v_index_name);
- ELSIFv_uniqueness='UNIQUE'AND
- v_index_type='FUNCTION-BASEDNORMAL'THEN
- v_string:=v_prompt||'CREATEUNIQUE,FUNCTIONINDEX'||
- lower(v_index_name);
- ELSIFv_uniqueness<>'UNIQUE'AND
- v_index_type='FUNCTION-BASEDNORMAL'THEN
- v_string:=v_prompt||'CREATEFUNCTIONINDEX'||
- lower(v_index_name);
- ENDIF;
- insert_rec(n_line_no,
- v_object_type,
- v_username,
- v_index_name,
- v_string);
- n_line_no:=n_line_no+1;
- ENDIF;
- IFv_uniqueness='UNIQUE'ANDv_index_type='NORMAL'THEN
- v_string:='CREATEUNIQUEINDEX'||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;
- ELSIFv_uniqueness<>'UNIQUE'ANDv_index_type='NORMAL'THEN
- v_string:='CREATEINDEX'||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;
- ELSIFv_index_type='BITMAP'THEN
- v_string:='CREATEBITMAPINDEX'||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;
- ELSIFv_uniqueness='UNIQUE'ANDv_index_type='NORMAL/REV'THEN
- v_string:='CREATEUNIQUEINDEX'||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;
- ELSIFv_uniqueness<>'UNIQUE'ANDv_index_type='NORMAL/REV'THEN
- v_string:='CREATEINDEX'||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;
- ELSIFv_uniqueness='UNIQUE'AND
- v_index_type='FUNCTION-BASEDNORMAL'THEN
- v_string:='CREATEUNIQUEINDEX'||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;
- ELSIFv_uniqueness<>'UNIQUE'AND
- v_index_type='FUNCTION-BASEDNORMAL'THEN
- v_string:='CREATEINDEX'||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;
- ENDIF;
- IFv_index_type<>'FUNCTION-BASEDNORMAL'THEN
- OPENcur_cols(v_index_name,v_table_name);
- LOOP
- FETCHcur_cols
- INTOlv_column_name;
- EXITWHENcur_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||',';
- ENDIF;
- v_string:=v_string||lower(lv_column_name);
- ENDLOOP;
- CLOSEcur_cols;
- ELSE
- OPENcur_fun_expression(v_index_name,v_table_name);
- LOOP
- FETCHcur_fun_expression
- INTOlv_column_name;
- EXITWHENcur_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);
- ENDLOOP;
- CLOSEcur_fun_expression;
- ENDIF;
- 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;
- IFupper(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);
- IFn_next_extentISNOTNULLTHEN
- v_string:=v_string||'NEXT'||to_char(n_next_extent);
- ENDIF;
- 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)||
- 'FREELISTGROUPS'||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;
- UPDATEtemp_for_pkg_gen_sql2000_temp
- SETsql_text=sql_text||')'
- WHEREline_no=n_line_no-1
- ANDobject_type=v_object_type;
- ELSE
- IFupper(v_gen_store_clause)='F'ANDupper(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;
- ENDIF;
- ENDIF;
- IFv_index_type<>'NORMAL/REV'THEN
- UPDATEtemp_for_pkg_gen_sql2000_temp
- SETsql_text=sql_text||';'
- WHEREline_no=n_line_no-1
- ANDobject_type=v_object_type;
- ELSE
- UPDATEtemp_for_pkg_gen_sql2000_temp
- SETsql_text=sql_text||'REVERSE;'
- WHEREline_no=n_line_no-1
- ANDobject_type=v_object_type;
- ENDIF;
- v_string:='';
- insert_rec(n_line_no,
- v_object_type,
- v_username,
- v_index_name,
- v_string);
- n_line_no:=n_line_no+1;
- ENDIF;
- ENDLOOP;
- CLOSEcur_indxes;
- SELECTCOUNT(*)INTOn_tempFROMuser_indexesWHEREindex_type='LOB';
- IFn_temp>0THEN
- v_string:='';
- insert_rec(n_line_no,
- v_object_type,
- v_username,
- 'LOBINDEX',
- v_string);
- n_line_no:=n_line_no+1;
- v_string:='--ThereissomeLOBindex,andwedon''tlist;';
- insert_rec(n_line_no,
- v_object_type,
- v_username,
- 'LOBINDEX',
- v_string);
- n_line_no:=n_line_no+1;
- v_string:='';
- insert_rec(n_line_no,
- v_object_type,
- v_username,
- 'LOBINDEX',
- v_string);
- n_line_no:=n_line_no+1;
- v_string:='';
- insert_rec(n_line_no,
- v_object_type,
- v_username,
- 'LOBINDEX',
- v_string);
- n_line_no:=n_line_no+1;
- ENDIF;
- COMMIT;
- END;
- PROCEDUREpro_reb_indx_sql(p_v_gen_store_clauseVARCHAR2default'T',
- p_v_rebuild_onlineVARCHAR2default'T',
- p_v_display_prompt_infoVARCHAR2default'T')AS
- CURSORcur_indxesIS
- SELECTindex_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
- FROMuser_indexes
- WHEREindex_type<>'LOB'
- ORDERBYindex_name;
- v_index_nameuser_indexes.index_name%TYPE;
- v_table_owneruser_indexes.table_owner%TYPE;
- v_table_nameuser_indexes.table_name%TYPE;
- v_index_typeuser_indexes.index_type%TYPE;
- v_uniquenessuser_indexes.uniqueness%TYPE;
- v_tablespace_nameuser_indexes.tablespace_name%TYPE;
- n_ini_transuser_indexes.ini_trans%TYPE;
- n_max_transuser_indexes.max_trans%TYPE;
- n_initial_extentuser_indexes.initial_extent%TYPE;
- n_next_extentuser_indexes.next_extent%TYPE;
- n_min_extentsuser_indexes.min_extents%TYPE;
- n_max_extentsuser_indexes.max_extents%TYPE;
- n_pct_increaseuser_indexes.pct_increase%TYPE;
- n_pct_freeuser_indexes.pct_free%TYPE;
- n_freelistsuser_indexes.freelists%TYPE;
- n_freelist_groupsuser_indexes.freelist_groups%TYPE;
- v_buffer_pooluser_indexes.buffer_pool%TYPE;
- v_loggingVARCHAR2(15);
- lv_column_nameuser_ind_columns.column_name%TYPE;
- b_first_recBOOLEAN;
- v_stringVARCHAR2(800);
- n_line_noNUMBER:=0;
- v_gen_store_clauseVARCHAR2(10);
- v_rebuild_onlineVARCHAR2(10);
- v_display_prompt_infoVARCHAR2(10);
- n_tempNUMBER(10,0);
- v_object_typeVARCHAR2(30);
- v_promptVARCHAR2(30);
- v_usernameVARCHAR2(30);
- PROCEDUREinsert_rec(p_line_noINTEGER,
- p_object_typeVARCHAR2,
- p_user_nameVARCHAR2,
- p_index_nameVARCHAR2,
- p_stringVARCHAR2)IS
- BEGIN
- INSERTINTOtemp_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';
- SELECTusernameINTOv_usernameFROMuser_users;
- DELETEFROMtemp_for_pkg_gen_sql2000_temp
- WHEREobject_type=v_object_type;
- COMMIT;
- n_line_no:=1;
- OPENcur_indxes;
- LOOP
- FETCHcur_indxes
- INTOv_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;
- EXITWHENcur_indxes%NOTFOUND;
- b_first_rec:=TRUE;
- IFupper(p_v_display_prompt_info)='T'THEN
- IFv_rebuild_online='T'THEN
- v_string:=v_prompt||'REBUILDINDEX'||lower(v_index_name)||
- 'ONLINE';
- ELSE
- v_string:=v_prompt||'REBUILDINDEX'||lower(v_index_name);
- ENDIF;
- insert_rec(n_line_no,
- v_object_type,
- v_username,
- v_index_name,
- v_string);
- n_line_no:=n_line_no+1;
- ENDIF;
- IFv_rebuild_online='T'THEN
- v_string:='ALTERINDEX'||lower(v_index_name)||
- 'REBUILDONLINE';
- ELSE
- v_string:='ALTERINDEX'||lower(v_index_name)||'REBUILD';
- ENDIF;
- insert_rec(n_line_no,
- v_object_type,
- v_username,
- v_index_name,
- v_string);
- n_line_no:=n_line_no+1;
- IFupper(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);
- IFn_next_extentISNOTNULLTHEN
- v_string:=v_string||'NEXT'||to_char(n_next_extent);
- ENDIF;
- 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;
- IFn_freelistsISNOTNULLANDn_freelist_groupsISNOTNULLTHEN
- v_string:=chr(9)||'FREELISTS'||to_char(n_freelists)||
- 'FREELISTGROUPS'||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;
- ENDIF;
- 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;
- UPDATEtemp_for_pkg_gen_sql2000_temp
- SETsql_text=sql_text||')'
- WHEREline_no=n_line_no-1
- ANDobject_type=v_object_type;
- ENDIF;
- UPDATEtemp_for_pkg_gen_sql2000_temp
- SETsql_text=sql_text||';'
- WHEREline_no=n_line_no-1
- ANDobject_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;
- ENDLOOP;
- CLOSEcur_indxes;
- SELECTCOUNT(*)INTOn_tempFROMuser_indexesWHEREindex_type='LOB';
- IFn_temp>0THEN
- v_string:='';
- insert_rec(n_line_no,
- v_object_type,
- v_username,
- 'LOBINDEX',
- v_string);
- n_line_no:=n_line_no+1;
- v_string:='--ThereissomeLOBindex,andwedon''tlist;';
- insert_rec(n_line_no,
- v_object_type,
- v_username,
- 'LOBINDEX',
- v_string);
- n_line_no:=n_line_no+1;
- v_string:='';
- insert_rec(n_line_no,
- v_object_type,
- v_username,
- 'LOBINDEX',
- v_string);
- n_line_no:=n_line_no+1;
- v_string:='';
- insert_rec(n_line_no,
- v_object_type,
- v_username,
- 'LOBINDEX',
- v_string);
- n_line_no:=n_line_no+1;
- ENDIF;
- COMMIT;
- END;
- PROCEDUREpro_view_sql(p_v_gen_drop_sqlVARCHAR2default'T',
- p_v_gen_create_sqlVARCHAR2default'T',
- p_v_display_prompt_infoVARCHAR2default'T')AS
- CURSORcur_viewsIS
- selectview_name,textfromuser_viewsorderbyview_name;
- CURSORcur_cols(v_nameVARCHAR2)IS
- SELECTtable_name,
- column_name,
- data_type,
- data_length,
- data_precision,
- data_scale,
- nullable,
- data_default
- FROMuser_tab_columns
- WHEREtable_name=v_name
- ORDERBYcolumn_id;
- v_usernameVARCHAR2(30);
- v_view_nameVARCHAR2(100);
- v_col_namesVARCHAR2(2000);
- v_textVARCHAR2(30000);
- v_sqlVARCHAR2(30000);
- v_sql_tempVARCHAR2(30000);
- n_line_noNUMBER(10,0);
- n38_countNUMBER(38,0);
- n_positionNUMBER(38,0);
- v_object_typeVARCHAR2(30);
- v_promptVARCHAR2(30);
- PROCEDUREinsert_rec(p_line_noINTEGER,
- p_object_typeVARCHAR2,
- p_user_nameVARCHAR2,
- p_view_nameVARCHAR2,
- p_stringVARCHAR2)IS
- BEGIN
- INSERTINTOtemp_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';
- SELECTusernameINTOv_usernameFROMuser_users;
- DELETEtemp_for_pkg_gen_sql4000_tempWHEREobject_type=v_object_type;
- COMMIT;
- n_line_no:=1;
- OPENcur_views;
- LOOP
- FETCHcur_views
- INTOv_view_name,v_text;
- EXITWHENcur_views%NOTFOUND;
- IFupper(p_v_gen_drop_sql)='T'THEN
- IFupper(p_v_display_prompt_info)='T'THEN
- v_sql:=v_prompt||'DROPVIEW'||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;
- ENDIF;
- v_sql:='DROPVIEW'||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;
- ENDIF;
- IFupper(p_v_gen_create_sql)='T'THEN
- IFupper(p_v_display_prompt_info)='T'THEN
- v_sql:=v_prompt||'CREATEVIEW'||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;
- ENDIF;
- v_sql:='CREATEORREPLACEVIEW'||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;
- FORcur_cols_recINcur_cols(v_view_name)LOOP
- v_col_names:=v_col_names||cur_cols_rec.column_name||',';
- n38_count:=n38_count+1;
- IFMOD(n38_count,5)=0THEN
- 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:='';
- ENDIF;
- ENDLOOP;
- IFlength(v_col_names)>2THEN
- 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
- UPDATEtemp_for_pkg_gen_sql4000_temp
- SETsql_text=substr(sql_text,1,length(sql_text)-2)
- WHEREline_no=n_line_no-1
- ANDobject_type=v_object_type;
- ENDIF;
- 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;
- IFlength(v_sql)>3800THEN
- WHILElength(v_sql)>3800LOOP
- 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);
- ENDLOOP;
- 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);
- ENDIF;
- n_line_no:=n_line_no+1;
- UPDATEtemp_for_pkg_gen_sql4000_temp
- SETsql_text=sql_text||';'
- WHEREline_no=n_line_no-1
- ANDobject_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;
- ENDIF;
- ENDLOOP;
- CLOSEcur_views;
- COMMIT;
- END;
- PROCEDUREpro_seq_max_val_sql(p_v_gen_drop_sqlVARCHAR2default'T',
- p_v_gen_create_sqlVARCHAR2default'T',
- p_v_display_prompt_infoVARCHAR2default'T')AS
- v_sqlVARCHAR2(500);
- n_max_idNUMBER(38,0);
- v_max_valVARCHAR2(1000);
- CURSORcur_etl_dataIS
- SELECTtable_nameFROMuser_tables;
- rec_etl_datacur_etl_data%rowtype;
- typeref_curisREFCURSOR;--定义一个ref类型的游标
- cur_idref_cur;
- CURSORcur_cols(t_nameVARCHAR2)IS
- SELECTcolumn_name,data_type
- FROMuser_tab_columns
- WHEREtable_name=t_name
- ORDERBYcolumn_id;
- rec_col_namecur_cols%rowtype;
- v_sequence_nameVARCHAR2(50);
- n_line_noNUMBER(38,0);
- v_object_typeVARCHAR2(30);
- v_promptVARCHAR2(30);
- v_usernameVARCHAR2(30);
- PROCEDUREinsert_rec(p_line_noINTEGER,
- p_object_typeVARCHAR2,
- p_user_nameVARCHAR2,
- p_sequence_nameVARCHAR2,
- p_stringVARCHAR2)IS
- BEGIN
- INSERTINTOtemp_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';
- SELECTusernameINTOv_usernameFROMuser_users;
- DELETEtemp_for_pkg_gen_sql2000_tempWHEREobject_type=v_object_type;
- COMMIT;
- OPENcur_etl_data;
- LOOP
- FETCHcur_etl_data
- INTOrec_etl_data;
- EXITWHENcur_etl_data%NOTFOUND;
- --得到表的第一个列
- OPENcur_cols(rec_etl_data.table_name);
- LOOP
- FETCHcur_cols
- INTOrec_col_name;
- EXITWHENcur_cols%NOTFOUND;
- EXIT;
- ENDLOOP;
- CLOSEcur_cols;
- IFrec_col_name.data_type='VARCHAR2'OR
- rec_col_name.data_type='VARCHAR'OR
- rec_col_name.data_type='CHAR'THEN
- BEGIN
- v_sql:='SELECTmax(to_NUMBER('||rec_col_name.column_name||
- '))FROM'||rec_etl_data.table_name||'';
- OPENcur_idFORv_sql;
- LOOP
- FETCHcur_id
- INTOv_max_val;
- EXITWHENcur_id%NOTFOUND;
- EXIT;
- ENDLOOP;
- CLOSEcur_id;
- EXCEPTION
- WHENothersTHEN
- IFcur_id%ISOPENTHEN
- CLOSEcur_id;
- ENDIF;
- v_max_val:='-1000';
- END;
- ELSIFrec_col_name.data_type='NUMBER'THEN
- v_sql:='SELECTmax('||rec_col_name.column_name||')FROM'||
- rec_etl_data.table_name||'';
- OPENcur_idFORv_sql;
- LOOP
- FETCHcur_id
- INTOn_max_id;
- EXITWHENcur_id%NOTFOUND;
- EXIT;
- ENDLOOP;
- CLOSEcur_id;
- ENDIF;
- --needmodify,generatesequencename
- v_sequence_name:='seq_'||substr(rec_etl_data.table_name,3)||
- '_id';
- IFp_v_gen_drop_sql='T'THEN
- IFp_v_display_prompt_info='T'THEN
- v_sql:=v_prompt||'DROPSEQUENCE'||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;
- ENDIF;
- v_sql:='DROPSEQUENCE'||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;
- ENDIF;
- IFp_v_gen_create_sql='T'THEN
- IFp_v_display_prompt_info='T'THEN
- v_sql:=v_prompt||'CREATESEQUENCE'||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;
- ENDIF;
- v_sql:='CREATESEQUENCE'||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;
- --handlethestation:treatethesequencevalueasvarcharcolumn(primarykey)
- IFrec_col_name.data_type='VARCHAR2'OR
- rec_col_name.data_type='VARCHAR'OR
- rec_col_name.data_type='CHAR'THEN
- v_sql:='STARTWITH'||
- to_char(to_number(nvl(v_max_val,'1'))+1)||'';
- ELSIFrec_col_name.data_type='NUMBER'THEN
- v_sql:='STARTWITH'||TO_CHAR(nvl(n_max_id,1)+1)||'';
- ENDIF;
- insert_rec(n_line_no,
- v_object_type,
- v_username,
- v_sequence_name,
- v_sql);
- n_line_no:=n_line_no+1;
- v_sql:='INCREMENTBY1';
- insert_rec(n_line_no,
- v_object_type,
- v_username,
- v_sequence_name,
- v_sql);
- n_line_no:=n_line_no+1;
- v_sql:='CACHE100NOCYCLE';
- insert_rec(n_line_no,
- v_object_type,
- v_username,
- v_sequence_name,
- v_sql);
- n_line_no:=n_line_no+1;
- UPDATEtemp_for_pkg_gen_sql2000_temp
- SETsql_text=sql_text||';'
- WHEREline_no=n_line_no-1
- ANDobject_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;
- ENDIF;
- ENDLOOP;
- CLOSEcur_etl_data;
- COMMIT;
- END;
- PROCEDUREpro_seq_next_val_sql(p_v_gen_drop_sqlVARCHAR2default'T',
- p_v_gen_create_sqlVARCHAR2default'T',
- p_v_display_prompt_infoVARCHAR2default'T')AS
- v_sqlVARCHAR2(2000);
- n_max_idNUMBER(38,0);
- v_max_valVARCHAR2(1000);
- CURSORcur_sequenceIS
- SELECT*FROMuser_sequences;
- rec_cur_sequencecur_sequence%rowtype;
- v_sequence_nameVARCHAR2(50);
- n_line_noNUMBER(38,0);
- v_object_typeVARCHAR2(30);
- v_promptVARCHAR2(30);
- v_usernameVARCHAR2(30);
- PROCEDUREinsert_rec(p_line_noINTEGER,
- p_object_typeVARCHAR2,
- p_user_nameVARCHAR2,
- p_sequence_nameVARCHAR2,
- p_stringVARCHAR2)IS
- BEGIN
- INSERTINTOtemp_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';
- SELECTusernameINTOv_usernameFROMuser_users;
- DELETEtemp_for_pkg_gen_sql2000_tempWHEREobject_type=v_object_type;
- COMMIT;
- OPENcur_sequence;
- LOOP
- FETCHcur_sequence
- INTOrec_cur_sequence;
- EXITWHENcur_sequence%NOTFOUND;
- IFp_v_gen_drop_sql='T'THEN
- IFp_v_display_prompt_info='T'THEN
- v_sql:=v_prompt||'DROPSEQUENCE'||
- 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;
- ENDIF;
- v_sql:='DROPSEQUENCE'||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;
- ENDIF;
- IFp_v_gen_create_sql='T'THEN
- IFp_v_display_prompt_info='T'THEN
- v_sql:=v_prompt||'CREATESEQUENCE'||
- 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;
- ENDIF;
- v_sql:='CREATESEQUENCE'||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:='STARTWITH'||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:='INCREMENTBY'||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;
- IFrec_cur_sequence.cache_size=0THEN
- v_sql:='NOCACHE';
- ELSE
- v_sql:='CACHE'||to_char(rec_cur_sequence.cache_size);
- ENDIF;
- IFrec_cur_sequence.cycle_flag='N'THEN
- v_sql:=v_sql||'NOCYCLE';
- ELSE
- v_sql:=v_sql||'CYCLE';
- ENDIF;
- insert_rec(n_line_no,
- v_object_type,
- v_username,
- rec_cur_sequence.sequence_name,
- v_sql);
- n_line_no:=n_line_no+1;
- UPDATEtemp_for_pkg_gen_sql2000_temp
- SETsql_text=sql_text||';'
- WHEREline_no=n_line_no-1
- ANDobject_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;
- ENDIF;
- ENDLOOP;
- CLOSEcur_sequence;
- COMMIT;
- END;
- PROCEDUREpro_seq_init_val_sql(p_v_gen_drop_sqlVARCHAR2default'T',
- p_v_gen_create_sqlVARCHAR2default'T',
- p_v_display_prompt_infoVARCHAR2default'T')AS
- v_sqlVARCHAR2(2000);
- n_max_idNUMBER(38,0);
- v_max_valVARCHAR2(1000);
- CURSORcur_sequenceIS
- SELECT*FROMuser_sequences;
- rec_cur_sequencecur_sequence%rowtype;
- v_sequence_nameVARCHAR2(50);
- n_line_noNUMBER(38,0);
- v_object_typeVARCHAR2(30);
- v_promptVARCHAR2(30);
- v_usernameVARCHAR2(30);
- PROCEDUREinsert_rec(p_line_noINTEGER,
- p_object_typeVARCHAR2,
- p_user_nameVARCHAR2,
- p_sequence_nameVARCHAR2,
- p_stringVARCHAR2)IS
- BEGIN
- INSERTINTOtemp_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';
- SELECTusernameINTOv_usernameFROMuser_users;
- DELETEtemp_for_pkg_gen_sql2000_tempWHEREobject_type=v_object_type;
- COMMIT;
- OPENcur_sequence;
- LOOP
- FETCHcur_sequence
- INTOrec_cur_sequence;
- EXITWHENcur_sequence%NOTFOUND;
- IFp_v_gen_drop_sql='T'THEN
- IFp_v_display_prompt_info='T'THEN
- v_sql:=v_prompt||'DROPSEQUENCE'||
- 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;
- ENDIF;
- v_sql:='DROPSEQUENCE'||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;
- ENDIF;
- IFp_v_gen_create_sql='T'THEN
- IFp_v_display_prompt_info='T'THEN
- v_sql:=v_prompt||'CREATESEQUENCE'||
- 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;
- ENDIF;
- v_sql:='CREATESEQUENCE'||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:='STARTWITH1';
- 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:='INCREMENTBY'||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;
- IFrec_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';
- ENDIF;
- insert_rec(n_line_no,
- v_object_type,
- v_username,
- rec_cur_sequence.sequence_name,
- v_sql);
- n_line_no:=n_line_no+1;
- UPDATEtemp_for_pkg_gen_sql2000_temp
- SETsql_text=sql_text||';'
- WHEREline_no=n_line_no-1
- ANDobject_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;
- ENDIF;
- ENDLOOP;
- CLOSEcur_sequence;
- COMMIT;
- END;
- PROCEDUREpro_synonym_sql(p_v_gen_drop_sqlVARCHAR2default'T',
- p_v_gen_create_sqlVARCHAR2default'T',
- p_v_display_prompt_infoVARCHAR2default'T')AS
- v_sqlVARCHAR2(2000);
- n_max_idNUMBER(38,0);
- v_max_valVARCHAR2(1000);
- v_object_typeVARCHAR2(30);
- v_promptVARCHAR2(30);
- v_usernameVARCHAR2(30);
- CURSORcur_synonymIS
- SELECTsynonym_name,
- 'CREATESYNONYM'||synonym_name||'for'||
- decode(db_link,null,table_owner||'.','')||table_name||
- decode(db_link,null,'','@'||db_link)||';'sql_text
- FROMuser_synonyms;
- rec_cur_synonymcur_synonym%rowtype;
- v_synonym_nameVARCHAR2(50);
- n_line_noNUMBER(38,0);
- PROCEDUREinsert_rec(p_line_noINTEGER,
- p_object_typeVARCHAR2,
- p_user_nameVARCHAR2,
- p_object_nameVARCHAR2,
- p_stringVARCHAR2)IS
- BEGIN
- INSERTINTOtemp_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';
- SELECTusernameINTOv_usernameFROMuser_users;
- DELETEtemp_for_pkg_gen_sql2000_tempWHEREOBJECT_TYPE=v_object_type;
- COMMIT;
- OPENcur_synonym;
- LOOP
- FETCHcur_synonym
- INTOrec_cur_synonym;
- EXITWHENcur_synonym%NOTFOUND;
- IFp_v_gen_drop_sql='T'THEN
- IFp_v_display_prompt_info='T'THEN
- v_sql:=v_prompt||'DROPSYNONYM'||
- 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;
- ENDIF;
- v_sql:='DROPSYNONYM'||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;
- ENDIF;
- IFp_v_gen_create_sql='T'THEN
- IFp_v_display_prompt_info='T'THEN
- v_sql:=v_prompt||'CREATESYNONYM'||
- 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;
- ENDIF;
- 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;
- ENDIF;
- ENDLOOP;
- CLOSEcur_synonym;
- COMMIT;
- END;
- PROCEDUREpro_job_sql(p_v_gen_drop_sqlVARCHAR2default'T',
- p_v_gen_create_sqlVARCHAR2default'T',
- p_v_display_prompt_infoVARCHAR2default'T')AS
- v_sqlVARCHAR2(4000);
- n_max_idNUMBER(38,0);
- v_max_valVARCHAR2(1000);
- v_object_typeVARCHAR2(30);
- v_promptVARCHAR2(30);
- v_usernameVARCHAR2(30);
- v_object_nameVARCHAR2(200);
- CURSORcur_jobIS
- SELECTjobjob_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
- FROMuser_jobs;
- rec_cur_jobcur_job%rowtype;
- v_job_nameVARCHAR2(50);
- n_line_noNUMBER(38,0);
- PROCEDUREinsert_rec(p_line_noINTEGER,
- p_object_typeVARCHAR2,
- p_user_nameVARCHAR2,
- p_object_nameVARCHAR2,
- p_stringVARCHAR2)IS
- BEGIN
- INSERTINTOtemp_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';
- SELECTusernameINTOv_usernameFROMuser_users;
- DELETEtemp_for_pkg_gen_sql4000_tempWHEREOBJECT_TYPE=v_object_type;
- COMMIT;
- OPENcur_job;
- LOOP
- FETCHcur_job
- INTOrec_cur_job;
- EXITWHENcur_job%NOTFOUND;
- IFp_v_gen_drop_sql='T'THEN
- IFp_v_display_prompt_info='T'THEN
- v_sql:=v_prompt||'DROPjob'||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;
- ENDIF;
- v_sql:='execdbms_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;
- ENDIF;
- IFp_v_gen_create_sql='T'THEN
- IFp_v_display_prompt_info='T'THEN
- v_sql:=v_prompt||'CREATEjob'||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;
- ENDIF;
- v_sql:='variablejobnonumber;';
- 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;
- ENDIF;
- ENDLOOP;
- CLOSEcur_job;
- COMMIT;
- END;
- PROCEDUREpro_dl_sql(p_v_gen_drop_sqlVARCHAR2default'T',
- p_v_gen_create_sqlVARCHAR2default'T',
- p_v_display_prompt_infoVARCHAR2default'T')AS
- v_sqlVARCHAR2(2000);
- n_max_idNUMBER(38,0);
- v_max_valVARCHAR2(1000);
- v_object_typeVARCHAR2(30);
- v_promptVARCHAR2(30);
- v_usernameVARCHAR2(30);
- CURSORcur_dlIS
- SELECTdb_link,
- 'CREATEDATABASELINK'||db_link||'CONNECTTO'||
- username||'IDENTIFIEDBY'||password||'USING'''||HOST||
- ''';'sql_text
- FROMuser_db_links;
- rec_cur_dlcur_dl%rowtype;
- v_db_linkVARCHAR2(50);
- n_line_noNUMBER(38,0);
- PROCEDUREinsert_rec(p_line_noINTEGER,
- p_object_typeVARCHAR2,
- p_user_nameVARCHAR2,
- p_object_nameVARCHAR2,
- p_stringVARCHAR2)IS
- BEGIN
- INSERTINTOtemp_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';
- SELECTusernameINTOv_usernameFROMuser_users;
- DELETEtemp_for_pkg_gen_sql2000_tempWHEREOBJECT_TYPE=v_object_type;
- COMMIT;
- OPENcur_dl;
- LOOP
- FETCHcur_dl
- INTOrec_cur_dl;
- EXITWHENcur_dl%NOTFOUND;
- IFp_v_gen_drop_sql='T'THEN
- IFp_v_display_prompt_info='T'THEN
- v_sql:=v_prompt||'DROPDATABASELIKE'||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;
- ENDIF;
- v_sql:='DROPDATABASELIKE'||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;
- ENDIF;
- IFp_v_gen_create_sql='T'THEN
- IFp_v_display_prompt_info='T'THEN
- v_sql:=v_prompt||'CREATEDATABASELINK'||
- 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;
- ENDIF;
- 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;
- ENDIF;
- ENDLOOP;
- CLOSEcur_dl;
- COMMIT;
- END;
- PROCEDUREpro_role_sql(p_v_gen_drop_sqlVARCHAR2default'T',
- p_v_gen_create_sqlVARCHAR2default'T',
- p_v_display_prompt_infoVARCHAR2default'T')AS
- v_sqlVARCHAR2(2000);
- v_optionVARCHAR2(200);
- n_max_idNUMBER(38,0);
- v_max_valVARCHAR2(1000);
- v_object_typeVARCHAR2(30);
- v_promptVARCHAR2(30);
- v_usernameVARCHAR2(30);
- CURSORcur_roleIS
- selectgranted_rolerolefromuser_role_privs;
- rec_cur_rolecur_role%rowtype;
- CURSORcur_role_pris(c_role_nameVARCHAR2)IS
- SELECTtype,
- role,
- owner,
- table_name,
- column_name,
- privilege,
- grantable
- FROM(SELECT'TAB'type,
- role,
- owner,
- table_name,
- column_name,
- privilege,
- grantable
- FROMrole_tab_privs
- WHEREroleNOTIN('CONNECT','RESOURCE','DBA')
- UNION
- SELECT'SYS'type,
- role,
- ''owner,
- ''table_name,
- ''column_name,
- privilege,
- admin_optiongrantable
- FROMrole_sys_privs
- WHEREroleNOTIN('CONNECT','RESOURCE','DBA'))
- whererole=upper(c_role_name);
- rec_cur_role_priscur_role_pris%rowtype;
- v_roleVARCHAR2(50);
- n_line_noNUMBER(38,0);
- PROCEDUREinsert_rec(p_line_noINTEGER,
- p_object_typeVARCHAR2,
- p_user_nameVARCHAR2,
- p_object_nameVARCHAR2,
- p_stringVARCHAR2)IS
- BEGIN
- INSERTINTOtemp_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';
- SELECTusernameINTOv_usernameFROMuser_users;
- DELETEtemp_for_pkg_gen_sql2000_tempWHEREOBJECT_TYPE=v_object_type;
- COMMIT;
- OPENcur_role;
- LOOP
- FETCHcur_role
- INTOrec_cur_role;
- EXITWHENcur_role%NOTFOUND;
- IFp_v_gen_drop_sql='T'THEN
- IFp_v_display_prompt_info='T'THEN
- v_sql:=v_prompt||'DROPROLE'||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;
- ENDIF;
- v_sql:='DROPROLE'||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;
- ENDIF;
- IFp_v_gen_create_sql='T'THEN
- IFp_v_display_prompt_info='T'THEN
- v_sql:=v_prompt||'CREATEROLE'||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;
- ENDIF;
- v_sql:='CREATEROLE'||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||'GRANTPRISTOROLE:'||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;
- OPENcur_role_pris(rec_cur_role.role);
- LOOP
- FETCHcur_role_pris
- INTOrec_cur_role_pris;
- EXITWHENcur_role_pris%NOTFOUND;
- IFrec_cur_role_pris.type='SYS'THEN
- IFrec_cur_role_pris.grantable='NO'THEN
- v_option:='';
- ELSE
- v_option:='WITHADMINOPTION';
- ENDIF;
- 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
- IFrec_cur_role_pris.grantable='NO'THEN
- v_option:='';
- ELSE
- v_option:='WITHGRANTOPTION';
- ENDIF;
- IFrec_cur_role_pris.column_nameISNOTNULLTHEN
- 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||';';
- ENDIF;
- insert_rec(n_line_no,
- v_object_type,
- v_username,
- rec_cur_role.role,
- v_sql);
- n_line_no:=n_line_no+1;
- ENDIF;
- ENDLOOP;
- CLOSEcur_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;
- ENDIF;
- ENDLOOP;
- CLOSEcur_role;
- COMMIT;
- END;
- PROCEDUREpro_priv_sql(p_v_gen_drop_sqlVARCHAR2default'T',
- p_v_gen_create_sqlVARCHAR2default'T',
- p_v_display_prompt_infoVARCHAR2default'T')AS
- v_sqlVARCHAR2(2000);
- v_optionVARCHAR2(200);
- n_max_idNUMBER(38,0);
- v_max_valVARCHAR2(1000);
- v_object_typeVARCHAR2(30);
- v_promptVARCHAR2(30);
- v_usernameVARCHAR2(30);
- n_countnumber(10,0);
- CURSORcur_privIS
- SELECTprivilege,
- owner,
- table_name,
- grantee,
- 'GRANT'||privilege||'ON'||owner||'.'||table_name||
- 'TO'||grantee||
- decode(grantable,'NO','','WITHGRANTOPTION')||';'SQL_TEXT
- FROMuser_tab_privs
- WHEREGRANTOR=(SELECTusernameFROMuser_users)
- ORDERBYowner,table_name;
- rec_cur_privcur_priv%rowtype;
- CURSORcur_col_privIS
- SELECTprivilege,
- owner,
- column_name,
- table_name,
- grantee,
- 'GRANT'||privilege||''||column_name||'ON'||owner||'.'||
- table_name||'TO'||grantee||
- decode(grantable,'NO','','WITHGRANTOPTION')||';'SQL_TEXT
- FROMuser_col_privs
- WHEREGRANTOR=(SELECTusernameFROMuser_users)
- ORDERBYowner,table_name;
- rec_cur_col_privcur_col_priv%rowtype;
- CURSORcur_sys_privIS
- SELECTusername,
- privilege,
- 'GRANT'||privilege||'TO'||username||
- decode(admin_option,'NO','','WITHADMINOPTION')||';'SQL_TEXT
- FROMuser_sys_privs
- ORDERBYusername;
- rec_cur_sys_privcur_sys_priv%rowtype;
- v_privVARCHAR2(50);
- n_line_noNUMBER(38,0);
- PROCEDUREinsert_rec(p_line_noINTEGER,
- p_object_typeVARCHAR2,
- p_user_nameVARCHAR2,
- p_object_nameVARCHAR2,
- p_stringVARCHAR2)IS
- BEGIN
- INSERTINTOtemp_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;
- SELECTUSERNAMEINTOv_usernameFROMUSER_USERS;
- DELETEtemp_for_pkg_gen_sql2000_tempWHEREOBJECT_TYPE=v_object_type;
- COMMIT;
- OPENcur_priv;
- LOOP
- FETCHcur_priv
- INTOrec_cur_priv;
- EXITWHENcur_priv%NOTFOUND;
- IFp_v_gen_create_sql='T'THEN
- IFp_v_display_prompt_info='T'THEN
- v_sql:=v_prompt||'GRANTPRIVILEGE:'||
- 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,
- 'tabpriv',
- v_sql);
- n_line_no:=n_line_no+1;
- ENDIF;
- v_sql:=rec_cur_priv.sql_text;
- insert_rec(n_line_no,v_object_type,v_username,'tabpriv',v_sql);
- n_line_no:=n_line_no+1;
- v_sql:='';
- insert_rec(n_line_no,v_object_type,v_username,'tabpriv',v_sql);
- n_line_no:=n_line_no+1;
- ENDIF;
- ENDLOOP;
- CLOSEcur_priv;
- OPENcur_col_priv;
- LOOP
- FETCHcur_col_priv
- INTOrec_cur_col_priv;
- EXITWHENcur_col_priv%NOTFOUND;
- IFn_count=1THEN
- v_sql:='--***********************';
- insert_rec(n_line_no,v_object_type,v_username,'tabpriv',v_sql);
- n_line_no:=n_line_no+1;
- n_count:=n_count+1;
- ENDIF;
- v_sql:='';
- insert_rec(n_line_no,v_object_type,v_username,'tabpriv',v_sql);
- n_line_no:=n_line_no+1;
- IFp_v_display_prompt_info='T'THEN
- v_sql:=v_prompt||'GRANTCOLPRIVILEGE:'||
- 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,'colpriv',v_sql);
- n_line_no:=n_line_no+1;
- ENDIF;
- v_sql:=rec_cur_col_priv.sql_text;
- insert_rec(n_line_no,v_object_type,v_username,'colpriv',v_sql);
- n_line_no:=n_line_no+1;
- v_sql:='';
- insert_rec(n_line_no,v_object_type,v_username,'colpriv',v_sql);
- n_line_no:=n_line_no+1;
- ENDLOOP;
- CLOSEcur_col_priv;
- n_count:=1;
- OPENcur_sys_priv;
- LOOP
- FETCHcur_sys_priv
- INTOrec_cur_sys_priv;
- EXITWHENcur_sys_priv%NOTFOUND;
- IFn_count=1THEN
- v_sql:='';
- insert_rec(n_line_no,v_object_type,v_username,'syspriv',v_sql);
- n_line_no:=n_line_no+1;
- v_sql:='PROMPT***********YoumustthefollowingsqlasauserwithDBApriv,othersyouwillgeterrors!
- ************';
- insert_rec(n_line_no,v_object_type,v_username,'syspriv',v_sql);
- n_line_no:=n_line_no+1;
- v_sql:='PROMPT***********Wecommentthefollowsql!************';
- insert_rec(n_line_no,v_object_type,v_username,'syspriv',v_sql);
- n_line_no:=n_line_no+1;
- v_sql:='';
- insert_rec(n_line_no,v_object_type,v_username,'syspriv',v_sql);
- n_line_no:=n_line_no+1;
- n_count:=n_count+1;
- ENDIF;
- IFp_v_display_prompt_info='T'THEN
- v_sql:=v_prompt||'GRANTSYSTEMPRIVILEGE:'||
- rec_cur_sys_priv.privilege||'TO'||
- rec_cur_sys_priv.username;
- insert_rec(n_line_no,v_object_type,v_username,'syspriv',v_sql);
- n_line_no:=n_line_no+1;
- ENDIF;
- v_sql:='--'||rec_cur_sys_priv.sql_text;
- insert_rec(n_line_no,v_object_type,v_username,'syspriv',v_sql);
- n_line_no:=n_line_no+1;
- v_sql:='';
- insert_rec(n_line_no,v_object_type,v_username,'syspriv',v_sql);
- n_line_no:=n_line_no+1;
- ENDLOOP;
- CLOSEcur_sys_priv;
- COMMIT;
- END;
- PROCEDUREpro_pkgprofuntri_sql(p_v_gen_drop_sqlVARCHAR2default'T',
- p_v_gen_create_sqlVARCHAR2default'T',
- p_v_display_prompt_infoVARCHAR2default'T',
- p_v_separ_fileVARCHAR2default'T',
- p_v_file_pathVARCHAR2default'C:/')AS
- v_sqlVARCHAR2(2000);
- v_object_typeVARCHAR2(30);
- v_promptVARCHAR2(30);
- v_file_pathVARCHAR2(600);
- v_notionchar(1);
- v_usernameVARCHAR2(30);
- CURSORcur_ProFunPkg_nameIS
- SELECTdistincttype,us.name
- FROMuser_sourceus
- WHEREtype<>'PACKAGEBODY'
- ANDus.name<>upper('pkg_gen_user_sql')
- ORDERBYus.type,us.name;
- CURSORcur_ProFunPkg_code(c_obj_nameVARCHAR2,c_obj_typeVARCHAR2)IS
- SELECTline,type,text
- FROMuser_sourceus
- WHERENAME=c_obj_name
- ANDtype=c_obj_type
- ORDERBYtype,line;
- v_object_nameVARCHAR2(50);
- n_line_noNUMBER(38,0);
- PROCEDUREinsert_rec(p_line_noINTEGER,
- p_object_typeVARCHAR2,
- p_user_nameVARCHAR2,
- p_object_nameVARCHAR2,
- p_stringVARCHAR2)IS
- BEGIN
- INSERTINTOtemp_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';
- SELECTusernameINTOv_usernameFROMuser_users;
- --findthenotionbetweenthedictionary
- IFinstr(p_v_file_path,'/')>0THEN
- v_notion:='/';
- ELSE
- v_notion:='/';
- ENDIF;
- IFsubstr(v_file_path,length(v_file_path))<>v_notionTHEN
- v_file_path:=v_file_path||v_notion;
- ENDIF;
- DELETEtemp_for_pkg_gen_sql4000_temp
- WHEREOBJECT_TYPEIN
- ('PACKAGEBODY','PACKAGE','PROCEDURE','FUNCTION',
- 'SEPAR_PROCS','SEPAR_FUNCS','SEPAR_PKG_HEADS',
- 'SEPAR_PKG_BODYS','SEPAR_PKGS','TRIGGER','SEPAR_TRIS');
- COMMIT;
- FORrec_ProFunPkg_nameINcur_ProFunPkg_nameLOOP
- 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;
- IFp_v_gen_drop_sql='T'ANDv_object_type<>'PACKAGEBODY'THEN
- IFp_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;
- ENDIF;
- 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;
- ENDIF;
- IFp_v_gen_create_sql='T'THEN
- IFp_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;
- ENDIF;
- FORrec_ProFunPkg_codeINcur_ProFunPkg_code(rec_ProFunPkg_name.name,
- rec_ProFunPkg_name.type)LOOP
- IFrec_ProFunPkg_code.line=1THEN
- v_sql:='CREATEORREPLACE'||rec_ProFunPkg_code.text;
- ELSE
- v_sql:=rec_ProFunPkg_code.text;
- ENDIF;
- insert_rec(n_line_no,
- v_object_type,
- v_username,
- rec_ProFunPkg_name.name,
- v_sql);
- n_line_no:=n_line_no+1;
- ENDLOOP;
- 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';
- IFv_object_type='PROCEDURE'THEN
- insert_rec(n_line_no,
- v_object_type,
- v_username,
- 'START_PROCS',
- v_sql);
- ELSIFv_object_type='FUNCTION'THEN
- insert_rec(n_line_no,
- v_object_type,
- v_username,
- 'START_FUNCS',
- v_sql);
- ELSIFv_object_type='PACKAGE'orv_object_type='PACKAGEBODY'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);
- ELSIFv_object_type='TRIGGER'THEN
- insert_rec(n_line_no,
- v_object_type,
- v_username,
- 'START_TRIS',
- v_sql);
- ELSIFv_object_type='TYPE'orv_object_type='TYPEBODY'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);
- ENDIF;
- 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;
- IFrec_ProFunPkg_name.type='PACKAGE'THEN
- FORrec_ProFunPkg_codeINcur_ProFunPkg_code(rec_ProFunPkg_name.name,
- rec_ProFunPkg_name.type||
- 'BODY')LOOP
- IFrec_ProFunPkg_code.line=1THEN
- v_sql:='CREATEORREPLACE'||rec_ProFunPkg_code.text;
- ELSE
- v_sql:=rec_ProFunPkg_code.text;
- ENDIF;
- 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;
- ENDLOOP;
- 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;
- ENDIF;
- 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;
- ENDIF;
- IFv_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:='SELECTrtrim(sql_text)FROMtemp_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:='WHEREOBJECT_TYPE=''PROCEDURE''ANDOBJECT_NAME='''||
- rec_ProFunPkg_name.name||'''ORDERBYline_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:='spooloff';
- 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;
- ELSIFv_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:='SELECTrtrim(sql_text)FROMtemp_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:='WHEREOBJECT_TYPE=''FUNCTION''ANDOBJECT_NAME='''||
- rec_ProFunPkg_name.name||'''ORDERBYline_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:='spooloff';
- 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;
- ELSIFv_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:='SELECTrtrim(sql_text)FROMtemp_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:='WHEREOBJECT_TYPE=''TRIGGER''ANDOBJECT_NAME='''||
- rec_ProFunPkg_name.name||'''ORDERBYline_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:='spooloff';
- 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;
- ELSIFv_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:='SELECTrtrim(sql_text)FROMtemp_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:='WHEREOBJECT_TYPE=''PACKAGE''ANDOBJECT_NAME='''||
- rec_ProFunPkg_name.name||'''ORDERBYline_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:='spooloff';
- 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:='SELECTrtrim(sql_text)FROMtemp_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:='WHEREOBJECT_TYPE=''PACKAGEBODY''ANDOBJECT_NAME='''||
- rec_ProFunPkg_name.name||'''ORDERBYline_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:='spooloff;';
- 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;
- --thepackageheadandpackagebodyallowinthesamefile
- 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:='SELECTrtrim(sql_text)FROMtemp_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:='WHEREOBJECT_TYPElike''%PACKAGE%''ANDOBJECT_NAME='''||
- rec_ProFunPkg_name.name||'''ORDERBYline_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:='spooloff;';
- 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;
- ENDIF;
- ENDLOOP;
- --生成批量运行生成各个文件的批文件
- 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:='SELECTrtrim(sql_text)FROMtemp_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:='WHEREOBJECT_TYPE=''PROCEDURE''ANDOBJECT_NAME=''START_PROCS''ORDERBYline_no;';
- insert_rec(n_line_no,'SEPAR_PROCS',v_username,'SEPAR_PROCS',v_sql);
- n_line_no:=n_line_no+1;
- v_sql:='spooloff';
- 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:='SELECTrtrim(sql_text)FROMtemp_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:='WHEREOBJECT_TYPE=''FUNCTION''ANDOBJECT_NAME=''START_FUNCS''ORDERBYline_no;';
- insert_rec(n_line_no,'SEPAR_FUNCS',v_username,'SEPAR_FUNCS',v_sql);
- n_line_no:=n_line_no+1;
- v_sql:='spooloff';
- 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:='SELECTrtrim(sql_text)FROMtemp_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:='WHEREOBJECT_TYPE=''TRIGGER''ANDOBJECT_NAME=''SEPAR_TRIS''ORDERBYline_no;';
- insert_rec(n_line_no,'SEPAR_TRIS',v_username,'SEPAR_TRIS',v_sql);
- n_line_no:=n_line_no+1;
- v_sql:='spooloff';
- 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:='SELECTrtrim(sql_text)FROMtemp_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:='WHEREOBJECT_TYPE=''PACKAGE''ANDOBJECT_NAME=''START_PKG_HS''ORDERBYline_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:='spooloff';
- 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:='SELECTrtrim(sql_text)FROMtemp_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:='WHEREOBJECT_TYPE=''PACKAGE''ANDOBJECT_NAME=''START_PKG_BS''ORDERBYline_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:='spooloff';
- 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:='SELECTrtrim(sql_text)FROMtemp_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:='WHEREOBJECT_TYPE=''PACKAGE''ANDOBJECT_NAME=''START_PKGS''ORDERBYline_no;';
- insert_rec(n_line_no,'SEPAR_PKGS',v_username,'SEPAR_PKGS',v_sql);
- n_line_no:=n_line_no+1;
- v_sql:='spooloff';
- 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;
- ENDpkg_gen_user_sql;
- /
- showerr
- setechooff
- setfeedbackoff
- setnewpagenone
- setpagesize0
- setverifyoff
- setpagesize0
- settermoff
- settrimson
- setlinesize5005
- setheadingoff
- settimingoff
- setverifyoff
- setnumwidth38
- --生成start
- execpkg_gen_user_sql.pro_gen_start_sql('&&file_dic')
- spool&&file_dic/start_all.sql
- SELECTrtrim(sql_text)
- FROMtemp_for_pkg_gen_sql2000_temp
- WHEREOBJECT_TYPE='START_SQL'
- ORDERBYline_no;
- spooloff
- --生成创建表的sql语句
- execpkg_gen_user_sql.pro_tab_sql_tab8('F','T','F','T');
- spool&&file_dic/cre_tables.sql
- SELECTrtrim(sql_text)
- FROMtemp_for_pkg_gen_sql2000_temp
- WHEREOBJECT_TYPE='TABLE_8'
- ORDERBYline_no;
- spooloff
- --生成创建索引的sql语句
- execpkg_gen_user_sql.pro_indx_sql('F','T','F','T')
- spool&&file_dic/cre_indexes.sql
- SELECTsql_text
- FROMtemp_for_pkg_gen_sql2000_temp
- WHEREOBJECT_TYPE='INDEX'
- ORDERBYline_no;
- spooloff
- --生成创建主键约束的sql语句
- execpkg_gen_user_sql.pro_con_sql('P','F','T','T','T');
- spool&&file_dic/cre_pri_constraint.sql
- SELECTrtrim(sql_text)
- FROMtemp_for_pkg_gen_sql2000_temp
- WHEREOBJECT_TYPE='CONSTRAINT'
- ORDERBYline_no;
- spooloff
- --生成创建出主键约束的其它约束的sql语句
- execpkg_gen_user_sql.pro_con_sql('NOT_PRI','F','T','F','T');
- spool&&file_dic/cre_not_pri_constraint.sql
- SELECTrtrim(sql_text)
- FROMtemp_for_pkg_gen_sql2000_temp
- WHEREOBJECT_TYPE='CONSTRAINT'
- ORDERBYline_no;
- spooloff
- --生成创建所有约束的sql语句
- execpkg_gen_user_sql.pro_con_sql('A','F','T','T','T');
- spool&&file_dic/cre_constraints.sql
- SELECTrtrim(sql_text)
- FROMtemp_for_pkg_gen_sql2000_temp
- WHEREOBJECT_TYPE='CONSTRAINT'
- ORDERBYline_no;
- spooloff
- --生成重建索引的sql语句
- execpkg_gen_user_sql.pro_reb_indx_sql('F','F')
- spool&&file_dic/reb_indexes.sql
- SELECTsql_text
- FROMtemp_for_pkg_gen_sql2000_temp
- WHEREOBJECT_TYPE='REBUILD_INDEX'
- ORDERBYline_no;
- spooloff
- --生成创建视图的sql语句
- execpkg_gen_user_sql.pro_view_sql('F','T','T');
- spool&&file_dic/cre_views.sql
- SELECTsql_text
- FROMtemp_for_pkg_gen_sql4000_temp
- WHEREOBJECT_TYPE='VIEW'
- ORDERBYline_no;
- spooloff
- --生成创建序列的sql语句
- execpkg_gen_user_sql.pro_seq_next_val_sql('F');
- spool&&file_dic/cre_sequences.sql
- SELECTsql_text
- FROMtemp_for_pkg_gen_sql2000_temp
- WHEREOBJECT_TYPE='SEQUENCE'
- ORDERBYline_no;
- spooloff
- --生成创建初始序列的sql语句,每个序列的开始值为1
- execpkg_gen_user_sql.pro_seq_init_val_sql('F');
- spool&&file_dic/cre_sequences_init.sql
- SELECTsql_text
- FROMtemp_for_pkg_gen_sql2000_temp
- WHEREOBJECT_TYPE='SEQUENCE_INIT'
- ORDERBYline_no;
- spooloff
- --生成创建同义词的sql语句
- execpkg_gen_user_sql.pro_synonym_sql('F')
- spool&&file_dic/cre_synonyms.sql
- SELECTrtrim(sql_text)
- FROMtemp_for_pkg_gen_sql2000_temp
- WHEREOBJECT_TYPE='SYNONYM'
- ORDERBYline_no;
- spooloff
- --生成创建job的sql语句
- execpkg_gen_user_sql.pro_job_sql('F')
- spool&&file_dic/cre_jobs.sql
- SELECTrtrim(sql_text)
- FROMtemp_for_pkg_gen_sql4000_temp
- WHEREOBJECT_TYPE='JOB'
- ORDERBYline_no;
- spooloff
- --生成创建数据库链的sql语句
- execpkg_gen_user_sql.pro_dl_sql('F')
- spool&&file_dic/cre_db_links.sql
- SELECTrtrim(sql_text)
- FROMtemp_for_pkg_gen_sql2000_temp
- WHEREOBJECT_TYPE='DL'
- ORDERBYline_no;
- spooloff
- --生成创建角色的sql语句
- execpkg_gen_user_sql.pro_role_sql('F')
- spool&&file_dic/cre_roles.sql
- SELECTrtrim(sql_text)
- FROMtemp_for_pkg_gen_sql2000_temp
- WHEREOBJECT_TYPE='ROLE'
- ORDERBYline_no;
- spooloff
- --生成创建授权的sql语句
- execpkg_gen_user_sql.pro_priv_sql('F')
- spool&&file_dic/cre_privs.sql
- SELECTrtrim(sql_text)
- FROMtemp_for_pkg_gen_sql2000_temp
- WHEREOBJECT_TYPE='PRIV'
- ORDERBYline_no;
- spooloff
- --生成创建存储过程的sql语句,所有存储过程放在一个文件中
- execpkg_gen_user_sql.pro_pkgprofuntri_sql('F','T','T','T','&&file_dic')
- spool&&file_dic/procedures/procedures.sql
- SELECTrtrim(sql_text)
- FROMtemp_for_pkg_gen_sql4000_temp
- WHEREOBJECT_TYPE='PROCEDURE'
- ANDlower(rtrim(sql_text))notlike'@%.sql'
- ORDERBYline_no;
- spooloff
- --生成创建函数的sql语句,所有函数放在一个文件中
- spool&&file_dic/functions/functions.sql
- SELECTrtrim(sql_text)
- FROMtemp_for_pkg_gen_sql4000_temp
- WHEREOBJECT_TYPE='FUNCTION'
- ANDlower(rtrim(sql_text))notlike'@%.sql'
- ORDERBYline_no;
- spooloff
- --生成创建包的sql语句,所有包放在一个文件中
- spool&&file_dic/packages/packages.sql
- SELECTrtrim(sql_text)
- FROMtemp_for_pkg_gen_sql4000_temp
- WHEREOBJECT_TYPElike'%PACKAGE%'
- ANDlower(rtrim(sql_text))notlike'@%.sql'
- ORDERBYline_no;
- spooloff
- --生成创建触发器的sql语句
- spool&&file_dic/triggers/triggers.sql
- SELECTrtrim(sql_text)
- FROMtemp_for_pkg_gen_sql4000_temp
- WHEREOBJECT_TYPE='TRIGGER'
- ORDERBYline_no;
- spooloff
- --生成创建存储过程的sql语句,每个存储过程放在单独的文件中
- spool&&file_dic/temp_sql/separ_pros.sql
- SELECTrtrim(sql_text)
- FROMtemp_for_pkg_gen_sql4000_temp
- WHEREOBJECT_TYPE='SEPAR_PROCS'
- ORDERBYline_no;
- spooloff
- @&&file_dic/temp_sql/separ_pros.sql
- --生成创建函数的sql语句,每个函数放在单独的文件中
- spool&&file_dic/temp_sql/separ_funcs.sql
- SELECTrtrim(sql_text)
- FROMtemp_for_pkg_gen_sql4000_temp
- WHEREOBJECT_TYPE='SEPAR_FUNCS'
- ORDERBYline_no;
- spooloff
- @&&file_dic/temp_sql/separ_funcs.sql
- --生成创建包的sql语句,每个包放在单独的文件中
- spool&&file_dic/temp_sql/separ_pkgs.sql
- SELECTrtrim(sql_text)
- FROMtemp_for_pkg_gen_sql4000_temp
- WHEREOBJECT_TYPElike'%SEPAR_PKGS%'
- ORDERBYline_no;
- spooloff
- @&&file_dic/temp_sql/separ_pkgs.sql
- --生成创建存储过程的sql语句,每个包的声明与包体各放在单独的文件中
- spool&&file_dic/temp_sql/separ_hb_pkgs.sql
- SELECTrtrim(sql_text)
- FROMtemp_for_pkg_gen_sql4000_temp
- WHEREOBJECT_TYPEin('SEPAR_PKG_HEADS','SEPAR_PKG_BODYS')
- ORDERBYobject_name,OBJECT_TYPEdesc,line_no;
- spooloff
- @&&file_dic/temp_sql/separ_hb_pkgs.sql
- --生成创建触发器的sql语句,每个触发器放在单独的文件中
- spool&&file_dic/temp_sql/separ_tris.sql
- SELECTrtrim(sql_text)
- FROMtemp_for_pkg_gen_sql4000_temp
- WHEREOBJECT_TYPE='SEPAR_TRIS'
- ORDERBYline_no;
- spooloff
- @&&file_dic/temp_sql/separ_tris.sql
- setechoon
- setfeedbackon
- setnewpage1
- setpagesize500
- setlinesize80
- setverifyon
- settermon
- settrimson
- setlinesize600
- setheadingon
- settimingoff
- setverifyon
- setnumwidth15
- droptabletemp_for_pkg_gen_sql2000_temp;
- droptabletemp_for_pkg_gen_sql4000_temp;
- droppackagepkg_gen_user_sql;