oracle导出创建用户下各个对象数据结构的sql语句的脚本,包括表、视图、索引、约束等等...

导出创建用户下各个对象数据结构的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:存放生成的临时文件
  1. DEFINEfile_dic=1
  2. CREATETABLEtemp_for_pkg_gen_sql4000_temp
  3. (line_noNUMBER(38,0),
  4. object_typeVARCHAR2(30),
  5. user_nameVARCHAR2(30),
  6. object_nameVARCHAR2(200),
  7. sql_textVARCHAR2(4000)
  8. );
  9. --synonym,job,db_link,role,user_type
  10. CREATETABLEtemp_for_pkg_gen_sql2000_temp
  11. (line_noNUMBER(38,0),
  12. object_typeVARCHAR2(30),
  13. user_nameVARCHAR2(30),
  14. object_nameVARCHAR2(200),
  15. sql_textVARCHAR2(2000)
  16. );
  17. DELETEtemp_for_pkg_gen_sql4000_temp;
  18. DELETEtemp_for_pkg_gen_sql2000_temp;
  19. COMMIT;
  20. CREATEORREPLACEPACKAGEpkg_gen_user_sqlAS
  21. --产生start脚本
  22. PROCEDUREpro_gen_start_sql(p_v_file_pathVARCHAR2default'C:/');
  23. FUNCTIONfun_return_table_name_tab4(p_v_table_nameVARCHAR2,
  24. p_n_col_max_lenNUMBER)RETURNVARCHAR2;
  25. FUNCTIONfun_return_table_name_tab8(p_v_table_nameVARCHAR2,
  26. p_n_col_max_lenNUMBER)RETURNVARCHAR2;
  27. --generatesqlforcreatetables;
  28. PROCEDUREpro_tab_sql_tab4(p_v_gen_drop_sqlVARCHAR2default'T',
  29. p_v_gen_create_sqlVARCHAR2default'T',
  30. p_v_gen_store_clauseVARCHAR2default'T',
  31. p_v_display_prompt_infoVARCHAR2default'T');
  32. PROCEDUREpro_tab_sql_tab8(p_v_gen_drop_sqlVARCHAR2default'T',
  33. p_v_gen_create_sqlVARCHAR2default'T',
  34. p_v_gen_store_clauseVARCHAR2default'T',
  35. p_v_display_prompt_infoVARCHAR2default'T');
  36. PROCEDUREpro_con_sql(p_v_con_typeVARCHAR2default'ALL',
  37. p_v_gen_drop_sqlVARCHAR2default'T',
  38. p_v_gen_create_sqlVARCHAR2default'T',
  39. p_v_gen_null_chkVARCHAR2default'T',
  40. p_v_display_prompt_infoVARCHAR2default'T');
  41. PROCEDUREpro_indx_sql(p_v_gen_drop_sqlVARCHAR2default'T',
  42. p_v_gen_create_sqlVARCHAR2default'T',
  43. p_v_gen_store_clauseVARCHAR2default'T',
  44. p_v_gen_ts_onlyVARCHAR2default'F',
  45. p_v_display_prompt_infoVARCHAR2default'T');
  46. --重建索引
  47. PROCEDUREpro_reb_indx_sql(p_v_gen_store_clauseVARCHAR2default'T',
  48. p_v_rebuild_onlineVARCHAR2default'T',
  49. p_v_display_prompt_infoVARCHAR2default'T');
  50. PROCEDUREpro_view_sql(p_v_gen_drop_sqlVARCHAR2default'T',
  51. p_v_gen_create_sqlVARCHAR2default'T',
  52. p_v_display_prompt_infoVARCHAR2default'T');
  53. PROCEDUREpro_seq_max_val_sql(p_v_gen_drop_sqlVARCHAR2default'T',
  54. p_v_gen_create_sqlVARCHAR2default'T',
  55. p_v_display_prompt_infoVARCHAR2default'T');
  56. PROCEDUREpro_seq_next_val_sql(p_v_gen_drop_sqlVARCHAR2default'T',
  57. p_v_gen_create_sqlVARCHAR2default'T',
  58. p_v_display_prompt_infoVARCHAR2default'T');
  59. PROCEDUREpro_seq_init_val_sql(p_v_gen_drop_sqlVARCHAR2default'T',
  60. p_v_gen_create_sqlVARCHAR2default'T',
  61. p_v_display_prompt_infoVARCHAR2default'T');
  62. PROCEDUREpro_synonym_sql(p_v_gen_drop_sqlVARCHAR2default'T',
  63. p_v_gen_create_sqlVARCHAR2default'T',
  64. p_v_display_prompt_infoVARCHAR2default'T');
  65. PROCEDUREpro_job_sql(p_v_gen_drop_sqlVARCHAR2default'T',
  66. p_v_gen_create_sqlVARCHAR2default'T',
  67. p_v_display_prompt_infoVARCHAR2default'T');
  68. PROCEDUREpro_dl_sql(p_v_gen_drop_sqlVARCHAR2default'T',
  69. p_v_gen_create_sqlVARCHAR2default'T',
  70. p_v_display_prompt_infoVARCHAR2default'T');
  71. PROCEDUREpro_role_sql(p_v_gen_drop_sqlVARCHAR2default'T',
  72. p_v_gen_create_sqlVARCHAR2default'T',
  73. p_v_display_prompt_infoVARCHAR2default'T');
  74. PROCEDUREpro_priv_sql(p_v_gen_drop_sqlVARCHAR2default'T',
  75. p_v_gen_create_sqlVARCHAR2default'T',
  76. p_v_display_prompt_infoVARCHAR2default'T');
  77. PROCEDUREpro_pkgprofuntri_sql(p_v_gen_drop_sqlVARCHAR2default'T',
  78. p_v_gen_create_sqlVARCHAR2default'T',
  79. p_v_display_prompt_infoVARCHAR2default'T',
  80. p_v_separ_fileVARCHAR2default'T',
  81. p_v_file_pathVARCHAR2default'C:/');
  82. ENDpkg_gen_user_sql;
  83. /
  84. showerr
  85. showerr
  86. CREATEORREPLACEPACKAGEBODYpkg_gen_user_sqlAS
  87. PROCEDUREpro_gen_start_sql(p_v_file_pathVARCHAR2default'C:/')AS
  88. v_usernameVARCHAR2(30);
  89. v_object_typeVARCHAR2(30);
  90. n_line_noNUMBER(10,0);
  91. v_sqlVARCHAR2(2000);
  92. v_promptVARCHAR2(30);
  93. v_file_pathVARCHAR2(600);
  94. v_notionchar(1);
  95. PROCEDUREinsert_rec(p_line_noINTEGER,
  96. p_object_typeVARCHAR2,
  97. p_user_nameVARCHAR2,
  98. p_view_nameVARCHAR2,
  99. p_stringVARCHAR2)IS
  100. BEGIN
  101. INSERTINTOtemp_for_pkg_gen_sql2000_temp
  102. (line_no,object_type,user_name,object_name,sql_text)
  103. VALUES
  104. (p_line_no,p_object_type,p_user_name,p_view_name,p_string);
  105. END;
  106. BEGIN
  107. v_object_type:='START_SQL';
  108. v_prompt:='--prompt';
  109. v_file_path:=p_v_file_path;
  110. --findthenotionbetweenthedictionary
  111. IFinstr(p_v_file_path,'/')>0THEN
  112. v_notion:='/';
  113. ELSE
  114. v_notion:='/';
  115. ENDIF;
  116. IFsubstr(v_file_path,length(v_file_path))<>v_notionTHEN
  117. v_file_path:=v_file_path||v_notion;
  118. ENDIF;
  119. SELECTusernameINTOv_usernameFROMuser_users;
  120. DELETEtemp_for_pkg_gen_sql2000_tempWHEREobject_type=v_object_type;
  121. COMMIT;
  122. n_line_no:=1;
  123. v_sql:='@'||v_file_path||'cre_tables.sql';
  124. insert_rec(n_line_no,v_object_type,v_username,v_object_type,v_sql);
  125. n_line_no:=n_line_no+1;
  126. v_sql:='@'||v_file_path||'cre_sequences.sql';
  127. insert_rec(n_line_no,v_object_type,v_username,v_object_type,v_sql);
  128. n_line_no:=n_line_no+1;
  129. v_sql:='@'||v_file_path||'cre_synonyms.sql';
  130. insert_rec(n_line_no,v_object_type,v_username,v_object_type,v_sql);
  131. n_line_no:=n_line_no+1;
  132. v_sql:='@'||v_file_path||'cre_views.sql';
  133. insert_rec(n_line_no,v_object_type,v_username,v_object_type,v_sql);
  134. n_line_no:=n_line_no+1;
  135. v_sql:='@'||v_file_path||'functions/';
  136. insert_rec(n_line_no,v_object_type,v_username,v_object_type,v_sql);
  137. n_line_no:=n_line_no+1;
  138. v_sql:='@'||v_file_path||'procedures/';
  139. insert_rec(n_line_no,v_object_type,v_username,v_object_type,v_sql);
  140. n_line_no:=n_line_no+1;
  141. v_sql:='@'||v_file_path||'packages/';
  142. insert_rec(n_line_no,v_object_type,v_username,v_object_type,v_sql);
  143. n_line_no:=n_line_no+1;
  144. v_sql:='@'||v_file_path||'triggers/';
  145. insert_rec(n_line_no,v_object_type,v_username,v_object_type,v_sql);
  146. n_line_no:=n_line_no+1;
  147. v_sql:='@'||v_file_path||'cre_synonyms.sql';
  148. insert_rec(n_line_no,v_object_type,v_username,v_object_type,v_sql);
  149. n_line_no:=n_line_no+1;
  150. v_sql:='';
  151. insert_rec(n_line_no,v_object_type,v_username,v_object_type,v_sql);
  152. n_line_no:=n_line_no+1;
  153. v_sql:='--*****importdata*****--';
  154. insert_rec(n_line_no,v_object_type,v_username,v_object_type,v_sql);
  155. n_line_no:=n_line_no+1;
  156. v_sql:='';
  157. insert_rec(n_line_no,v_object_type,v_username,v_object_type,v_sql);
  158. n_line_no:=n_line_no+1;
  159. v_sql:='@'||v_file_path||'cre_indexes.sql';
  160. insert_rec(n_line_no,v_object_type,v_username,v_object_type,v_sql);
  161. n_line_no:=n_line_no+1;
  162. v_sql:='@'||v_file_path||'cre_pri_constraint.sql';
  163. insert_rec(n_line_no,v_object_type,v_username,v_object_type,v_sql);
  164. n_line_no:=n_line_no+1;
  165. v_sql:='@'||v_file_path||'cre_not_pri_constraint.sql';
  166. insert_rec(n_line_no,v_object_type,v_username,v_object_type,v_sql);
  167. n_line_no:=n_line_no+1;
  168. v_sql:='@'||v_file_path||'cre_db_links.sql';
  169. insert_rec(n_line_no,v_object_type,v_username,v_object_type,v_sql);
  170. n_line_no:=n_line_no+1;
  171. COMMIT;
  172. END;
  173. FUNCTIONfun_return_table_name_tab4(p_v_table_nameVARCHAR2,
  174. p_n_col_max_lenNUMBER)RETURNVARCHAR2AS
  175. v_table_nameVARCHAR2(100);
  176. v_tempVARCHAR2(100);
  177. n_col_max_lenNUMBER;
  178. BEGIN
  179. v_table_name:=trim(p_v_table_name);
  180. n_col_max_len:=p_n_col_max_len;
  181. v_temp:=v_table_name;
  182. WHILEmod(length(v_temp),4)<>0LOOP
  183. v_temp:=v_temp||'';
  184. ENDLOOP;
  185. IFmod(length(v_table_name),4)<>0THEN
  186. v_table_name:=v_table_name||chr(9);
  187. ENDIF;
  188. WHILElength(v_temp)<n_col_max_lenLOOP
  189. v_table_name:=v_table_name||chr(9);
  190. v_temp:=v_temp||'';
  191. ENDLOOP;
  192. RETURNv_table_name;
  193. END;
  194. FUNCTIONfun_return_table_name_tab8(p_v_table_nameVARCHAR2,
  195. p_n_col_max_lenNUMBER)RETURNVARCHAR2AS
  196. v_table_nameVARCHAR2(100);
  197. v_tempVARCHAR2(100);
  198. n_col_max_lenNUMBER;
  199. BEGIN
  200. v_table_name:=trim(p_v_table_name);
  201. n_col_max_len:=p_n_col_max_len;
  202. v_temp:=v_table_name;
  203. WHILEmod(length(v_temp),8)<>0LOOP
  204. v_temp:=v_temp||'';
  205. ENDLOOP;
  206. IFmod(length(v_table_name),8)<>0THEN
  207. v_table_name:=v_table_name||chr(9);
  208. ENDIF;
  209. WHILElength(v_temp)<n_col_max_lenLOOP
  210. v_table_name:=v_table_name||chr(9);
  211. v_temp:=v_temp||'';
  212. ENDLOOP;
  213. RETURNv_table_name;
  214. END;
  215. PROCEDUREpro_tab_sql_tab4(p_v_gen_drop_sqlVARCHAR2default'T',
  216. p_v_gen_create_sqlVARCHAR2default'T',
  217. p_v_gen_store_clauseVARCHAR2default'T',
  218. p_v_display_prompt_infoVARCHAR2default'T')AS
  219. CURSORcur_tablesis
  220. SELECTtable_name,
  221. tablespace_name,
  222. pct_free,
  223. pct_used,
  224. ini_trans,
  225. max_trans,
  226. initial_extent,
  227. next_extent,
  228. min_extents,
  229. max_extents,
  230. pct_increase,
  231. freelists,
  232. freelist_groups,
  233. buffer_pool,
  234. decode(logging,'YES','LOGGING','NOLOGGING')logging
  235. FROMuser_tables
  236. WHERElower(TABLE_NAME)NOTIN
  237. ('temp_for_pkg_gen_sql2000_temp',
  238. 'temp_for_pkg_gen_sql4000_temp')
  239. ORDERBYtable_name;
  240. CURSORcur_cols(t_nameVARCHAR2)is
  241. SELECTtable_name,
  242. column_name,
  243. data_type,
  244. data_length,
  245. data_precision,
  246. data_scale,
  247. nullable,
  248. data_default
  249. FROMuser_tab_columns
  250. WHEREtable_name=t_name
  251. ORDERBYcolumn_id;
  252. v_tab_nameVARCHAR2(40);
  253. v_tabsp_nameVARCHAR2(40);
  254. n_mpct_freeuser_tables.pct_free%TYPE;
  255. n_mpct_useduser_tables.pct_used%TYPE;
  256. n_mini_transuser_tables.ini_trans%TYPE;
  257. n_mmax_transuser_tables.max_trans%TYPE;
  258. n_mini_extuser_tables.initial_extent%TYPE;
  259. n_mnext_extuser_tables.next_extent%TYPE;
  260. n_mmin_extuser_tables.min_extents%TYPE;
  261. n_mmax_extuser_tables.max_extents%TYPE;
  262. n_mpct_incuser_tables.pct_increase%TYPE;
  263. n_freelistsuser_tables.freelists%TYPE;
  264. n_freelist_groupsuser_tables.freelist_groups%TYPE;
  265. v_buffer_pooluser_tables.buffer_pool%TYPE;
  266. v_loggingVARCHAR2(15);
  267. col_nameVARCHAR2(40);
  268. ctNUMBER:=0;
  269. n_line_noNUMBER:=0;
  270. col_contentVARCHAR2(120);
  271. n_col_max_lenNUMBER(10,0);
  272. v_default_valVARCHAR2(4000);
  273. v_gen_drop_tab_sqlVARCHAR2(10);
  274. v_gen_create_tab_sqlVARCHAR2(10);
  275. v_gen_store_clauseVARCHAR2(10);
  276. v_display_prompt_infoVARCHAR2(10);
  277. v_usernameVARCHAR2(30);
  278. v_sqlVARCHAR2(2000);
  279. n_positionNUMBER(6,0);
  280. v_object_typeVARCHAR2(10);
  281. v_promptVARCHAR2(10);
  282. PROCEDUREinsert_rec(p_line_noINTEGER,
  283. p_object_typeVARCHAR2,
  284. p_user_nameVARCHAR2,
  285. p_object_nameVARCHAR2,
  286. p_stringVARCHAR2)IS
  287. BEGIN
  288. INSERTINTOtemp_for_pkg_gen_sql2000_temp
  289. (line_no,object_type,user_name,object_name,sql_text)
  290. VALUES
  291. (p_line_no,p_object_type,p_user_name,p_object_name,p_string);
  292. END;
  293. BEGIN
  294. v_gen_drop_tab_sql:=p_v_gen_drop_sql;
  295. v_gen_create_tab_sql:=p_v_gen_create_sql;
  296. v_gen_store_clause:=p_v_gen_store_clause;
  297. v_display_prompt_info:=p_v_display_prompt_info;
  298. v_prompt:='--prompt';
  299. v_object_type:='TABLE_4';
  300. n_line_no:=1;
  301. SELECTusernameINTOv_usernameFROMuser_users;
  302. DELETEtemp_for_pkg_gen_sql2000_tempWHEREOBJECT_TYPE=v_object_type;
  303. COMMIT;
  304. FORcur_tables_recINcur_tablesLOOP
  305. v_tab_name:=cur_tables_rec.table_name;
  306. v_tabsp_name:=cur_tables_rec.tablespace_name;
  307. n_mpct_free:=cur_tables_rec.pct_free;
  308. n_mpct_used:=cur_tables_rec.pct_used;
  309. n_mini_trans:=cur_tables_rec.ini_trans;
  310. n_mmax_trans:=cur_tables_rec.max_trans;
  311. n_mini_ext:=cur_tables_rec.initial_extent;
  312. n_mnext_ext:=cur_tables_rec.next_extent;
  313. n_mmin_ext:=cur_tables_rec.min_extents;
  314. n_mmax_ext:=cur_tables_rec.max_extents;
  315. n_mpct_inc:=nvl(cur_tables_rec.pct_increase,0);
  316. n_freelists:=cur_tables_rec.freelists;
  317. n_freelist_groups:=cur_tables_rec.freelist_groups;
  318. v_buffer_pool:=cur_tables_rec.buffer_pool;
  319. v_logging:=cur_tables_rec.logging;
  320. IFv_gen_drop_tab_sql='T'THEN
  321. IFupper(v_display_prompt_info)='T'THEN
  322. v_sql:=v_prompt||'DropTable'||v_tab_name;
  323. insert_rec(n_line_no,
  324. v_object_type,
  325. v_username,
  326. v_tab_name,
  327. v_sql);
  328. n_line_no:=n_line_no+1;
  329. ENDIF;
  330. v_sql:='ALTERTABLE'||v_tab_name||
  331. 'dropprimarykeycascade;';
  332. insert_rec(n_line_no,v_object_type,v_username,v_tab_name,v_sql);
  333. n_line_no:=n_line_no+1;
  334. v_sql:='DROPTABLE'||v_tab_name||'cascadeconstraint;';
  335. insert_rec(n_line_no,v_object_type,v_username,v_tab_name,v_sql);
  336. n_line_no:=n_line_no+1;
  337. v_sql:='';
  338. insert_rec(n_line_no,v_object_type,v_username,v_tab_name,v_sql);
  339. n_line_no:=n_line_no+1;
  340. ENDIF;
  341. IFupper(v_gen_create_tab_sql)='T'THEN
  342. IFupper(v_display_prompt_info)='T'THEN
  343. v_sql:=v_prompt||'CreateTable'||v_tab_name;
  344. insert_rec(n_line_no,
  345. v_object_type,
  346. v_username,
  347. v_tab_name,
  348. v_sql);
  349. n_line_no:=n_line_no+1;
  350. ENDIF;
  351. v_sql:='CREATETABLE'||v_tab_name||'(';
  352. insert_rec(n_line_no,v_object_type,v_username,v_tab_name,v_sql);
  353. n_line_no:=n_line_no+1;
  354. --找到最长的列名的长度
  355. n_col_max_len:=1;
  356. FORcur_cols_recINcur_cols(v_tab_name)LOOP
  357. IFn_col_max_len<length(trim(cur_cols_rec.column_name))THEN
  358. n_col_max_len:=length(trim(cur_cols_rec.column_name));
  359. ENDIF;
  360. ENDLOOP;
  361. ct:=0;
  362. FORcur_cols_recINcur_cols(v_tab_name)LOOP
  363. ct:=ct+1;
  364. v_default_val:=cur_cols_rec.data_default;
  365. v_default_val:=trim(v_default_val);
  366. n_position:=instr(v_default_val,chr(10),-1);
  367. WHILEn_position>0LOOP
  368. IFn_position=length(v_default_val)THEN
  369. v_default_val:=substr(v_default_val,1,n_position-1);
  370. ELSE
  371. v_default_val:=substr(v_default_val,1,n_position-1)||
  372. substr(v_default_val,n_position+1);
  373. ENDIF;
  374. n_position:=instr(v_default_val,chr(10),-1);
  375. ENDLOOP;
  376. n_position:=instr(v_default_val,chr(9),-1);
  377. IFn_position=length(v_default_val)THEN
  378. v_default_val:=substr(v_default_val,1,n_position-1);
  379. ENDIF;
  380. IFct=1THEN
  381. INSERTINTOtemp_for_pkg_gen_sql2000_temp
  382. (line_no,object_type,user_name,object_name,sql_text)
  383. VALUES
  384. (n_line_no,
  385. v_object_type,
  386. v_username,
  387. v_tab_name,
  388. chr(9)||
  389. pkg_gen_user_sql.fun_return_table_name_tab4(trim(cur_cols_rec.column_name),
  390. n_col_max_len)||
  391. chr(9)||trim(cur_cols_rec.data_type)||
  392. decode(cur_cols_rec.data_type,
  393. 'VARCHAR2',
  394. '('||to_char(cur_cols_rec.data_length)||')',
  395. 'VARCHAR',
  396. '('||to_char(cur_cols_rec.data_length)||')',
  397. 'NVARCHAR2',
  398. '('||to_char(cur_cols_rec.data_length)||')',
  399. 'NVARCHAR',
  400. '('||to_char(cur_cols_rec.data_length)||')',
  401. 'CHAR',
  402. '('||to_char(cur_cols_rec.data_length)||')',
  403. 'NCHAR',
  404. '('||to_char(cur_cols_rec.data_length)||')',
  405. 'NUMBER',
  406. decode(cur_cols_rec.data_precision,
  407. null,
  408. '',
  409. '('||to_char(cur_cols_rec.data_precision)||
  410. decode(cur_cols_rec.data_scale,
  411. null,
  412. ')',
  413. ','||to_char(cur_cols_rec.data_scale)||')')),
  414. '')||
  415. decode(cur_cols_rec.nullable,
  416. 'Y',
  417. decode(v_default_val,
  418. null,
  419. ',',
  420. chr(9)||'default'||chr(9)||v_default_val||','),
  421. decode(v_default_val,
  422. null,
  423. chr(9)||'NOTNULL,',
  424. chr(9)||'default'||chr(9)||v_default_val||
  425. chr(9)||chr(9)||'NOTNULL,')));
  426. n_line_no:=n_line_no+1;
  427. ELSE
  428. INSERTINTOtemp_for_pkg_gen_sql2000_temp
  429. (line_no,object_type,user_name,object_name,sql_text)
  430. VALUES
  431. (n_line_no,
  432. v_object_type,
  433. v_username,
  434. v_tab_name,
  435. chr(9)||
  436. pkg_gen_user_sql.fun_return_table_name_tab4(trim(cur_cols_rec.column_name),
  437. n_col_max_len)||
  438. chr(9)||trim(cur_cols_rec.data_type)||
  439. decode(cur_cols_rec.data_type,
  440. 'VARCHAR2',
  441. '('||to_char(cur_cols_rec.data_length)||')',
  442. 'VARCHAR',
  443. '('||to_char(cur_cols_rec.data_length)||')',
  444. 'NVARCHAR2',
  445. '('||to_char(cur_cols_rec.data_length)||')',
  446. 'NVARCHAR',
  447. '('||to_char(cur_cols_rec.data_length)||')',
  448. 'CHAR',
  449. '('||to_char(cur_cols_rec.data_length)||')',
  450. 'NCHAR',
  451. '('||to_char(cur_cols_rec.data_length)||')',
  452. 'NUMBER',
  453. decode(cur_cols_rec.data_precision,
  454. null,
  455. '',
  456. '('||to_char(cur_cols_rec.data_precision)||
  457. decode(cur_cols_rec.data_scale,
  458. null,
  459. ')',
  460. ','||to_char(cur_cols_rec.data_scale)||')')),
  461. '')||
  462. decode(cur_cols_rec.nullable,
  463. 'Y',
  464. decode(v_default_val,
  465. null,
  466. ',',
  467. chr(9)||'default'||chr(9)||v_default_val||','),
  468. decode(v_default_val,
  469. null,
  470. chr(9)||'NOTNULL,',
  471. chr(9)||'default'||chr(9)||v_default_val||
  472. chr(9)||chr(9)||'NOTNULL,')));
  473. n_line_no:=n_line_no+1;
  474. ENDIF;
  475. ENDLOOP;
  476. SELECTrtrim(sql_text)
  477. intocol_content
  478. FROMtemp_for_pkg_gen_sql2000_temp
  479. WHEREline_no=n_line_no-1
  480. ANDobject_type=v_object_type;
  481. col_content:=substr(col_content,1,length(col_content)-1);
  482. UPDATEtemp_for_pkg_gen_sql2000_temp
  483. SETsql_text=col_content
  484. WHEREline_no=n_line_no-1
  485. ANDobject_type=v_object_type;
  486. v_sql:=')';
  487. insert_rec(n_line_no,v_object_type,v_username,v_tab_name,v_sql);
  488. n_line_no:=n_line_no+1;
  489. IFv_gen_store_clause='T'THEN
  490. v_sql:=v_logging;
  491. insert_rec(n_line_no,
  492. v_object_type,
  493. v_username,
  494. v_tab_name,
  495. v_sql);
  496. n_line_no:=n_line_no+1;
  497. v_sql:='TABLESPACE'||v_tabsp_name;
  498. insert_rec(n_line_no,
  499. v_object_type,
  500. v_username,
  501. v_tab_name,
  502. v_sql);
  503. n_line_no:=n_line_no+1;
  504. v_sql:='PCTFREE'||n_mpct_free||chr(9)||'PCTUSED'||
  505. n_mpct_used;
  506. insert_rec(n_line_no,
  507. v_object_type,
  508. v_username,
  509. v_tab_name,
  510. v_sql);
  511. n_line_no:=n_line_no+1;
  512. v_sql:='INITRANS'||n_mini_trans||chr(9)||'MAXTRANS'||
  513. n_mmax_trans;
  514. insert_rec(n_line_no,
  515. v_object_type,
  516. v_username,
  517. v_tab_name,
  518. v_sql);
  519. n_line_no:=n_line_no+1;
  520. v_sql:='STORAGE(';
  521. insert_rec(n_line_no,
  522. v_object_type,
  523. v_username,
  524. v_tab_name,
  525. v_sql);
  526. n_line_no:=n_line_no+1;
  527. v_sql:=chr(9)||'INITIAL'||n_mini_ext;
  528. insert_rec(n_line_no,
  529. v_object_type,
  530. v_username,
  531. v_tab_name,
  532. v_sql);
  533. n_line_no:=n_line_no+1;
  534. IFn_mnext_extISNOTNULLTHEN
  535. UPDATEtemp_for_pkg_gen_sql2000_temp
  536. SETsql_text=sql_text||chr(9)||'NEXT'||
  537. to_char(n_mnext_ext)
  538. WHEREline_no=n_line_no-1
  539. ANDobject_type=v_object_type;
  540. ENDIF;
  541. UPDATEtemp_for_pkg_gen_sql2000_temp
  542. SETsql_text=sql_text||chr(9)||'PCTINCREASE'||
  543. to_char(n_mpct_inc)
  544. WHEREline_no=n_line_no-1
  545. ANDobject_type=v_object_type;
  546. v_sql:=chr(9)||'FREELISTS'||to_char(n_freelists);
  547. insert_rec(n_line_no,
  548. v_object_type,
  549. v_username,
  550. v_tab_name,
  551. v_sql);
  552. n_line_no:=n_line_no+1;
  553. UPDATEtemp_for_pkg_gen_sql2000_temp
  554. SETsql_text=sql_text||chr(9)||'FREELISTGROUPS'||
  555. to_char(n_freelist_groups)
  556. WHEREline_no=n_line_no-1
  557. ANDobject_type=v_object_type;
  558. v_sql:=chr(9)||'BUFFER_POOL'||v_buffer_pool;
  559. insert_rec(n_line_no,
  560. v_object_type,
  561. v_username,
  562. v_tab_name,
  563. v_sql);
  564. n_line_no:=n_line_no+1;
  565. UPDATEtemp_for_pkg_gen_sql2000_temp
  566. SETsql_text=sql_text||');'
  567. WHEREline_no=n_line_no-1
  568. ANDobject_type=v_object_type;
  569. ELSE
  570. UPDATEtemp_for_pkg_gen_sql2000_temp
  571. SETsql_text=sql_text||';'
  572. WHEREline_no=n_line_no-1
  573. ANDobject_type=v_object_type;
  574. ENDIF;
  575. v_sql:='';
  576. insert_rec(n_line_no,v_object_type,v_username,v_tab_name,v_sql);
  577. n_line_no:=n_line_no+1;
  578. ENDIF;
  579. ENDLOOP;
  580. COMMIT;
  581. END;
  582. PROCEDUREpro_tab_sql_tab8(p_v_gen_drop_sqlVARCHAR2default'T',
  583. p_v_gen_create_sqlVARCHAR2default'T',
  584. p_v_gen_store_clauseVARCHAR2default'T',
  585. p_v_display_prompt_infoVARCHAR2default'T')AS
  586. CURSORcur_tablesIS
  587. SELECTtable_name,
  588. tablespace_name,
  589. pct_free,
  590. pct_used,
  591. ini_trans,
  592. max_trans,
  593. initial_extent,
  594. next_extent,
  595. min_extents,
  596. max_extents,
  597. pct_increase,
  598. freelists,
  599. freelist_groups,
  600. buffer_pool,
  601. decode(logging,'YES','LOGGING','NOLOGGING')logging
  602. FROMuser_tables
  603. WHERElower(TABLE_NAME)NOTIN
  604. ('temp_for_pkg_gen_sql2000_temp',
  605. 'temp_for_pkg_gen_sql4000_temp')
  606. ORDERBYtable_name;
  607. CURSORcur_cols(t_nameVARCHAR2)IS
  608. SELECTtable_name,
  609. column_name,
  610. data_type,
  611. data_length,
  612. data_precision,
  613. data_scale,
  614. nullable,
  615. data_default
  616. FROMuser_tab_columns
  617. WHEREtable_name=t_name
  618. ORDERBYcolumn_id;
  619. v_tab_nameVARCHAR2(40);
  620. v_tabsp_nameVARCHAR2(40);
  621. n_mpct_freeuser_tables.pct_free%TYPE;
  622. n_mpct_useduser_tables.pct_used%TYPE;
  623. n_mini_transuser_tables.ini_trans%TYPE;
  624. n_mmax_transuser_tables.max_trans%TYPE;
  625. n_mini_extuser_tables.initial_extent%TYPE;
  626. n_mnext_extuser_tables.next_extent%TYPE;
  627. n_mmin_extuser_tables.min_extents%TYPE;
  628. n_mmax_extuser_tables.max_extents%TYPE;
  629. n_mpct_incuser_tables.pct_increase%TYPE;
  630. n_freelistsuser_tables.freelists%TYPE;
  631. n_freelist_groupsuser_tables.freelist_groups%TYPE;
  632. v_buffer_pooluser_tables.buffer_pool%TYPE;
  633. v_loggingVARCHAR2(15);
  634. col_nameVARCHAR2(40);
  635. ctNUMBER:=0;
  636. n_line_noNUMBER:=0;
  637. col_contentVARCHAR2(120);
  638. n_col_max_lenNUMBER(10,0);
  639. v_default_valVARCHAR2(4000);
  640. v_gen_drop_tab_sqlVARCHAR2(10);
  641. v_gen_create_tab_sqlVARCHAR2(10);
  642. v_gen_store_clauseVARCHAR2(10);
  643. v_display_prompt_infoVARCHAR2(10);
  644. v_usernameVARCHAR2(30);
  645. v_sqlVARCHAR2(2000);
  646. n_positionNUMBER(6,0);
  647. v_object_typeVARCHAR2(10);
  648. v_promptVARCHAR2(10);
  649. PROCEDUREinsert_rec(p_line_noINTEGER,
  650. p_object_typeVARCHAR2,
  651. p_user_nameVARCHAR2,
  652. p_object_nameVARCHAR2,
  653. p_stringVARCHAR2)IS
  654. BEGIN
  655. INSERTINTOtemp_for_pkg_gen_sql2000_temp
  656. (line_no,object_type,user_name,object_name,sql_text)
  657. VALUES
  658. (p_line_no,p_object_type,p_user_name,p_object_name,p_string);
  659. END;
  660. BEGIN
  661. v_gen_drop_tab_sql:=p_v_gen_drop_sql;
  662. v_gen_create_tab_sql:=p_v_gen_create_sql;
  663. v_gen_store_clause:=p_v_gen_store_clause;
  664. v_display_prompt_info:=p_v_display_prompt_info;
  665. v_prompt:='--prompt';
  666. v_object_type:='TABLE_8';
  667. n_line_no:=1;
  668. SELECTusernameINTOv_usernameFROMuser_users;
  669. DELETEtemp_for_pkg_gen_sql2000_tempWHEREOBJECT_TYPE=v_object_type;
  670. COMMIT;
  671. FORcur_tables_recINcur_tablesLOOP
  672. v_tab_name:=cur_tables_rec.table_name;
  673. v_tabsp_name:=cur_tables_rec.tablespace_name;
  674. n_mpct_free:=cur_tables_rec.pct_free;
  675. n_mpct_used:=cur_tables_rec.pct_used;
  676. n_mini_trans:=cur_tables_rec.ini_trans;
  677. n_mmax_trans:=cur_tables_rec.max_trans;
  678. n_mini_ext:=cur_tables_rec.initial_extent;
  679. n_mnext_ext:=cur_tables_rec.next_extent;
  680. n_mmin_ext:=cur_tables_rec.min_extents;
  681. n_mmax_ext:=cur_tables_rec.max_extents;
  682. n_mpct_inc:=nvl(cur_tables_rec.pct_increase,0);
  683. n_freelists:=cur_tables_rec.freelists;
  684. n_freelist_groups:=cur_tables_rec.freelist_groups;
  685. v_buffer_pool:=cur_tables_rec.buffer_pool;
  686. v_logging:=cur_tables_rec.logging;
  687. IFv_gen_drop_tab_sql='T'THEN
  688. IFupper(v_display_prompt_info)='T'THEN
  689. v_sql:=v_prompt||'DropTable'||v_tab_name;
  690. insert_rec(n_line_no,
  691. v_object_type,
  692. v_username,
  693. v_tab_name,
  694. v_sql);
  695. n_line_no:=n_line_no+1;
  696. ENDIF;
  697. v_sql:='ALTERTABLE'||v_tab_name||
  698. 'dropprimarykeycascade;';
  699. insert_rec(n_line_no,v_object_type,v_username,v_tab_name,v_sql);
  700. n_line_no:=n_line_no+1;
  701. v_sql:='DROPTABLE'||v_tab_name||'cascadeconstraint;';
  702. insert_rec(n_line_no,v_object_type,v_username,v_tab_name,v_sql);
  703. n_line_no:=n_line_no+1;
  704. v_sql:='';
  705. insert_rec(n_line_no,v_object_type,v_username,v_tab_name,v_sql);
  706. n_line_no:=n_line_no+1;
  707. ENDIF;
  708. IFupper(v_gen_create_tab_sql)='T'THEN
  709. IFupper(v_display_prompt_info)='T'THEN
  710. v_sql:=v_prompt||'CreateTable'||v_tab_name;
  711. insert_rec(n_line_no,
  712. v_object_type,
  713. v_username,
  714. v_tab_name,
  715. v_sql);
  716. n_line_no:=n_line_no+1;
  717. ENDIF;
  718. v_sql:='CREATETABLE'||v_tab_name||'(';
  719. insert_rec(n_line_no,v_object_type,v_username,v_tab_name,v_sql);
  720. n_line_no:=n_line_no+1;
  721. --找到最长的列名的长度
  722. n_col_max_len:=1;
  723. FORcur_cols_recINcur_cols(v_tab_name)LOOP
  724. IFn_col_max_len<length(trim(cur_cols_rec.column_name))THEN
  725. n_col_max_len:=length(trim(cur_cols_rec.column_name));
  726. ENDIF;
  727. ENDLOOP;
  728. ct:=0;
  729. FORcur_cols_recINcur_cols(v_tab_name)LOOP
  730. ct:=ct+1;
  731. v_default_val:=cur_cols_rec.data_default;
  732. v_default_val:=trim(v_default_val);
  733. n_position:=instr(v_default_val,chr(10),-1);
  734. WHILEn_position>0LOOP
  735. IFn_position=length(v_default_val)THEN
  736. v_default_val:=substr(v_default_val,1,n_position-1);
  737. ELSE
  738. v_default_val:=substr(v_default_val,1,n_position-1)||
  739. substr(v_default_val,n_position+1);
  740. ENDIF;
  741. n_position:=instr(v_default_val,chr(10),-1);
  742. ENDLOOP;
  743. n_position:=instr(v_default_val,chr(9),-1);
  744. IFn_position=length(v_default_val)THEN
  745. v_default_val:=substr(v_default_val,1,n_position-1);
  746. ENDIF;
  747. IFct=1THEN
  748. INSERTINTOtemp_for_pkg_gen_sql2000_temp
  749. (line_no,object_type,user_name,object_name,sql_text)
  750. VALUES
  751. (n_line_no,
  752. v_object_type,
  753. v_username,
  754. v_tab_name,
  755. chr(9)||
  756. pkg_gen_user_sql.fun_return_table_name_tab8(trim(cur_cols_rec.column_name),
  757. n_col_max_len)||
  758. chr(9)||trim(cur_cols_rec.data_type)||
  759. decode(cur_cols_rec.data_type,
  760. 'VARCHAR2',
  761. '('||to_char(cur_cols_rec.data_length)||')',
  762. 'VARCHAR',
  763. '('||to_char(cur_cols_rec.data_length)||')',
  764. 'NVARCHAR2',
  765. '('||to_char(cur_cols_rec.data_length)||')',
  766. 'NVARCHAR',
  767. '('||to_char(cur_cols_rec.data_length)||')',
  768. 'CHAR',
  769. '('||to_char(cur_cols_rec.data_length)||')',
  770. 'NCHAR',
  771. '('||to_char(cur_cols_rec.data_length)||')',
  772. 'NUMBER',
  773. decode(cur_cols_rec.data_precision,
  774. null,
  775. '',
  776. '('||to_char(cur_cols_rec.data_precision)||
  777. decode(cur_cols_rec.data_scale,
  778. null,
  779. ')',
  780. ','||to_char(cur_cols_rec.data_scale)||')')),
  781. '')||
  782. decode(cur_cols_rec.nullable,
  783. 'Y',
  784. decode(v_default_val,
  785. null,
  786. ',',
  787. chr(9)||'default'||chr(9)||v_default_val||','),
  788. decode(v_default_val,
  789. null,
  790. chr(9)||'NOTNULL,',
  791. chr(9)||'default'||chr(9)||v_default_val||
  792. chr(9)||chr(9)||'NOTNULL,')));
  793. n_line_no:=n_line_no+1;
  794. ELSE
  795. INSERTINTOtemp_for_pkg_gen_sql2000_temp
  796. (line_no,object_type,user_name,object_name,sql_text)
  797. VALUES
  798. (n_line_no,
  799. v_object_type,
  800. v_username,
  801. v_tab_name,
  802. chr(9)||
  803. pkg_gen_user_sql.fun_return_table_name_tab8(trim(cur_cols_rec.column_name),
  804. n_col_max_len)||
  805. chr(9)||trim(cur_cols_rec.data_type)||
  806. decode(cur_cols_rec.data_type,
  807. 'VARCHAR2',
  808. '('||to_char(cur_cols_rec.data_length)||')',
  809. 'VARCHAR',
  810. '('||to_char(cur_cols_rec.data_length)||')',
  811. 'NVARCHAR2',
  812. '('||to_char(cur_cols_rec.data_length)||')',
  813. 'NVARCHAR',
  814. '('||to_char(cur_cols_rec.data_length)||')',
  815. 'CHAR',
  816. '('||to_char(cur_cols_rec.data_length)||')',
  817. 'NCHAR',
  818. '('||to_char(cur_cols_rec.data_length)||')',
  819. 'NUMBER',
  820. decode(cur_cols_rec.data_precision,
  821. null,
  822. '',
  823. '('||to_char(cur_cols_rec.data_precision)||
  824. decode(cur_cols_rec.data_scale,
  825. null,
  826. ')',
  827. ','||to_char(cur_cols_rec.data_scale)||')')),
  828. '')||
  829. decode(cur_cols_rec.nullable,
  830. 'Y',
  831. decode(v_default_val,
  832. null,
  833. ',',
  834. chr(9)||'default'||chr(9)||v_default_val||','),
  835. decode(v_default_val,
  836. null,
  837. chr(9)||'NOTNULL,',
  838. chr(9)||'default'||chr(9)||v_default_val||
  839. chr(9)||chr(9)||'NOTNULL,')));
  840. n_line_no:=n_line_no+1;
  841. ENDIF;
  842. ENDLOOP;
  843. SELECTrtrim(sql_text)
  844. intocol_content
  845. FROMtemp_for_pkg_gen_sql2000_temp
  846. WHEREline_no=n_line_no-1
  847. ANDobject_type=v_object_type;
  848. col_content:=substr(col_content,1,length(col_content)-1);
  849. UPDATEtemp_for_pkg_gen_sql2000_temp
  850. SETsql_text=col_content
  851. WHEREline_no=n_line_no-1
  852. ANDobject_type=v_object_type;
  853. v_sql:=')';
  854. insert_rec(n_line_no,v_object_type,v_username,v_tab_name,v_sql);
  855. n_line_no:=n_line_no+1;
  856. IFv_gen_store_clause='T'THEN
  857. v_sql:=v_logging;
  858. insert_rec(n_line_no,
  859. v_object_type,
  860. v_username,
  861. v_tab_name,
  862. v_sql);
  863. n_line_no:=n_line_no+1;
  864. v_sql:='TABLESPACE'||v_tabsp_name;
  865. insert_rec(n_line_no,
  866. v_object_type,
  867. v_username,
  868. v_tab_name,
  869. v_sql);
  870. n_line_no:=n_line_no+1;
  871. v_sql:='PCTFREE'||n_mpct_free||chr(9)||'PCTUSED'||
  872. n_mpct_used;
  873. insert_rec(n_line_no,
  874. v_object_type,
  875. v_username,
  876. v_tab_name,
  877. v_sql);
  878. n_line_no:=n_line_no+1;
  879. v_sql:='INITRANS'||n_mini_trans||chr(9)||'MAXTRANS'||
  880. n_mmax_trans;
  881. insert_rec(n_line_no,
  882. v_object_type,
  883. v_username,
  884. v_tab_name,
  885. v_sql);
  886. n_line_no:=n_line_no+1;
  887. v_sql:='STORAGE(';
  888. insert_rec(n_line_no,
  889. v_object_type,
  890. v_username,
  891. v_tab_name,
  892. v_sql);
  893. n_line_no:=n_line_no+1;
  894. v_sql:=chr(9)||'INITIAL'||n_mini_ext;
  895. insert_rec(n_line_no,
  896. v_object_type,
  897. v_username,
  898. v_tab_name,
  899. v_sql);
  900. n_line_no:=n_line_no+1;
  901. IFn_mnext_extISNOTNULLTHEN
  902. UPDATEtemp_for_pkg_gen_sql2000_temp
  903. SETsql_text=sql_text||chr(9)||'NEXT'||
  904. to_char(n_mnext_ext)
  905. WHEREline_no=n_line_no-1
  906. ANDobject_type=v_object_type;
  907. ENDIF;
  908. UPDATEtemp_for_pkg_gen_sql2000_temp
  909. SETsql_text=sql_text||chr(9)||'PCTINCREASE'||
  910. to_char(n_mpct_inc)
  911. WHEREline_no=n_line_no-1
  912. ANDobject_type=v_object_type;
  913. v_sql:=chr(9)||'FREELISTS'||to_char(n_freelists);
  914. insert_rec(n_line_no,
  915. v_object_type,
  916. v_username,
  917. v_tab_name,
  918. v_sql);
  919. n_line_no:=n_line_no+1;
  920. UPDATEtemp_for_pkg_gen_sql2000_temp
  921. SETsql_text=sql_text||chr(9)||'FREELISTGROUPS'||
  922. to_char(n_freelist_groups)
  923. WHEREline_no=n_line_no-1
  924. ANDobject_type=v_object_type;
  925. v_sql:=chr(9)||'BUFFER_POOL'||v_buffer_pool;
  926. insert_rec(n_line_no,
  927. v_object_type,
  928. v_username,
  929. v_tab_name,
  930. v_sql);
  931. n_line_no:=n_line_no+1;
  932. UPDATEtemp_for_pkg_gen_sql2000_temp
  933. SETsql_text=sql_text||');'
  934. WHEREline_no=n_line_no-1
  935. ANDobject_type=v_object_type;
  936. ELSE
  937. UPDATEtemp_for_pkg_gen_sql2000_temp
  938. SETsql_text=sql_text||';'
  939. WHEREline_no=n_line_no-1
  940. ANDobject_type=v_object_type;
  941. ENDIF;
  942. v_sql:='';
  943. insert_rec(n_line_no,v_object_type,v_username,v_tab_name,v_sql);
  944. n_line_no:=n_line_no+1;
  945. ENDIF;
  946. ENDLOOP;
  947. COMMIT;
  948. END;
  949. PROCEDUREpro_con_sql(p_v_con_typeVARCHAR2default'ALL',
  950. p_v_gen_drop_sqlVARCHAR2default'T',
  951. p_v_gen_create_sqlVARCHAR2default'T',
  952. p_v_gen_null_chkVARCHAR2default'T',
  953. p_v_display_prompt_infoVARCHAR2default'T')AS
  954. CURSORcur_tablesis
  955. SELECTtable_nameFROMuser_tablesORDERBYtable_name;
  956. CURSORcur_con_cols(c_nameVARCHAR2)IS
  957. SELECTcolumn_name
  958. FROMuser_cons_columns
  959. WHEREconstraint_name=c_name
  960. ORDERBYposition;
  961. typeref_curisREFCURSOR;--定义一个ref类型的游标
  962. cur_consref_cur;--定义游标变量
  963. TYPEtype_conISRECORD(
  964. constraint_nameuser_constraints.constraint_name%type,
  965. r_constraint_nameuser_constraints.r_constraint_name%type,
  966. constraint_typeuser_constraints.constraint_type%type,
  967. search_conditionuser_constraints.search_condition%type);
  968. cur_cons_rectype_con;
  969. v_tab_nameVARCHAR2(40);
  970. v_table_nameVARCHAR2(40);
  971. v_typeVARCHAR2(1);
  972. n_ctNUMBER:=0;
  973. n_line_noNUMBER:=0;
  974. v_con_typeVARCHAR2(10);
  975. v_con_sqlVARCHAR2(500);
  976. v_sqlVARCHAR2(2000);
  977. v_gen_drop_con_sqlVARCHAR2(10);
  978. v_display_prompt_infoVARCHAR2(10);
  979. v_gen_create_con_sqlVARCHAR2(10);
  980. v_gen_null_chkVARCHAR2(10);
  981. v_usernameVARCHAR2(30);
  982. v_object_typeVARCHAR2(30);
  983. v_promptVARCHAR2(30);
  984. v_search_conditionVARCHAR2(1000);
  985. PROCEDUREinsert_rec(p_line_noINTEGER,
  986. p_object_typeVARCHAR2,
  987. p_user_nameVARCHAR2,
  988. p_con_nameVARCHAR2,
  989. p_stringVARCHAR2)IS
  990. BEGIN
  991. INSERTINTOtemp_for_pkg_gen_sql2000_temp
  992. (line_no,object_type,user_name,object_name,sql_text)
  993. VALUES
  994. (p_line_no,p_object_type,p_user_name,p_con_name,p_string);
  995. END;
  996. BEGIN
  997. v_con_type:=p_v_con_type;
  998. v_gen_drop_con_sql:=p_v_gen_drop_sql;
  999. v_display_prompt_info:=p_v_display_prompt_info;
  1000. v_gen_create_con_sql:=p_v_gen_create_sql;
  1001. v_gen_null_chk:=p_v_gen_null_chk;
  1002. v_object_type:='CONSTRAINT';
  1003. v_prompt:='--prompt';
  1004. n_line_no:=1;
  1005. SELECTusernameINTOv_usernameFROMuser_users;
  1006. DELETEFROMtemp_for_pkg_gen_sql2000_temp
  1007. WHEREobject_type=v_object_type;
  1008. COMMIT;
  1009. FORcur_tables_recINcur_tablesLOOP
  1010. v_tab_name:=trim(cur_tables_rec.table_name);
  1011. --Gettheconstraintinfoforspecifiedtable
  1012. v_con_sql:='SELECTconstraint_name,r_constraint_name,';
  1013. v_con_sql:=v_con_sql||'constraint_type,search_condition';
  1014. v_con_sql:=v_con_sql||'FROMuser_constraints';
  1015. IFupper(v_con_type)<>'ALL'ANDupper(v_con_type)<>'A'AND
  1016. upper(v_con_type)<>'NOT_PRI'THEN
  1017. v_con_sql:=v_con_sql||'WHEREtable_name='''||v_tab_name||
  1018. '''ANDconstraint_type='''||upper(v_con_type)||
  1019. '''';
  1020. ELSIFupper(v_con_type)='NOT_PRI'THEN
  1021. v_con_sql:=v_con_sql||'WHEREtable_name='''||v_tab_name||
  1022. '''ANDconstraint_type<>''P''';
  1023. ELSE
  1024. v_con_sql:=v_con_sql||'WHEREtable_name='''||v_tab_name||
  1025. '''';
  1026. ENDIF;
  1027. v_con_sql:=v_con_sql||'ORDERBYconstraint_name';
  1028. OPENcur_consFORv_con_sql;
  1029. LOOP
  1030. FETCHcur_cons
  1031. INTOcur_cons_rec;
  1032. EXITWHENcur_cons%NOTFOUND;
  1033. v_type:=cur_cons_rec.constraint_type;
  1034. v_search_condition:=cur_cons_rec.search_condition;
  1035. IFupper(v_gen_drop_con_sql)='T'THEN
  1036. IFv_gen_null_chk='F'ANDv_type='C'AND
  1037. instr(v_search_condition,'ISNOTNULL')>0THEN
  1038. --donull
  1039. v_gen_null_chk:=v_gen_null_chk;
  1040. ELSE
  1041. IFupper(v_display_prompt_info)='T'THEN
  1042. --insertpromptinfo
  1043. INSERTINTOtemp_for_pkg_gen_sql2000_temp
  1044. (line_no,object_type,user_name,object_name,sql_text)
  1045. VALUES
  1046. (n_line_no,
  1047. v_object_type,
  1048. v_username,
  1049. cur_cons_rec.constraint_name,
  1050. v_prompt||'Dropconstraints:'||v_tab_name||'.'||
  1051. trim(cur_cons_rec.constraint_name)||';Type:'||
  1052. decode(v_type,
  1053. 'C',
  1054. 'CHECK',
  1055. 'P',
  1056. 'PRIMARYKEY',
  1057. 'U',
  1058. 'UNIQUE',
  1059. 'R',
  1060. 'FROEIGNRELATION',
  1061. v_type));
  1062. n_line_no:=n_line_no+1;
  1063. ENDIF;
  1064. v_sql:='altertable'||v_tab_name||'dropconstraint'||
  1065. cur_cons_rec.constraint_name||';';
  1066. insert_rec(n_line_no,
  1067. v_object_type,
  1068. v_username,
  1069. cur_cons_rec.constraint_name,
  1070. v_sql);
  1071. n_line_no:=n_line_no+1;
  1072. v_sql:='';
  1073. insert_rec(n_line_no,
  1074. v_object_type,
  1075. v_username,
  1076. cur_cons_rec.constraint_name,
  1077. v_sql);
  1078. n_line_no:=n_line_no+1;
  1079. ENDIF;
  1080. ENDIF;
  1081. IFupper(v_gen_create_con_sql)='T'THEN
  1082. IFv_gen_null_chk='F'ANDv_type='C'AND
  1083. instr(v_search_condition,'ISNOTNULL')>0THEN
  1084. --donull
  1085. v_gen_null_chk:=v_gen_null_chk;
  1086. ELSE
  1087. IFupper(v_display_prompt_info)='T'THEN
  1088. --insertpromptinfo
  1089. INSERTINTOtemp_for_pkg_gen_sql2000_temp
  1090. (line_no,object_type,user_name,object_name,sql_text)
  1091. VALUES
  1092. (n_line_no,
  1093. v_object_type,
  1094. v_username,
  1095. cur_cons_rec.constraint_name,
  1096. v_prompt||'Addconstraints:'||v_tab_name||'.'||
  1097. trim(cur_cons_rec.constraint_name)||';Type:'||
  1098. decode(v_type,
  1099. 'C',
  1100. 'CHECK',
  1101. 'P',
  1102. 'PRIMARYKEY',
  1103. 'U',
  1104. 'UNIQUE',
  1105. 'R',
  1106. 'FROEIGNRELATION',
  1107. v_type));
  1108. n_line_no:=n_line_no+1;
  1109. ENDIF;
  1110. v_sql:='altertable'||v_tab_name||'addconstraint'||
  1111. trim(cur_cons_rec.constraint_name);
  1112. insert_rec(n_line_no,
  1113. v_object_type,
  1114. v_username,
  1115. cur_cons_rec.constraint_name,
  1116. v_sql);
  1117. n_line_no:=n_line_no+1;
  1118. IFv_type='C'THEN
  1119. v_sql:='check('||
  1120. trim(cur_cons_rec.search_condition);
  1121. insert_rec(n_line_no,
  1122. v_object_type,
  1123. v_username,
  1124. cur_cons_rec.constraint_name,
  1125. v_sql);
  1126. n_line_no:=n_line_no+1;
  1127. ENDIF;
  1128. n_ct:=0;
  1129. FORcur_con_cols_recINcur_con_cols(cur_cons_rec.constraint_name)LOOP
  1130. n_ct:=n_ct+1;
  1131. IFn_ct=1THEN
  1132. IFv_type='R'THEN
  1133. v_sql:='foreignkey('||
  1134. trim(cur_con_cols_rec.column_name);
  1135. insert_rec(n_line_no,
  1136. v_object_type,
  1137. v_username,
  1138. cur_cons_rec.constraint_name,
  1139. v_sql);
  1140. n_line_no:=n_line_no+1;
  1141. ENDIF;
  1142. IFv_type='P'THEN
  1143. v_sql:='primarykey('||
  1144. trim(cur_con_cols_rec.column_name);
  1145. insert_rec(n_line_no,
  1146. v_object_type,
  1147. v_username,
  1148. cur_cons_rec.constraint_name,
  1149. v_sql);
  1150. n_line_no:=n_line_no+1;
  1151. ENDIF;
  1152. IFv_type='U'THEN
  1153. v_sql:='unique('||
  1154. trim(cur_con_cols_rec.column_name);
  1155. insert_rec(n_line_no,
  1156. v_object_type,
  1157. v_username,
  1158. cur_cons_rec.constraint_name,
  1159. v_sql);
  1160. n_line_no:=n_line_no+1;
  1161. ENDIF;
  1162. ELSE
  1163. UPDATEtemp_for_pkg_gen_sql2000_temp
  1164. SETsql_text=rtrim(sql_text)||','||
  1165. trim(cur_con_cols_rec.column_name)
  1166. WHEREline_no=n_line_no-1
  1167. ANDobject_type=v_object_type;
  1168. ENDIF;
  1169. ENDLOOP;
  1170. UPDATEtemp_for_pkg_gen_sql2000_temp
  1171. SETsql_text=rtrim(sql_text)||')'
  1172. WHEREline_no=n_line_no-1
  1173. ANDobject_type=v_object_type;
  1174. IFv_type='R'THEN
  1175. SELECTtable_name
  1176. intov_table_name
  1177. FROMuser_constraints
  1178. WHEREconstraint_name=cur_cons_rec.r_constraint_name;
  1179. n_ct:=0;
  1180. FORcur_con_cols_recINcur_con_cols(cur_cons_rec.r_constraint_name)LOOP
  1181. n_ct:=n_ct+1;
  1182. IFn_ct=1THEN
  1183. v_sql:='references'||v_table_name||'(';
  1184. insert_rec(n_line_no,
  1185. v_object_type,
  1186. v_username,
  1187. cur_cons_rec.constraint_name,
  1188. v_sql);
  1189. n_line_no:=n_line_no+1;
  1190. UPDATEtemp_for_pkg_gen_sql2000_temp
  1191. SETsql_text=rtrim(sql_text)||
  1192. trim(cur_con_cols_rec.column_name)
  1193. WHEREline_no=n_line_no-1
  1194. ANDobject_type=v_object_type;
  1195. ELSE
  1196. UPDATEtemp_for_pkg_gen_sql2000_temp
  1197. SETsql_text=rtrim(sql_text)||','||
  1198. trim(cur_con_cols_rec.column_name)
  1199. WHEREline_no=n_line_no-1
  1200. ANDobject_type=v_object_type;
  1201. ENDIF;
  1202. ENDLOOP;
  1203. UPDATEtemp_for_pkg_gen_sql2000_temp
  1204. SETsql_text=rtrim(sql_text)||')'
  1205. WHEREline_no=n_line_no-1
  1206. ANDobject_type=v_object_type;
  1207. ELSE
  1208. IFv_type='P'orv_type='U'THEN
  1209. UPDATEtemp_for_pkg_gen_sql2000_temp
  1210. SETsql_text=rtrim(sql_text)||'USINGINDEX'
  1211. WHEREline_no=n_line_no-1
  1212. ANDobject_type=v_object_type;
  1213. ENDIF;
  1214. ENDIF;
  1215. UPDATEtemp_for_pkg_gen_sql2000_temp
  1216. SETsql_text=sql_text||';'
  1217. WHEREline_no=n_line_no-1
  1218. ANDobject_type=v_object_type;
  1219. v_sql:='';
  1220. insert_rec(n_line_no,
  1221. v_object_type,
  1222. v_username,
  1223. cur_cons_rec.constraint_name,
  1224. v_sql);
  1225. n_line_no:=n_line_no+1;
  1226. ENDIF;
  1227. ENDIF;
  1228. ENDLOOP;
  1229. CLOSEcur_cons;
  1230. ENDLOOP;
  1231. COMMIT;
  1232. END;
  1233. PROCEDUREpro_indx_sql(p_v_gen_drop_sqlVARCHAR2default'T',
  1234. p_v_gen_create_sqlVARCHAR2default'T',
  1235. p_v_gen_store_clauseVARCHAR2default'T',
  1236. p_v_gen_ts_onlyVARCHAR2default'F',
  1237. p_v_display_prompt_infoVARCHAR2default'T')AS
  1238. CURSORcur_indxesIS
  1239. SELECTindex_name,
  1240. table_owner,
  1241. table_name,
  1242. index_type,
  1243. uniqueness,
  1244. tablespace_name,
  1245. ini_trans,
  1246. max_trans,
  1247. initial_extent,
  1248. next_extent,
  1249. min_extents,
  1250. max_extents,
  1251. pct_increase,
  1252. pct_free,
  1253. freelists,
  1254. freelist_groups,
  1255. buffer_pool,
  1256. decode(logging,'YES','LOGGING','NOLOGGING')logging
  1257. FROMuser_indexes
  1258. WHEREindex_type<>'LOB'
  1259. ORDERBYindex_name;
  1260. CURSORcur_cols(c_indVARCHAR2,c_tabVARCHAR2)IS
  1261. SELECTcolumn_name
  1262. FROMuser_ind_columns
  1263. WHEREindex_name=c_ind
  1264. ANDtable_name=c_tab
  1265. ORDERBYcolumn_position;
  1266. CURSORcur_fun_expression(c_indVARCHAR2,c_tabVARCHAR2)IS
  1267. SELECTcolumn_expression
  1268. FROMuser_ind_expressions
  1269. WHEREindex_name=c_ind
  1270. andtable_name=c_tab;
  1271. v_index_nameuser_indexes.index_name%TYPE;
  1272. v_table_owneruser_indexes.table_owner%TYPE;
  1273. v_table_nameuser_indexes.table_name%TYPE;
  1274. v_index_typeuser_indexes.index_type%TYPE;
  1275. v_uniquenessuser_indexes.uniqueness%TYPE;
  1276. v_tablespace_nameuser_indexes.tablespace_name%TYPE;
  1277. n_ini_transuser_indexes.ini_trans%TYPE;
  1278. n_max_transuser_indexes.max_trans%TYPE;
  1279. n_initial_extentuser_indexes.initial_extent%TYPE;
  1280. n_next_extentuser_indexes.next_extent%TYPE;
  1281. n_min_extentsuser_indexes.min_extents%TYPE;
  1282. n_max_extentsuser_indexes.max_extents%TYPE;
  1283. n_pct_increaseuser_indexes.pct_increase%TYPE;
  1284. n_pct_freeuser_indexes.pct_free%TYPE;
  1285. n_freelistsuser_indexes.freelists%TYPE;
  1286. n_freelist_groupsuser_indexes.freelist_groups%TYPE;
  1287. v_buffer_pooluser_indexes.buffer_pool%TYPE;
  1288. v_loggingVARCHAR2(15);
  1289. lv_column_nameuser_ind_columns.column_name%TYPE;
  1290. b_first_recBOOLEAN;
  1291. v_stringVARCHAR2(800);
  1292. n_line_noNUMBER:=0;
  1293. v_gen_drop_indx_sqlVARCHAR2(10);
  1294. v_gen_create_indx_sqlVARCHAR2(10);
  1295. v_gen_store_clauseVARCHAR2(10);
  1296. v_display_prompt_infoVARCHAR2(10);
  1297. v_gen_ts_onlyVARCHAR2(10);
  1298. n_tempNUMBER(10,0);
  1299. v_object_typeVARCHAR2(30);
  1300. v_promptVARCHAR2(30);
  1301. v_usernameVARCHAR2(30);
  1302. procedureinsert_rec(p_line_noINTEGER,
  1303. p_object_typeVARCHAR2,
  1304. p_user_nameVARCHAR2,
  1305. p_index_nameVARCHAR2,
  1306. p_stringVARCHAR2)IS
  1307. BEGIN
  1308. INSERTINTOtemp_for_pkg_gen_sql2000_temp
  1309. (line_no,object_type,user_name,object_name,sql_text)
  1310. VALUES
  1311. (p_line_no,p_object_type,p_user_name,p_index_name,p_string);
  1312. END;
  1313. BEGIN
  1314. v_gen_drop_indx_sql:=p_v_gen_drop_sql;
  1315. v_gen_create_indx_sql:=p_v_gen_create_sql;
  1316. v_gen_store_clause:=p_v_gen_store_clause;
  1317. v_gen_ts_only:=p_v_gen_ts_only;
  1318. v_display_prompt_info:=p_v_display_prompt_info;
  1319. v_object_type:='INDEX';
  1320. v_prompt:='--prompt';
  1321. SELECTusernameINTOv_usernameFROMuser_users;
  1322. DELETEFROMtemp_for_pkg_gen_sql2000_temp
  1323. WHEREobject_type=v_object_type;
  1324. COMMIT;
  1325. n_line_no:=1;
  1326. OPENcur_indxes;
  1327. LOOP
  1328. FETCHcur_indxes
  1329. INTOv_index_name,v_table_owner,v_table_name,v_index_type,v_uniqueness,v_tablespace_name,n_ini_trans,
  1330. n_max_trans,n_initial_extent,n_next_extent,n_min_extents,n_max_extents,n_pct_increase,n_pct_free,n_freelists,
  1331. n_freelist_groups,v_buffer_pool,v_logging;
  1332. EXITWHENcur_indxes%NOTFOUND;
  1333. b_first_rec:=TRUE;
  1334. IFupper(v_gen_drop_indx_sql)='T'THEN
  1335. IFupper(v_display_prompt_info)='T'THEN
  1336. IFv_uniqueness='UNIQUE'ANDv_index_type='NORMAL'THEN
  1337. v_string:=v_prompt||'DROPUNIQUEINDEX'||
  1338. lower(v_index_name);
  1339. ELSIFv_uniqueness<>'UNIQUE'ANDv_index_type='NORMAL'THEN
  1340. v_string:=v_prompt||'DROPINDEX'||lower(v_index_name);
  1341. ELSIFv_index_type='BITMAP'THEN
  1342. v_string:=v_prompt||'DROPBITMAPINDEX'||
  1343. lower(v_index_name);
  1344. ELSIFv_uniqueness='UNIQUE'ANDv_index_type='NORMAL/REV'THEN
  1345. v_string:=v_prompt||'DROPUNIQUE,REVERSEINDEX'||
  1346. lower(v_index_name);
  1347. ELSIFv_uniqueness<>'UNIQUE'ANDv_index_type='NORMAL/REV'THEN
  1348. v_string:=v_prompt||'DROPREVERSEINDEX'||
  1349. lower(v_index_name);
  1350. ELSIFv_uniqueness='UNIQUE'AND
  1351. v_index_type='FUNCTION-BASEDNORMAL'THEN
  1352. v_string:=v_prompt||'DROPUNIQUE,FUNCTIONINDEX'||
  1353. lower(v_index_name);
  1354. ELSIFv_uniqueness<>'UNIQUE'AND
  1355. v_index_type='FUNCTION-BASEDNORMAL'THEN
  1356. v_string:=v_prompt||'DROPFUNCTIONINDEX'||
  1357. lower(v_index_name);
  1358. ENDIF;
  1359. insert_rec(n_line_no,
  1360. v_object_type,
  1361. v_username,
  1362. v_index_name,
  1363. v_string);
  1364. n_line_no:=n_line_no+1;
  1365. ENDIF;
  1366. v_string:='DROPINDEX'||lower(v_index_name)||';';
  1367. insert_rec(n_line_no,
  1368. v_object_type,
  1369. v_username,
  1370. v_index_name,
  1371. v_string);
  1372. n_line_no:=n_line_no+1;
  1373. v_string:='';
  1374. insert_rec(n_line_no,
  1375. v_object_type,
  1376. v_username,
  1377. v_index_name,
  1378. v_string);
  1379. n_line_no:=n_line_no+1;
  1380. ENDIF;
  1381. IFupper(v_gen_create_indx_sql)='T'THEN
  1382. IFupper(p_v_display_prompt_info)='T'THEN
  1383. IFv_uniqueness='UNIQUE'ANDv_index_type='NORMAL'THEN
  1384. v_string:=v_prompt||'CREATEUNIQUEINDEX'||
  1385. lower(v_index_name);
  1386. ELSIFv_uniqueness<>'UNIQUE'ANDv_index_type='NORMAL'THEN
  1387. v_string:=v_prompt||'CREATEINDEX'||lower(v_index_name);
  1388. ELSIFv_index_type='BITMAP'THEN
  1389. v_string:=v_prompt||'CREATEBITMAPINDEX'||
  1390. lower(v_index_name);
  1391. ELSIFv_uniqueness='UNIQUE'ANDv_index_type='NORMAL/REV'THEN
  1392. v_string:=v_prompt||'CREATEUNIQUE,REVERSEINDEX'||
  1393. lower(v_index_name);
  1394. ELSIFv_uniqueness<>'UNIQUE'ANDv_index_type='NORMAL/REV'THEN
  1395. v_string:=v_prompt||'CREATEREVERSEINDEX'||
  1396. lower(v_index_name);
  1397. ELSIFv_uniqueness='UNIQUE'AND
  1398. v_index_type='FUNCTION-BASEDNORMAL'THEN
  1399. v_string:=v_prompt||'CREATEUNIQUE,FUNCTIONINDEX'||
  1400. lower(v_index_name);
  1401. ELSIFv_uniqueness<>'UNIQUE'AND
  1402. v_index_type='FUNCTION-BASEDNORMAL'THEN
  1403. v_string:=v_prompt||'CREATEFUNCTIONINDEX'||
  1404. lower(v_index_name);
  1405. ENDIF;
  1406. insert_rec(n_line_no,
  1407. v_object_type,
  1408. v_username,
  1409. v_index_name,
  1410. v_string);
  1411. n_line_no:=n_line_no+1;
  1412. ENDIF;
  1413. IFv_uniqueness='UNIQUE'ANDv_index_type='NORMAL'THEN
  1414. v_string:='CREATEUNIQUEINDEX'||lower(v_index_name);
  1415. insert_rec(n_line_no,
  1416. v_object_type,
  1417. v_username,
  1418. v_index_name,
  1419. v_string);
  1420. n_line_no:=n_line_no+1;
  1421. ELSIFv_uniqueness<>'UNIQUE'ANDv_index_type='NORMAL'THEN
  1422. v_string:='CREATEINDEX'||lower(v_index_name);
  1423. insert_rec(n_line_no,
  1424. v_object_type,
  1425. v_username,
  1426. v_index_name,
  1427. v_string);
  1428. n_line_no:=n_line_no+1;
  1429. ELSIFv_index_type='BITMAP'THEN
  1430. v_string:='CREATEBITMAPINDEX'||lower(v_index_name);
  1431. insert_rec(n_line_no,
  1432. v_object_type,
  1433. v_username,
  1434. v_index_name,
  1435. v_string);
  1436. n_line_no:=n_line_no+1;
  1437. ELSIFv_uniqueness='UNIQUE'ANDv_index_type='NORMAL/REV'THEN
  1438. v_string:='CREATEUNIQUEINDEX'||lower(v_index_name);
  1439. insert_rec(n_line_no,
  1440. v_object_type,
  1441. v_username,
  1442. v_index_name,
  1443. v_string);
  1444. n_line_no:=n_line_no+1;
  1445. ELSIFv_uniqueness<>'UNIQUE'ANDv_index_type='NORMAL/REV'THEN
  1446. v_string:='CREATEINDEX'||lower(v_index_name);
  1447. insert_rec(n_line_no,
  1448. v_object_type,
  1449. v_username,
  1450. v_index_name,
  1451. v_string);
  1452. n_line_no:=n_line_no+1;
  1453. ELSIFv_uniqueness='UNIQUE'AND
  1454. v_index_type='FUNCTION-BASEDNORMAL'THEN
  1455. v_string:='CREATEUNIQUEINDEX'||lower(v_index_name);
  1456. insert_rec(n_line_no,
  1457. v_object_type,
  1458. v_username,
  1459. v_index_name,
  1460. v_string);
  1461. n_line_no:=n_line_no+1;
  1462. ELSIFv_uniqueness<>'UNIQUE'AND
  1463. v_index_type='FUNCTION-BASEDNORMAL'THEN
  1464. v_string:='CREATEINDEX'||lower(v_index_name);
  1465. insert_rec(n_line_no,
  1466. v_object_type,
  1467. v_username,
  1468. v_index_name,
  1469. v_string);
  1470. n_line_no:=n_line_no+1;
  1471. ENDIF;
  1472. IFv_index_type<>'FUNCTION-BASEDNORMAL'THEN
  1473. OPENcur_cols(v_index_name,v_table_name);
  1474. LOOP
  1475. FETCHcur_cols
  1476. INTOlv_column_name;
  1477. EXITWHENcur_cols%NOTFOUND;
  1478. IF(b_first_rec)THEN
  1479. v_string:=chr(9)||'ON'||lower(v_table_name)||'(';
  1480. b_first_rec:=FALSE;
  1481. ELSE
  1482. v_string:=v_string||',';
  1483. ENDIF;
  1484. v_string:=v_string||lower(lv_column_name);
  1485. ENDLOOP;
  1486. CLOSEcur_cols;
  1487. ELSE
  1488. OPENcur_fun_expression(v_index_name,v_table_name);
  1489. LOOP
  1490. FETCHcur_fun_expression
  1491. INTOlv_column_name;
  1492. EXITWHENcur_fun_expression%NOTFOUND;
  1493. lv_column_name:=replace(lv_column_name,'"','');
  1494. v_string:=chr(9)||'ON'||lower(v_table_name)||'(';
  1495. n_temp:=length(v_string);
  1496. n_temp:=length(chr(9));
  1497. v_string:=v_string||lower(lv_column_name);
  1498. ENDLOOP;
  1499. CLOSEcur_fun_expression;
  1500. ENDIF;
  1501. v_string:=v_string||')';
  1502. insert_rec(n_line_no,
  1503. v_object_type,
  1504. v_username,
  1505. v_index_name,
  1506. v_string);
  1507. n_line_no:=n_line_no+1;
  1508. IFupper(v_gen_store_clause)='T'THEN
  1509. v_string:=null;
  1510. v_string:=v_logging;
  1511. insert_rec(n_line_no,
  1512. v_object_type,
  1513. v_username,
  1514. v_index_name,
  1515. v_string);
  1516. n_line_no:=n_line_no+1;
  1517. v_string:='PCTFREE'||to_char(n_pct_free);
  1518. insert_rec(n_line_no,
  1519. v_object_type,
  1520. v_username,
  1521. v_index_name,
  1522. v_string);
  1523. n_line_no:=n_line_no+1;
  1524. v_string:='INITRANS'||to_char(n_ini_trans)||'MAXTRANS'||
  1525. to_char(n_max_trans);
  1526. insert_rec(n_line_no,
  1527. v_object_type,
  1528. v_username,
  1529. v_index_name,
  1530. v_string);
  1531. n_line_no:=n_line_no+1;
  1532. v_string:='TABLESPACE'||v_tablespace_name||'';
  1533. insert_rec(n_line_no,
  1534. v_object_type,
  1535. v_username,
  1536. v_index_name,
  1537. v_string);
  1538. n_line_no:=n_line_no+1;
  1539. v_string:='STORAGE(';
  1540. insert_rec(n_line_no,
  1541. v_object_type,
  1542. v_username,
  1543. v_index_name,
  1544. v_string);
  1545. n_line_no:=n_line_no+1;
  1546. v_string:=chr(9)||'INITIAL'||to_char(n_initial_extent);
  1547. IFn_next_extentISNOTNULLTHEN
  1548. v_string:=v_string||'NEXT'||to_char(n_next_extent);
  1549. ENDIF;
  1550. insert_rec(n_line_no,
  1551. v_object_type,
  1552. v_username,
  1553. v_index_name,
  1554. v_string);
  1555. n_line_no:=n_line_no+1;
  1556. v_string:=chr(9)||'MINEXTENTS'||to_char(n_min_extents)||
  1557. 'MAXEXTENTS'||to_char(n_max_extents)||
  1558. 'PCTINCREASE'||to_char(nvl(n_pct_increase,0));
  1559. insert_rec(n_line_no,
  1560. v_object_type,
  1561. v_username,
  1562. v_index_name,
  1563. v_string);
  1564. n_line_no:=n_line_no+1;
  1565. v_string:=chr(9)||'FREELISTS'||to_char(n_freelists)||
  1566. 'FREELISTGROUPS'||to_char(n_freelist_groups);
  1567. insert_rec(n_line_no,
  1568. v_object_type,
  1569. v_username,
  1570. v_index_name,
  1571. v_string);
  1572. n_line_no:=n_line_no+1;
  1573. v_string:=chr(9)||'BUFFER_POOL'||v_buffer_pool||'';
  1574. insert_rec(n_line_no,
  1575. v_object_type,
  1576. v_username,
  1577. v_index_name,
  1578. v_string);
  1579. n_line_no:=n_line_no+1;
  1580. UPDATEtemp_for_pkg_gen_sql2000_temp
  1581. SETsql_text=sql_text||')'
  1582. WHEREline_no=n_line_no-1
  1583. ANDobject_type=v_object_type;
  1584. ELSE
  1585. IFupper(v_gen_store_clause)='F'ANDupper(v_gen_ts_only)='T'THEN
  1586. v_string:='TABLESPACE'||v_tablespace_name||'';
  1587. insert_rec(n_line_no,
  1588. v_object_type,
  1589. v_username,
  1590. v_index_name,
  1591. v_string);
  1592. n_line_no:=n_line_no+1;
  1593. ENDIF;
  1594. ENDIF;
  1595. IFv_index_type<>'NORMAL/REV'THEN
  1596. UPDATEtemp_for_pkg_gen_sql2000_temp
  1597. SETsql_text=sql_text||';'
  1598. WHEREline_no=n_line_no-1
  1599. ANDobject_type=v_object_type;
  1600. ELSE
  1601. UPDATEtemp_for_pkg_gen_sql2000_temp
  1602. SETsql_text=sql_text||'REVERSE;'
  1603. WHEREline_no=n_line_no-1
  1604. ANDobject_type=v_object_type;
  1605. ENDIF;
  1606. v_string:='';
  1607. insert_rec(n_line_no,
  1608. v_object_type,
  1609. v_username,
  1610. v_index_name,
  1611. v_string);
  1612. n_line_no:=n_line_no+1;
  1613. ENDIF;
  1614. ENDLOOP;
  1615. CLOSEcur_indxes;
  1616. SELECTCOUNT(*)INTOn_tempFROMuser_indexesWHEREindex_type='LOB';
  1617. IFn_temp>0THEN
  1618. v_string:='';
  1619. insert_rec(n_line_no,
  1620. v_object_type,
  1621. v_username,
  1622. 'LOBINDEX',
  1623. v_string);
  1624. n_line_no:=n_line_no+1;
  1625. v_string:='--ThereissomeLOBindex,andwedon''tlist;';
  1626. insert_rec(n_line_no,
  1627. v_object_type,
  1628. v_username,
  1629. 'LOBINDEX',
  1630. v_string);
  1631. n_line_no:=n_line_no+1;
  1632. v_string:='';
  1633. insert_rec(n_line_no,
  1634. v_object_type,
  1635. v_username,
  1636. 'LOBINDEX',
  1637. v_string);
  1638. n_line_no:=n_line_no+1;
  1639. v_string:='';
  1640. insert_rec(n_line_no,
  1641. v_object_type,
  1642. v_username,
  1643. 'LOBINDEX',
  1644. v_string);
  1645. n_line_no:=n_line_no+1;
  1646. ENDIF;
  1647. COMMIT;
  1648. END;
  1649. PROCEDUREpro_reb_indx_sql(p_v_gen_store_clauseVARCHAR2default'T',
  1650. p_v_rebuild_onlineVARCHAR2default'T',
  1651. p_v_display_prompt_infoVARCHAR2default'T')AS
  1652. CURSORcur_indxesIS
  1653. SELECTindex_name,
  1654. table_owner,
  1655. table_name,
  1656. index_type,
  1657. uniqueness,
  1658. tablespace_name,
  1659. ini_trans,
  1660. max_trans,
  1661. initial_extent,
  1662. next_extent,
  1663. min_extents,
  1664. max_extents,
  1665. pct_increase,
  1666. pct_free,
  1667. freelists,
  1668. freelist_groups,
  1669. buffer_pool,
  1670. decode(logging,'YES','LOGGING','NOLOGGING')logging
  1671. FROMuser_indexes
  1672. WHEREindex_type<>'LOB'
  1673. ORDERBYindex_name;
  1674. v_index_nameuser_indexes.index_name%TYPE;
  1675. v_table_owneruser_indexes.table_owner%TYPE;
  1676. v_table_nameuser_indexes.table_name%TYPE;
  1677. v_index_typeuser_indexes.index_type%TYPE;
  1678. v_uniquenessuser_indexes.uniqueness%TYPE;
  1679. v_tablespace_nameuser_indexes.tablespace_name%TYPE;
  1680. n_ini_transuser_indexes.ini_trans%TYPE;
  1681. n_max_transuser_indexes.max_trans%TYPE;
  1682. n_initial_extentuser_indexes.initial_extent%TYPE;
  1683. n_next_extentuser_indexes.next_extent%TYPE;
  1684. n_min_extentsuser_indexes.min_extents%TYPE;
  1685. n_max_extentsuser_indexes.max_extents%TYPE;
  1686. n_pct_increaseuser_indexes.pct_increase%TYPE;
  1687. n_pct_freeuser_indexes.pct_free%TYPE;
  1688. n_freelistsuser_indexes.freelists%TYPE;
  1689. n_freelist_groupsuser_indexes.freelist_groups%TYPE;
  1690. v_buffer_pooluser_indexes.buffer_pool%TYPE;
  1691. v_loggingVARCHAR2(15);
  1692. lv_column_nameuser_ind_columns.column_name%TYPE;
  1693. b_first_recBOOLEAN;
  1694. v_stringVARCHAR2(800);
  1695. n_line_noNUMBER:=0;
  1696. v_gen_store_clauseVARCHAR2(10);
  1697. v_rebuild_onlineVARCHAR2(10);
  1698. v_display_prompt_infoVARCHAR2(10);
  1699. n_tempNUMBER(10,0);
  1700. v_object_typeVARCHAR2(30);
  1701. v_promptVARCHAR2(30);
  1702. v_usernameVARCHAR2(30);
  1703. PROCEDUREinsert_rec(p_line_noINTEGER,
  1704. p_object_typeVARCHAR2,
  1705. p_user_nameVARCHAR2,
  1706. p_index_nameVARCHAR2,
  1707. p_stringVARCHAR2)IS
  1708. BEGIN
  1709. INSERTINTOtemp_for_pkg_gen_sql2000_temp
  1710. (line_no,object_type,user_name,object_name,sql_text)
  1711. VALUES
  1712. (p_line_no,p_object_type,p_user_name,p_index_name,p_string);
  1713. END;
  1714. BEGIN
  1715. v_gen_store_clause:=p_v_gen_store_clause;
  1716. v_display_prompt_info:=p_v_display_prompt_info;
  1717. v_rebuild_online:=p_v_rebuild_online;
  1718. v_object_type:='REBUILD_INDEX';
  1719. v_prompt:='--prompt';
  1720. SELECTusernameINTOv_usernameFROMuser_users;
  1721. DELETEFROMtemp_for_pkg_gen_sql2000_temp
  1722. WHEREobject_type=v_object_type;
  1723. COMMIT;
  1724. n_line_no:=1;
  1725. OPENcur_indxes;
  1726. LOOP
  1727. FETCHcur_indxes
  1728. INTOv_index_name,v_table_owner,v_table_name,v_index_type,v_uniqueness,v_tablespace_name,n_ini_trans,
  1729. n_max_trans,n_initial_extent,n_next_extent,n_min_extents,n_max_extents,n_pct_increase,n_pct_free,n_freelists,
  1730. n_freelist_groups,v_buffer_pool,v_logging;
  1731. EXITWHENcur_indxes%NOTFOUND;
  1732. b_first_rec:=TRUE;
  1733. IFupper(p_v_display_prompt_info)='T'THEN
  1734. IFv_rebuild_online='T'THEN
  1735. v_string:=v_prompt||'REBUILDINDEX'||lower(v_index_name)||
  1736. 'ONLINE';
  1737. ELSE
  1738. v_string:=v_prompt||'REBUILDINDEX'||lower(v_index_name);
  1739. ENDIF;
  1740. insert_rec(n_line_no,
  1741. v_object_type,
  1742. v_username,
  1743. v_index_name,
  1744. v_string);
  1745. n_line_no:=n_line_no+1;
  1746. ENDIF;
  1747. IFv_rebuild_online='T'THEN
  1748. v_string:='ALTERINDEX'||lower(v_index_name)||
  1749. 'REBUILDONLINE';
  1750. ELSE
  1751. v_string:='ALTERINDEX'||lower(v_index_name)||'REBUILD';
  1752. ENDIF;
  1753. insert_rec(n_line_no,
  1754. v_object_type,
  1755. v_username,
  1756. v_index_name,
  1757. v_string);
  1758. n_line_no:=n_line_no+1;
  1759. IFupper(v_gen_store_clause)='T'THEN
  1760. v_string:=null;
  1761. v_string:=v_logging;
  1762. insert_rec(n_line_no,
  1763. v_object_type,
  1764. v_username,
  1765. v_index_name,
  1766. v_string);
  1767. n_line_no:=n_line_no+1;
  1768. v_string:='PCTFREE'||to_char(n_pct_free);
  1769. insert_rec(n_line_no,
  1770. v_object_type,
  1771. v_username,
  1772. v_index_name,
  1773. v_string);
  1774. n_line_no:=n_line_no+1;
  1775. v_string:='INITRANS'||to_char(n_ini_trans)||'MAXTRANS'||
  1776. to_char(n_max_trans);
  1777. insert_rec(n_line_no,
  1778. v_object_type,
  1779. v_username,
  1780. v_index_name,
  1781. v_string);
  1782. n_line_no:=n_line_no+1;
  1783. v_string:='TABLESPACE'||v_tablespace_name||'';
  1784. insert_rec(n_line_no,
  1785. v_object_type,
  1786. v_username,
  1787. v_index_name,
  1788. v_string);
  1789. n_line_no:=n_line_no+1;
  1790. v_string:='STORAGE(';
  1791. insert_rec(n_line_no,
  1792. v_object_type,
  1793. v_username,
  1794. v_index_name,
  1795. v_string);
  1796. n_line_no:=n_line_no+1;
  1797. v_string:=chr(9)||'INITIAL'||to_char(n_initial_extent);
  1798. IFn_next_extentISNOTNULLTHEN
  1799. v_string:=v_string||'NEXT'||to_char(n_next_extent);
  1800. ENDIF;
  1801. insert_rec(n_line_no,
  1802. v_object_type,
  1803. v_username,
  1804. v_index_name,
  1805. v_string);
  1806. n_line_no:=n_line_no+1;
  1807. v_string:=chr(9)||'MINEXTENTS'||to_char(n_min_extents)||
  1808. 'MAXEXTENTS'||to_char(n_max_extents)||
  1809. 'PCTINCREASE'||to_char(nvl(n_pct_increase,0));
  1810. insert_rec(n_line_no,
  1811. v_object_type,
  1812. v_username,
  1813. v_index_name,
  1814. v_string);
  1815. n_line_no:=n_line_no+1;
  1816. IFn_freelistsISNOTNULLANDn_freelist_groupsISNOTNULLTHEN
  1817. v_string:=chr(9)||'FREELISTS'||to_char(n_freelists)||
  1818. 'FREELISTGROUPS'||to_char(n_freelist_groups);
  1819. insert_rec(n_line_no,
  1820. v_object_type,
  1821. v_username,
  1822. v_index_name,
  1823. v_string);
  1824. n_line_no:=n_line_no+1;
  1825. ENDIF;
  1826. v_string:=chr(9)||'BUFFER_POOL'||v_buffer_pool||'';
  1827. insert_rec(n_line_no,
  1828. v_object_type,
  1829. v_username,
  1830. v_index_name,
  1831. v_string);
  1832. n_line_no:=n_line_no+1;
  1833. UPDATEtemp_for_pkg_gen_sql2000_temp
  1834. SETsql_text=sql_text||')'
  1835. WHEREline_no=n_line_no-1
  1836. ANDobject_type=v_object_type;
  1837. ENDIF;
  1838. UPDATEtemp_for_pkg_gen_sql2000_temp
  1839. SETsql_text=sql_text||';'
  1840. WHEREline_no=n_line_no-1
  1841. ANDobject_type=v_object_type;
  1842. v_string:='';
  1843. insert_rec(n_line_no,
  1844. v_object_type,
  1845. v_username,
  1846. v_index_name,
  1847. v_string);
  1848. n_line_no:=n_line_no+1;
  1849. ENDLOOP;
  1850. CLOSEcur_indxes;
  1851. SELECTCOUNT(*)INTOn_tempFROMuser_indexesWHEREindex_type='LOB';
  1852. IFn_temp>0THEN
  1853. v_string:='';
  1854. insert_rec(n_line_no,
  1855. v_object_type,
  1856. v_username,
  1857. 'LOBINDEX',
  1858. v_string);
  1859. n_line_no:=n_line_no+1;
  1860. v_string:='--ThereissomeLOBindex,andwedon''tlist;';
  1861. insert_rec(n_line_no,
  1862. v_object_type,
  1863. v_username,
  1864. 'LOBINDEX',
  1865. v_string);
  1866. n_line_no:=n_line_no+1;
  1867. v_string:='';
  1868. insert_rec(n_line_no,
  1869. v_object_type,
  1870. v_username,
  1871. 'LOBINDEX',
  1872. v_string);
  1873. n_line_no:=n_line_no+1;
  1874. v_string:='';
  1875. insert_rec(n_line_no,
  1876. v_object_type,
  1877. v_username,
  1878. 'LOBINDEX',
  1879. v_string);
  1880. n_line_no:=n_line_no+1;
  1881. ENDIF;
  1882. COMMIT;
  1883. END;
  1884. PROCEDUREpro_view_sql(p_v_gen_drop_sqlVARCHAR2default'T',
  1885. p_v_gen_create_sqlVARCHAR2default'T',
  1886. p_v_display_prompt_infoVARCHAR2default'T')AS
  1887. CURSORcur_viewsIS
  1888. selectview_name,textfromuser_viewsorderbyview_name;
  1889. CURSORcur_cols(v_nameVARCHAR2)IS
  1890. SELECTtable_name,
  1891. column_name,
  1892. data_type,
  1893. data_length,
  1894. data_precision,
  1895. data_scale,
  1896. nullable,
  1897. data_default
  1898. FROMuser_tab_columns
  1899. WHEREtable_name=v_name
  1900. ORDERBYcolumn_id;
  1901. v_usernameVARCHAR2(30);
  1902. v_view_nameVARCHAR2(100);
  1903. v_col_namesVARCHAR2(2000);
  1904. v_textVARCHAR2(30000);
  1905. v_sqlVARCHAR2(30000);
  1906. v_sql_tempVARCHAR2(30000);
  1907. n_line_noNUMBER(10,0);
  1908. n38_countNUMBER(38,0);
  1909. n_positionNUMBER(38,0);
  1910. v_object_typeVARCHAR2(30);
  1911. v_promptVARCHAR2(30);
  1912. PROCEDUREinsert_rec(p_line_noINTEGER,
  1913. p_object_typeVARCHAR2,
  1914. p_user_nameVARCHAR2,
  1915. p_view_nameVARCHAR2,
  1916. p_stringVARCHAR2)IS
  1917. BEGIN
  1918. INSERTINTOtemp_for_pkg_gen_sql4000_temp
  1919. (line_no,object_type,user_name,object_name,sql_text)
  1920. VALUES
  1921. (p_line_no,p_object_type,p_user_name,p_view_name,p_string);
  1922. END;
  1923. BEGIN
  1924. v_object_type:='VIEW';
  1925. v_prompt:='--prompt';
  1926. SELECTusernameINTOv_usernameFROMuser_users;
  1927. DELETEtemp_for_pkg_gen_sql4000_tempWHEREobject_type=v_object_type;
  1928. COMMIT;
  1929. n_line_no:=1;
  1930. OPENcur_views;
  1931. LOOP
  1932. FETCHcur_views
  1933. INTOv_view_name,v_text;
  1934. EXITWHENcur_views%NOTFOUND;
  1935. IFupper(p_v_gen_drop_sql)='T'THEN
  1936. IFupper(p_v_display_prompt_info)='T'THEN
  1937. v_sql:=v_prompt||'DROPVIEW'||v_view_name;
  1938. insert_rec(n_line_no,
  1939. v_object_type,
  1940. v_username,
  1941. v_view_name,
  1942. v_sql);
  1943. n_line_no:=n_line_no+1;
  1944. ENDIF;
  1945. v_sql:='DROPVIEW'||v_view_name||';';
  1946. insert_rec(n_line_no,
  1947. v_object_type,
  1948. v_username,
  1949. v_view_name,
  1950. v_sql);
  1951. n_line_no:=n_line_no+1;
  1952. v_sql:='';
  1953. insert_rec(n_line_no,
  1954. v_object_type,
  1955. v_username,
  1956. v_view_name,
  1957. v_sql);
  1958. n_line_no:=n_line_no+1;
  1959. ENDIF;
  1960. IFupper(p_v_gen_create_sql)='T'THEN
  1961. IFupper(p_v_display_prompt_info)='T'THEN
  1962. v_sql:=v_prompt||'CREATEVIEW'||v_view_name;
  1963. insert_rec(n_line_no,
  1964. v_object_type,
  1965. v_username,
  1966. v_view_name,
  1967. v_sql);
  1968. n_line_no:=n_line_no+1;
  1969. ENDIF;
  1970. v_sql:='CREATEORREPLACEVIEW'||v_view_name;
  1971. insert_rec(n_line_no,
  1972. v_object_type,
  1973. v_username,
  1974. v_view_name,
  1975. v_sql);
  1976. n_line_no:=n_line_no+1;
  1977. v_sql:='(';
  1978. insert_rec(n_line_no,
  1979. v_object_type,
  1980. v_username,
  1981. v_view_name,
  1982. v_sql);
  1983. n_line_no:=n_line_no+1;
  1984. v_col_names:='';
  1985. n38_count:=0;
  1986. FORcur_cols_recINcur_cols(v_view_name)LOOP
  1987. v_col_names:=v_col_names||cur_cols_rec.column_name||',';
  1988. n38_count:=n38_count+1;
  1989. IFMOD(n38_count,5)=0THEN
  1990. v_sql:=chr(9)||v_col_names;
  1991. insert_rec(n_line_no,
  1992. v_object_type,
  1993. v_username,
  1994. v_view_name,
  1995. v_sql);
  1996. n_line_no:=n_line_no+1;
  1997. v_col_names:='';
  1998. ENDIF;
  1999. ENDLOOP;
  2000. IFlength(v_col_names)>2THEN
  2001. v_col_names:=substr(v_col_names,1,length(v_col_names)-2);
  2002. v_sql:=chr(9)||v_col_names;
  2003. insert_rec(n_line_no,
  2004. v_object_type,
  2005. v_username,
  2006. v_view_name,
  2007. v_sql);
  2008. n_line_no:=n_line_no+1;
  2009. ELSE
  2010. UPDATEtemp_for_pkg_gen_sql4000_temp
  2011. SETsql_text=substr(sql_text,1,length(sql_text)-2)
  2012. WHEREline_no=n_line_no-1
  2013. ANDobject_type=v_object_type;
  2014. ENDIF;
  2015. v_sql:=')';
  2016. insert_rec(n_line_no,
  2017. v_object_type,
  2018. v_username,
  2019. v_view_name,
  2020. v_sql);
  2021. n_line_no:=n_line_no+1;
  2022. v_sql:='AS';
  2023. insert_rec(n_line_no,
  2024. v_object_type,
  2025. v_username,
  2026. v_view_name,
  2027. v_sql);
  2028. n_line_no:=n_line_no+1;
  2029. v_text:=replace(v_text,',',',');
  2030. v_sql:=v_text;
  2031. IFlength(v_sql)>3800THEN
  2032. WHILElength(v_sql)>3800LOOP
  2033. n_position:=instr(substr(v_sql,1,3800),',',-1);
  2034. insert_rec(n_line_no,
  2035. v_object_type,
  2036. v_username,
  2037. v_view_name,
  2038. substr(v_sql,1,n_position));
  2039. v_sql:=substr(v_sql,n_position+1);
  2040. ENDLOOP;
  2041. insert_rec(n_line_no,
  2042. v_object_type,
  2043. v_username,
  2044. v_view_name,
  2045. v_sql);
  2046. ELSE
  2047. insert_rec(n_line_no,
  2048. v_object_type,
  2049. v_username,
  2050. v_view_name,
  2051. v_sql);
  2052. ENDIF;
  2053. n_line_no:=n_line_no+1;
  2054. UPDATEtemp_for_pkg_gen_sql4000_temp
  2055. SETsql_text=sql_text||';'
  2056. WHEREline_no=n_line_no-1
  2057. ANDobject_type=v_object_type;
  2058. v_sql:='';
  2059. insert_rec(n_line_no,
  2060. v_object_type,
  2061. v_username,
  2062. v_view_name,
  2063. v_sql);
  2064. n_line_no:=n_line_no+1;
  2065. ENDIF;
  2066. ENDLOOP;
  2067. CLOSEcur_views;
  2068. COMMIT;
  2069. END;
  2070. PROCEDUREpro_seq_max_val_sql(p_v_gen_drop_sqlVARCHAR2default'T',
  2071. p_v_gen_create_sqlVARCHAR2default'T',
  2072. p_v_display_prompt_infoVARCHAR2default'T')AS
  2073. v_sqlVARCHAR2(500);
  2074. n_max_idNUMBER(38,0);
  2075. v_max_valVARCHAR2(1000);
  2076. CURSORcur_etl_dataIS
  2077. SELECTtable_nameFROMuser_tables;
  2078. rec_etl_datacur_etl_data%rowtype;
  2079. typeref_curisREFCURSOR;--定义一个ref类型的游标
  2080. cur_idref_cur;
  2081. CURSORcur_cols(t_nameVARCHAR2)IS
  2082. SELECTcolumn_name,data_type
  2083. FROMuser_tab_columns
  2084. WHEREtable_name=t_name
  2085. ORDERBYcolumn_id;
  2086. rec_col_namecur_cols%rowtype;
  2087. v_sequence_nameVARCHAR2(50);
  2088. n_line_noNUMBER(38,0);
  2089. v_object_typeVARCHAR2(30);
  2090. v_promptVARCHAR2(30);
  2091. v_usernameVARCHAR2(30);
  2092. PROCEDUREinsert_rec(p_line_noINTEGER,
  2093. p_object_typeVARCHAR2,
  2094. p_user_nameVARCHAR2,
  2095. p_sequence_nameVARCHAR2,
  2096. p_stringVARCHAR2)IS
  2097. BEGIN
  2098. INSERTINTOtemp_for_pkg_gen_sql2000_temp
  2099. (line_no,object_type,user_name,object_name,sql_text)
  2100. VALUES
  2101. (p_line_no,p_object_type,p_user_name,p_sequence_name,p_string);
  2102. END;
  2103. BEGIN
  2104. n_line_no:=1;
  2105. v_object_type:='SEQUENCE_CHAR';
  2106. v_prompt:='--prompt';
  2107. SELECTusernameINTOv_usernameFROMuser_users;
  2108. DELETEtemp_for_pkg_gen_sql2000_tempWHEREobject_type=v_object_type;
  2109. COMMIT;
  2110. OPENcur_etl_data;
  2111. LOOP
  2112. FETCHcur_etl_data
  2113. INTOrec_etl_data;
  2114. EXITWHENcur_etl_data%NOTFOUND;
  2115. --得到表的第一个列
  2116. OPENcur_cols(rec_etl_data.table_name);
  2117. LOOP
  2118. FETCHcur_cols
  2119. INTOrec_col_name;
  2120. EXITWHENcur_cols%NOTFOUND;
  2121. EXIT;
  2122. ENDLOOP;
  2123. CLOSEcur_cols;
  2124. IFrec_col_name.data_type='VARCHAR2'OR
  2125. rec_col_name.data_type='VARCHAR'OR
  2126. rec_col_name.data_type='CHAR'THEN
  2127. BEGIN
  2128. v_sql:='SELECTmax(to_NUMBER('||rec_col_name.column_name||
  2129. '))FROM'||rec_etl_data.table_name||'';
  2130. OPENcur_idFORv_sql;
  2131. LOOP
  2132. FETCHcur_id
  2133. INTOv_max_val;
  2134. EXITWHENcur_id%NOTFOUND;
  2135. EXIT;
  2136. ENDLOOP;
  2137. CLOSEcur_id;
  2138. EXCEPTION
  2139. WHENothersTHEN
  2140. IFcur_id%ISOPENTHEN
  2141. CLOSEcur_id;
  2142. ENDIF;
  2143. v_max_val:='-1000';
  2144. END;
  2145. ELSIFrec_col_name.data_type='NUMBER'THEN
  2146. v_sql:='SELECTmax('||rec_col_name.column_name||')FROM'||
  2147. rec_etl_data.table_name||'';
  2148. OPENcur_idFORv_sql;
  2149. LOOP
  2150. FETCHcur_id
  2151. INTOn_max_id;
  2152. EXITWHENcur_id%NOTFOUND;
  2153. EXIT;
  2154. ENDLOOP;
  2155. CLOSEcur_id;
  2156. ENDIF;
  2157. --needmodify,generatesequencename
  2158. v_sequence_name:='seq_'||substr(rec_etl_data.table_name,3)||
  2159. '_id';
  2160. IFp_v_gen_drop_sql='T'THEN
  2161. IFp_v_display_prompt_info='T'THEN
  2162. v_sql:=v_prompt||'DROPSEQUENCE'||v_sequence_name;
  2163. insert_rec(n_line_no,
  2164. v_object_type,
  2165. v_username,
  2166. v_sequence_name,
  2167. v_sql);
  2168. n_line_no:=n_line_no+1;
  2169. ENDIF;
  2170. v_sql:='DROPSEQUENCE'||v_sequence_name||';';
  2171. insert_rec(n_line_no,
  2172. v_object_type,
  2173. v_username,
  2174. v_sequence_name,
  2175. v_sql);
  2176. n_line_no:=n_line_no+1;
  2177. v_sql:='';
  2178. insert_rec(n_line_no,
  2179. v_object_type,
  2180. v_username,
  2181. v_sequence_name,
  2182. v_sql);
  2183. n_line_no:=n_line_no+1;
  2184. ENDIF;
  2185. IFp_v_gen_create_sql='T'THEN
  2186. IFp_v_display_prompt_info='T'THEN
  2187. v_sql:=v_prompt||'CREATESEQUENCE'||v_sequence_name;
  2188. insert_rec(n_line_no,
  2189. v_object_type,
  2190. v_username,
  2191. v_sequence_name,
  2192. v_sql);
  2193. n_line_no:=n_line_no+1;
  2194. ENDIF;
  2195. v_sql:='CREATESEQUENCE'||v_sequence_name;
  2196. insert_rec(n_line_no,
  2197. v_object_type,
  2198. v_username,
  2199. v_sequence_name,
  2200. v_sql);
  2201. n_line_no:=n_line_no+1;
  2202. --handlethestation:treatethesequencevalueasvarcharcolumn(primarykey)
  2203. IFrec_col_name.data_type='VARCHAR2'OR
  2204. rec_col_name.data_type='VARCHAR'OR
  2205. rec_col_name.data_type='CHAR'THEN
  2206. v_sql:='STARTWITH'||
  2207. to_char(to_number(nvl(v_max_val,'1'))+1)||'';
  2208. ELSIFrec_col_name.data_type='NUMBER'THEN
  2209. v_sql:='STARTWITH'||TO_CHAR(nvl(n_max_id,1)+1)||'';
  2210. ENDIF;
  2211. insert_rec(n_line_no,
  2212. v_object_type,
  2213. v_username,
  2214. v_sequence_name,
  2215. v_sql);
  2216. n_line_no:=n_line_no+1;
  2217. v_sql:='INCREMENTBY1';
  2218. insert_rec(n_line_no,
  2219. v_object_type,
  2220. v_username,
  2221. v_sequence_name,
  2222. v_sql);
  2223. n_line_no:=n_line_no+1;
  2224. v_sql:='CACHE100NOCYCLE';
  2225. insert_rec(n_line_no,
  2226. v_object_type,
  2227. v_username,
  2228. v_sequence_name,
  2229. v_sql);
  2230. n_line_no:=n_line_no+1;
  2231. UPDATEtemp_for_pkg_gen_sql2000_temp
  2232. SETsql_text=sql_text||';'
  2233. WHEREline_no=n_line_no-1
  2234. ANDobject_type=v_object_type;
  2235. v_sql:='';
  2236. insert_rec(n_line_no,
  2237. v_object_type,
  2238. v_username,
  2239. v_sequence_name,
  2240. v_sql);
  2241. n_line_no:=n_line_no+1;
  2242. ENDIF;
  2243. ENDLOOP;
  2244. CLOSEcur_etl_data;
  2245. COMMIT;
  2246. END;
  2247. PROCEDUREpro_seq_next_val_sql(p_v_gen_drop_sqlVARCHAR2default'T',
  2248. p_v_gen_create_sqlVARCHAR2default'T',
  2249. p_v_display_prompt_infoVARCHAR2default'T')AS
  2250. v_sqlVARCHAR2(2000);
  2251. n_max_idNUMBER(38,0);
  2252. v_max_valVARCHAR2(1000);
  2253. CURSORcur_sequenceIS
  2254. SELECT*FROMuser_sequences;
  2255. rec_cur_sequencecur_sequence%rowtype;
  2256. v_sequence_nameVARCHAR2(50);
  2257. n_line_noNUMBER(38,0);
  2258. v_object_typeVARCHAR2(30);
  2259. v_promptVARCHAR2(30);
  2260. v_usernameVARCHAR2(30);
  2261. PROCEDUREinsert_rec(p_line_noINTEGER,
  2262. p_object_typeVARCHAR2,
  2263. p_user_nameVARCHAR2,
  2264. p_sequence_nameVARCHAR2,
  2265. p_stringVARCHAR2)IS
  2266. BEGIN
  2267. INSERTINTOtemp_for_pkg_gen_sql2000_temp
  2268. (line_no,object_type,user_name,object_name,sql_text)
  2269. VALUES
  2270. (p_line_no,p_object_type,p_user_name,p_sequence_name,p_string);
  2271. END;
  2272. BEGIN
  2273. n_line_no:=1;
  2274. v_object_type:='SEQUENCE';
  2275. v_prompt:='--prompt';
  2276. SELECTusernameINTOv_usernameFROMuser_users;
  2277. DELETEtemp_for_pkg_gen_sql2000_tempWHEREobject_type=v_object_type;
  2278. COMMIT;
  2279. OPENcur_sequence;
  2280. LOOP
  2281. FETCHcur_sequence
  2282. INTOrec_cur_sequence;
  2283. EXITWHENcur_sequence%NOTFOUND;
  2284. IFp_v_gen_drop_sql='T'THEN
  2285. IFp_v_display_prompt_info='T'THEN
  2286. v_sql:=v_prompt||'DROPSEQUENCE'||
  2287. rec_cur_sequence.sequence_name;
  2288. insert_rec(n_line_no,
  2289. v_object_type,
  2290. v_username,
  2291. rec_cur_sequence.sequence_name,
  2292. v_sql);
  2293. n_line_no:=n_line_no+1;
  2294. ENDIF;
  2295. v_sql:='DROPSEQUENCE'||rec_cur_sequence.sequence_name||';';
  2296. insert_rec(n_line_no,
  2297. v_object_type,
  2298. v_username,
  2299. rec_cur_sequence.sequence_name,
  2300. v_sql);
  2301. n_line_no:=n_line_no+1;
  2302. v_sql:='';
  2303. insert_rec(n_line_no,
  2304. v_object_type,
  2305. v_username,
  2306. rec_cur_sequence.sequence_name,
  2307. v_sql);
  2308. n_line_no:=n_line_no+1;
  2309. ENDIF;
  2310. IFp_v_gen_create_sql='T'THEN
  2311. IFp_v_display_prompt_info='T'THEN
  2312. v_sql:=v_prompt||'CREATESEQUENCE'||
  2313. rec_cur_sequence.sequence_name;
  2314. insert_rec(n_line_no,
  2315. v_object_type,
  2316. v_username,
  2317. rec_cur_sequence.sequence_name,
  2318. v_sql);
  2319. n_line_no:=n_line_no+1;
  2320. ENDIF;
  2321. v_sql:='CREATESEQUENCE'||rec_cur_sequence.sequence_name;
  2322. insert_rec(n_line_no,
  2323. v_object_type,
  2324. v_username,
  2325. rec_cur_sequence.sequence_name,
  2326. v_sql);
  2327. n_line_no:=n_line_no+1;
  2328. v_sql:='MINVALUE'||to_char(rec_cur_sequence.min_value);
  2329. insert_rec(n_line_no,
  2330. v_object_type,
  2331. v_username,
  2332. rec_cur_sequence.sequence_name,
  2333. v_sql);
  2334. n_line_no:=n_line_no+1;
  2335. v_sql:='MAXVALUE'||to_char(rec_cur_sequence.max_value);
  2336. insert_rec(n_line_no,
  2337. v_object_type,
  2338. v_username,
  2339. rec_cur_sequence.sequence_name,
  2340. v_sql);
  2341. n_line_no:=n_line_no+1;
  2342. v_sql:='STARTWITH'||to_char(rec_cur_sequence.last_number);
  2343. insert_rec(n_line_no,
  2344. v_object_type,
  2345. v_username,
  2346. rec_cur_sequence.sequence_name,
  2347. v_sql);
  2348. n_line_no:=n_line_no+1;
  2349. v_sql:='INCREMENTBY'||to_char(rec_cur_sequence.increment_by);
  2350. insert_rec(n_line_no,
  2351. v_object_type,
  2352. v_username,
  2353. rec_cur_sequence.sequence_name,
  2354. v_sql);
  2355. n_line_no:=n_line_no+1;
  2356. IFrec_cur_sequence.cache_size=0THEN
  2357. v_sql:='NOCACHE';
  2358. ELSE
  2359. v_sql:='CACHE'||to_char(rec_cur_sequence.cache_size);
  2360. ENDIF;
  2361. IFrec_cur_sequence.cycle_flag='N'THEN
  2362. v_sql:=v_sql||'NOCYCLE';
  2363. ELSE
  2364. v_sql:=v_sql||'CYCLE';
  2365. ENDIF;
  2366. insert_rec(n_line_no,
  2367. v_object_type,
  2368. v_username,
  2369. rec_cur_sequence.sequence_name,
  2370. v_sql);
  2371. n_line_no:=n_line_no+1;
  2372. UPDATEtemp_for_pkg_gen_sql2000_temp
  2373. SETsql_text=sql_text||';'
  2374. WHEREline_no=n_line_no-1
  2375. ANDobject_type=v_object_type;
  2376. v_sql:='';
  2377. insert_rec(n_line_no,
  2378. v_object_type,
  2379. v_username,
  2380. rec_cur_sequence.sequence_name,
  2381. v_sql);
  2382. n_line_no:=n_line_no+1;
  2383. ENDIF;
  2384. ENDLOOP;
  2385. CLOSEcur_sequence;
  2386. COMMIT;
  2387. END;
  2388. PROCEDUREpro_seq_init_val_sql(p_v_gen_drop_sqlVARCHAR2default'T',
  2389. p_v_gen_create_sqlVARCHAR2default'T',
  2390. p_v_display_prompt_infoVARCHAR2default'T')AS
  2391. v_sqlVARCHAR2(2000);
  2392. n_max_idNUMBER(38,0);
  2393. v_max_valVARCHAR2(1000);
  2394. CURSORcur_sequenceIS
  2395. SELECT*FROMuser_sequences;
  2396. rec_cur_sequencecur_sequence%rowtype;
  2397. v_sequence_nameVARCHAR2(50);
  2398. n_line_noNUMBER(38,0);
  2399. v_object_typeVARCHAR2(30);
  2400. v_promptVARCHAR2(30);
  2401. v_usernameVARCHAR2(30);
  2402. PROCEDUREinsert_rec(p_line_noINTEGER,
  2403. p_object_typeVARCHAR2,
  2404. p_user_nameVARCHAR2,
  2405. p_sequence_nameVARCHAR2,
  2406. p_stringVARCHAR2)IS
  2407. BEGIN
  2408. INSERTINTOtemp_for_pkg_gen_sql2000_temp
  2409. (line_no,object_type,user_name,object_name,sql_text)
  2410. VALUES
  2411. (p_line_no,p_object_type,p_user_name,p_sequence_name,p_string);
  2412. END;
  2413. BEGIN
  2414. n_line_no:=1;
  2415. v_object_type:='SEQUENCE_INIT';
  2416. v_prompt:='--prompt';
  2417. SELECTusernameINTOv_usernameFROMuser_users;
  2418. DELETEtemp_for_pkg_gen_sql2000_tempWHEREobject_type=v_object_type;
  2419. COMMIT;
  2420. OPENcur_sequence;
  2421. LOOP
  2422. FETCHcur_sequence
  2423. INTOrec_cur_sequence;
  2424. EXITWHENcur_sequence%NOTFOUND;
  2425. IFp_v_gen_drop_sql='T'THEN
  2426. IFp_v_display_prompt_info='T'THEN
  2427. v_sql:=v_prompt||'DROPSEQUENCE'||
  2428. rec_cur_sequence.sequence_name;
  2429. insert_rec(n_line_no,
  2430. v_object_type,
  2431. v_username,
  2432. rec_cur_sequence.sequence_name,
  2433. v_sql);
  2434. n_line_no:=n_line_no+1;
  2435. ENDIF;
  2436. v_sql:='DROPSEQUENCE'||rec_cur_sequence.sequence_name||';';
  2437. insert_rec(n_line_no,
  2438. v_object_type,
  2439. v_username,
  2440. rec_cur_sequence.sequence_name,
  2441. v_sql);
  2442. n_line_no:=n_line_no+1;
  2443. v_sql:='';
  2444. insert_rec(n_line_no,
  2445. v_object_type,
  2446. v_username,
  2447. rec_cur_sequence.sequence_name,
  2448. v_sql);
  2449. n_line_no:=n_line_no+1;
  2450. ENDIF;
  2451. IFp_v_gen_create_sql='T'THEN
  2452. IFp_v_display_prompt_info='T'THEN
  2453. v_sql:=v_prompt||'CREATESEQUENCE'||
  2454. rec_cur_sequence.sequence_name;
  2455. insert_rec(n_line_no,
  2456. v_object_type,
  2457. v_username,
  2458. rec_cur_sequence.sequence_name,
  2459. v_sql);
  2460. n_line_no:=n_line_no+1;
  2461. ENDIF;
  2462. v_sql:='CREATESEQUENCE'||rec_cur_sequence.sequence_name;
  2463. insert_rec(n_line_no,
  2464. v_object_type,
  2465. v_username,
  2466. rec_cur_sequence.sequence_name,
  2467. v_sql);
  2468. n_line_no:=n_line_no+1;
  2469. v_sql:='MINVALUE'||to_char(rec_cur_sequence.min_value);
  2470. insert_rec(n_line_no,
  2471. v_object_type,
  2472. v_username,
  2473. rec_cur_sequence.sequence_name,
  2474. v_sql);
  2475. n_line_no:=n_line_no+1;
  2476. v_sql:='MAXVALUE'||to_char(rec_cur_sequence.max_value);
  2477. insert_rec(n_line_no,
  2478. v_object_type,
  2479. v_username,
  2480. rec_cur_sequence.sequence_name,
  2481. v_sql);
  2482. n_line_no:=n_line_no+1;
  2483. v_sql:='STARTWITH1';
  2484. insert_rec(n_line_no,
  2485. v_object_type,
  2486. v_username,
  2487. rec_cur_sequence.sequence_name,
  2488. v_sql);
  2489. n_line_no:=n_line_no+1;
  2490. v_sql:='INCREMENTBY'||to_char(rec_cur_sequence.increment_by);
  2491. insert_rec(n_line_no,
  2492. v_object_type,
  2493. v_username,
  2494. rec_cur_sequence.sequence_name,
  2495. v_sql);
  2496. n_line_no:=n_line_no+1;
  2497. IFrec_cur_sequence.cycle_flag='N'THEN
  2498. v_sql:='CACHE'||to_char(rec_cur_sequence.cache_size)||
  2499. 'NOCYCLE';
  2500. ELSE
  2501. v_sql:='CACHE'||to_char(rec_cur_sequence.cache_size)||
  2502. 'CYCLE';
  2503. ENDIF;
  2504. insert_rec(n_line_no,
  2505. v_object_type,
  2506. v_username,
  2507. rec_cur_sequence.sequence_name,
  2508. v_sql);
  2509. n_line_no:=n_line_no+1;
  2510. UPDATEtemp_for_pkg_gen_sql2000_temp
  2511. SETsql_text=sql_text||';'
  2512. WHEREline_no=n_line_no-1
  2513. ANDobject_type=v_object_type;
  2514. v_sql:='';
  2515. insert_rec(n_line_no,
  2516. v_object_type,
  2517. v_username,
  2518. rec_cur_sequence.sequence_name,
  2519. v_sql);
  2520. n_line_no:=n_line_no+1;
  2521. ENDIF;
  2522. ENDLOOP;
  2523. CLOSEcur_sequence;
  2524. COMMIT;
  2525. END;
  2526. PROCEDUREpro_synonym_sql(p_v_gen_drop_sqlVARCHAR2default'T',
  2527. p_v_gen_create_sqlVARCHAR2default'T',
  2528. p_v_display_prompt_infoVARCHAR2default'T')AS
  2529. v_sqlVARCHAR2(2000);
  2530. n_max_idNUMBER(38,0);
  2531. v_max_valVARCHAR2(1000);
  2532. v_object_typeVARCHAR2(30);
  2533. v_promptVARCHAR2(30);
  2534. v_usernameVARCHAR2(30);
  2535. CURSORcur_synonymIS
  2536. SELECTsynonym_name,
  2537. 'CREATESYNONYM'||synonym_name||'for'||
  2538. decode(db_link,null,table_owner||'.','')||table_name||
  2539. decode(db_link,null,'','@'||db_link)||';'sql_text
  2540. FROMuser_synonyms;
  2541. rec_cur_synonymcur_synonym%rowtype;
  2542. v_synonym_nameVARCHAR2(50);
  2543. n_line_noNUMBER(38,0);
  2544. PROCEDUREinsert_rec(p_line_noINTEGER,
  2545. p_object_typeVARCHAR2,
  2546. p_user_nameVARCHAR2,
  2547. p_object_nameVARCHAR2,
  2548. p_stringVARCHAR2)IS
  2549. BEGIN
  2550. INSERTINTOtemp_for_pkg_gen_sql2000_temp
  2551. (line_no,object_type,user_name,object_name,sql_text)
  2552. VALUES
  2553. (p_line_no,p_object_type,p_user_name,p_object_name,p_string);
  2554. END;
  2555. BEGIN
  2556. n_line_no:=1;
  2557. v_object_type:=upper('SYNONYM');
  2558. v_prompt:='--prompt';
  2559. SELECTusernameINTOv_usernameFROMuser_users;
  2560. DELETEtemp_for_pkg_gen_sql2000_tempWHEREOBJECT_TYPE=v_object_type;
  2561. COMMIT;
  2562. OPENcur_synonym;
  2563. LOOP
  2564. FETCHcur_synonym
  2565. INTOrec_cur_synonym;
  2566. EXITWHENcur_synonym%NOTFOUND;
  2567. IFp_v_gen_drop_sql='T'THEN
  2568. IFp_v_display_prompt_info='T'THEN
  2569. v_sql:=v_prompt||'DROPSYNONYM'||
  2570. rec_cur_synonym.synonym_name;
  2571. insert_rec(n_line_no,
  2572. v_object_type,
  2573. v_username,
  2574. rec_cur_synonym.synonym_name,
  2575. v_sql);
  2576. n_line_no:=n_line_no+1;
  2577. ENDIF;
  2578. v_sql:='DROPSYNONYM'||rec_cur_synonym.synonym_name||';';
  2579. insert_rec(n_line_no,
  2580. v_object_type,
  2581. v_username,
  2582. rec_cur_synonym.synonym_name,
  2583. v_sql);
  2584. n_line_no:=n_line_no+1;
  2585. v_sql:='';
  2586. insert_rec(n_line_no,
  2587. v_object_type,
  2588. v_username,
  2589. rec_cur_synonym.synonym_name,
  2590. v_sql);
  2591. n_line_no:=n_line_no+1;
  2592. ENDIF;
  2593. IFp_v_gen_create_sql='T'THEN
  2594. IFp_v_display_prompt_info='T'THEN
  2595. v_sql:=v_prompt||'CREATESYNONYM'||
  2596. rec_cur_synonym.synonym_name;
  2597. insert_rec(n_line_no,
  2598. v_object_type,
  2599. v_username,
  2600. rec_cur_synonym.synonym_name,
  2601. v_sql);
  2602. n_line_no:=n_line_no+1;
  2603. ENDIF;
  2604. v_sql:=rec_cur_synonym.sql_text;
  2605. insert_rec(n_line_no,
  2606. v_object_type,
  2607. v_username,
  2608. rec_cur_synonym.synonym_name,
  2609. v_sql);
  2610. n_line_no:=n_line_no+1;
  2611. v_sql:='';
  2612. insert_rec(n_line_no,
  2613. v_object_type,
  2614. v_username,
  2615. rec_cur_synonym.synonym_name,
  2616. v_sql);
  2617. n_line_no:=n_line_no+1;
  2618. ENDIF;
  2619. ENDLOOP;
  2620. CLOSEcur_synonym;
  2621. COMMIT;
  2622. END;
  2623. PROCEDUREpro_job_sql(p_v_gen_drop_sqlVARCHAR2default'T',
  2624. p_v_gen_create_sqlVARCHAR2default'T',
  2625. p_v_display_prompt_infoVARCHAR2default'T')AS
  2626. v_sqlVARCHAR2(4000);
  2627. n_max_idNUMBER(38,0);
  2628. v_max_valVARCHAR2(1000);
  2629. v_object_typeVARCHAR2(30);
  2630. v_promptVARCHAR2(30);
  2631. v_usernameVARCHAR2(30);
  2632. v_object_nameVARCHAR2(200);
  2633. CURSORcur_jobIS
  2634. SELECTjobjob_no,
  2635. decode(instr(what,chr(10)),
  2636. 0,
  2637. what,
  2638. substr(what,1,instr(what,chr(10))-1))job_name,
  2639. 'dbms_job.submit(:jobno,'''||what||''',sysdate,'''||
  2640. interval||''');'sql_text
  2641. FROMuser_jobs;
  2642. rec_cur_jobcur_job%rowtype;
  2643. v_job_nameVARCHAR2(50);
  2644. n_line_noNUMBER(38,0);
  2645. PROCEDUREinsert_rec(p_line_noINTEGER,
  2646. p_object_typeVARCHAR2,
  2647. p_user_nameVARCHAR2,
  2648. p_object_nameVARCHAR2,
  2649. p_stringVARCHAR2)IS
  2650. BEGIN
  2651. INSERTINTOtemp_for_pkg_gen_sql4000_temp
  2652. (line_no,object_type,user_name,object_name,sql_text)
  2653. VALUES
  2654. (p_line_no,p_object_type,p_user_name,p_object_name,p_string);
  2655. END;
  2656. BEGIN
  2657. n_line_no:=1;
  2658. v_object_type:=upper('job');
  2659. v_prompt:='--prompt';
  2660. SELECTusernameINTOv_usernameFROMuser_users;
  2661. DELETEtemp_for_pkg_gen_sql4000_tempWHEREOBJECT_TYPE=v_object_type;
  2662. COMMIT;
  2663. OPENcur_job;
  2664. LOOP
  2665. FETCHcur_job
  2666. INTOrec_cur_job;
  2667. EXITWHENcur_job%NOTFOUND;
  2668. IFp_v_gen_drop_sql='T'THEN
  2669. IFp_v_display_prompt_info='T'THEN
  2670. v_sql:=v_prompt||'DROPjob'||rec_cur_job.job_name;
  2671. insert_rec(n_line_no,
  2672. v_object_type,
  2673. v_username,
  2674. rec_cur_job.job_name,
  2675. v_sql);
  2676. n_line_no:=n_line_no+1;
  2677. ENDIF;
  2678. v_sql:='execdbms_job.remove('||to_char(rec_cur_job.job_no)||');';
  2679. insert_rec(n_line_no,
  2680. v_object_type,
  2681. v_username,
  2682. rec_cur_job.job_name,
  2683. v_sql);
  2684. n_line_no:=n_line_no+1;
  2685. v_sql:='';
  2686. insert_rec(n_line_no,
  2687. v_object_type,
  2688. v_username,
  2689. rec_cur_job.job_name,
  2690. v_sql);
  2691. n_line_no:=n_line_no+1;
  2692. ENDIF;
  2693. IFp_v_gen_create_sql='T'THEN
  2694. IFp_v_display_prompt_info='T'THEN
  2695. v_sql:=v_prompt||'CREATEjob'||rec_cur_job.job_name;
  2696. insert_rec(n_line_no,
  2697. v_object_type,
  2698. v_username,
  2699. rec_cur_job.job_name,
  2700. v_sql);
  2701. n_line_no:=n_line_no+1;
  2702. ENDIF;
  2703. v_sql:='variablejobnonumber;';
  2704. insert_rec(n_line_no,
  2705. v_object_type,
  2706. v_username,
  2707. rec_cur_job.job_name,
  2708. v_sql);
  2709. n_line_no:=n_line_no+1;
  2710. v_sql:='begin';
  2711. insert_rec(n_line_no,
  2712. v_object_type,
  2713. v_username,
  2714. rec_cur_job.job_name,
  2715. v_sql);
  2716. n_line_no:=n_line_no+1;
  2717. v_sql:=rec_cur_job.sql_text;
  2718. insert_rec(n_line_no,
  2719. v_object_type,
  2720. v_username,
  2721. rec_cur_job.job_name,
  2722. v_sql);
  2723. n_line_no:=n_line_no+1;
  2724. v_sql:='end;';
  2725. insert_rec(n_line_no,
  2726. v_object_type,
  2727. v_username,
  2728. rec_cur_job.job_name,
  2729. v_sql);
  2730. n_line_no:=n_line_no+1;
  2731. v_sql:='/';
  2732. insert_rec(n_line_no,
  2733. v_object_type,
  2734. v_username,
  2735. rec_cur_job.job_name,
  2736. v_sql);
  2737. n_line_no:=n_line_no+1;
  2738. v_sql:='';
  2739. insert_rec(n_line_no,
  2740. v_object_type,
  2741. v_username,
  2742. rec_cur_job.job_name,
  2743. v_sql);
  2744. n_line_no:=n_line_no+1;
  2745. ENDIF;
  2746. ENDLOOP;
  2747. CLOSEcur_job;
  2748. COMMIT;
  2749. END;
  2750. PROCEDUREpro_dl_sql(p_v_gen_drop_sqlVARCHAR2default'T',
  2751. p_v_gen_create_sqlVARCHAR2default'T',
  2752. p_v_display_prompt_infoVARCHAR2default'T')AS
  2753. v_sqlVARCHAR2(2000);
  2754. n_max_idNUMBER(38,0);
  2755. v_max_valVARCHAR2(1000);
  2756. v_object_typeVARCHAR2(30);
  2757. v_promptVARCHAR2(30);
  2758. v_usernameVARCHAR2(30);
  2759. CURSORcur_dlIS
  2760. SELECTdb_link,
  2761. 'CREATEDATABASELINK'||db_link||'CONNECTTO'||
  2762. username||'IDENTIFIEDBY'||password||'USING'''||HOST||
  2763. ''';'sql_text
  2764. FROMuser_db_links;
  2765. rec_cur_dlcur_dl%rowtype;
  2766. v_db_linkVARCHAR2(50);
  2767. n_line_noNUMBER(38,0);
  2768. PROCEDUREinsert_rec(p_line_noINTEGER,
  2769. p_object_typeVARCHAR2,
  2770. p_user_nameVARCHAR2,
  2771. p_object_nameVARCHAR2,
  2772. p_stringVARCHAR2)IS
  2773. BEGIN
  2774. INSERTINTOtemp_for_pkg_gen_sql2000_temp
  2775. (line_no,object_type,user_name,object_name,sql_text)
  2776. VALUES
  2777. (p_line_no,p_object_type,p_user_name,p_object_name,p_string);
  2778. END;
  2779. BEGIN
  2780. n_line_no:=1;
  2781. v_object_type:=upper('DL');
  2782. v_prompt:='--prompt';
  2783. SELECTusernameINTOv_usernameFROMuser_users;
  2784. DELETEtemp_for_pkg_gen_sql2000_tempWHEREOBJECT_TYPE=v_object_type;
  2785. COMMIT;
  2786. OPENcur_dl;
  2787. LOOP
  2788. FETCHcur_dl
  2789. INTOrec_cur_dl;
  2790. EXITWHENcur_dl%NOTFOUND;
  2791. IFp_v_gen_drop_sql='T'THEN
  2792. IFp_v_display_prompt_info='T'THEN
  2793. v_sql:=v_prompt||'DROPDATABASELIKE'||rec_cur_dl.db_link;
  2794. insert_rec(n_line_no,
  2795. v_object_type,
  2796. v_username,
  2797. rec_cur_dl.db_link,
  2798. v_sql);
  2799. n_line_no:=n_line_no+1;
  2800. ENDIF;
  2801. v_sql:='DROPDATABASELIKE'||rec_cur_dl.db_link||';';
  2802. insert_rec(n_line_no,
  2803. v_object_type,
  2804. v_username,
  2805. rec_cur_dl.db_link,
  2806. v_sql);
  2807. n_line_no:=n_line_no+1;
  2808. v_sql:='';
  2809. insert_rec(n_line_no,
  2810. v_object_type,
  2811. v_username,
  2812. rec_cur_dl.db_link,
  2813. v_sql);
  2814. n_line_no:=n_line_no+1;
  2815. ENDIF;
  2816. IFp_v_gen_create_sql='T'THEN
  2817. IFp_v_display_prompt_info='T'THEN
  2818. v_sql:=v_prompt||'CREATEDATABASELINK'||
  2819. rec_cur_dl.db_link;
  2820. insert_rec(n_line_no,
  2821. v_object_type,
  2822. v_username,
  2823. rec_cur_dl.db_link,
  2824. v_sql);
  2825. n_line_no:=n_line_no+1;
  2826. ENDIF;
  2827. v_sql:=rec_cur_dl.sql_text;
  2828. insert_rec(n_line_no,
  2829. v_object_type,
  2830. v_username,
  2831. rec_cur_dl.db_link,
  2832. v_sql);
  2833. n_line_no:=n_line_no+1;
  2834. v_sql:='';
  2835. insert_rec(n_line_no,
  2836. v_object_type,
  2837. v_username,
  2838. rec_cur_dl.db_link,
  2839. v_sql);
  2840. n_line_no:=n_line_no+1;
  2841. ENDIF;
  2842. ENDLOOP;
  2843. CLOSEcur_dl;
  2844. COMMIT;
  2845. END;
  2846. PROCEDUREpro_role_sql(p_v_gen_drop_sqlVARCHAR2default'T',
  2847. p_v_gen_create_sqlVARCHAR2default'T',
  2848. p_v_display_prompt_infoVARCHAR2default'T')AS
  2849. v_sqlVARCHAR2(2000);
  2850. v_optionVARCHAR2(200);
  2851. n_max_idNUMBER(38,0);
  2852. v_max_valVARCHAR2(1000);
  2853. v_object_typeVARCHAR2(30);
  2854. v_promptVARCHAR2(30);
  2855. v_usernameVARCHAR2(30);
  2856. CURSORcur_roleIS
  2857. selectgranted_rolerolefromuser_role_privs;
  2858. rec_cur_rolecur_role%rowtype;
  2859. CURSORcur_role_pris(c_role_nameVARCHAR2)IS
  2860. SELECTtype,
  2861. role,
  2862. owner,
  2863. table_name,
  2864. column_name,
  2865. privilege,
  2866. grantable
  2867. FROM(SELECT'TAB'type,
  2868. role,
  2869. owner,
  2870. table_name,
  2871. column_name,
  2872. privilege,
  2873. grantable
  2874. FROMrole_tab_privs
  2875. WHEREroleNOTIN('CONNECT','RESOURCE','DBA')
  2876. UNION
  2877. SELECT'SYS'type,
  2878. role,
  2879. ''owner,
  2880. ''table_name,
  2881. ''column_name,
  2882. privilege,
  2883. admin_optiongrantable
  2884. FROMrole_sys_privs
  2885. WHEREroleNOTIN('CONNECT','RESOURCE','DBA'))
  2886. whererole=upper(c_role_name);
  2887. rec_cur_role_priscur_role_pris%rowtype;
  2888. v_roleVARCHAR2(50);
  2889. n_line_noNUMBER(38,0);
  2890. PROCEDUREinsert_rec(p_line_noINTEGER,
  2891. p_object_typeVARCHAR2,
  2892. p_user_nameVARCHAR2,
  2893. p_object_nameVARCHAR2,
  2894. p_stringVARCHAR2)IS
  2895. BEGIN
  2896. INSERTINTOtemp_for_pkg_gen_sql2000_temp
  2897. (line_no,object_type,user_name,object_name,sql_text)
  2898. VALUES
  2899. (p_line_no,p_object_type,p_user_name,p_object_name,p_string);
  2900. END;
  2901. BEGIN
  2902. n_line_no:=1;
  2903. v_object_type:=UPPER('ROLE');
  2904. v_prompt:='--prompt';
  2905. SELECTusernameINTOv_usernameFROMuser_users;
  2906. DELETEtemp_for_pkg_gen_sql2000_tempWHEREOBJECT_TYPE=v_object_type;
  2907. COMMIT;
  2908. OPENcur_role;
  2909. LOOP
  2910. FETCHcur_role
  2911. INTOrec_cur_role;
  2912. EXITWHENcur_role%NOTFOUND;
  2913. IFp_v_gen_drop_sql='T'THEN
  2914. IFp_v_display_prompt_info='T'THEN
  2915. v_sql:=v_prompt||'DROPROLE'||rec_cur_role.role;
  2916. insert_rec(n_line_no,
  2917. v_object_type,
  2918. v_username,
  2919. rec_cur_role.role,
  2920. v_sql);
  2921. n_line_no:=n_line_no+1;
  2922. ENDIF;
  2923. v_sql:='DROPROLE'||rec_cur_role.role||';';
  2924. insert_rec(n_line_no,
  2925. v_object_type,
  2926. v_username,
  2927. rec_cur_role.role,
  2928. v_sql);
  2929. n_line_no:=n_line_no+1;
  2930. v_sql:='';
  2931. insert_rec(n_line_no,
  2932. v_object_type,
  2933. v_username,
  2934. rec_cur_role.role,
  2935. v_sql);
  2936. n_line_no:=n_line_no+1;
  2937. ENDIF;
  2938. IFp_v_gen_create_sql='T'THEN
  2939. IFp_v_display_prompt_info='T'THEN
  2940. v_sql:=v_prompt||'CREATEROLE'||rec_cur_role.role;
  2941. insert_rec(n_line_no,
  2942. v_object_type,
  2943. v_username,
  2944. rec_cur_role.role,
  2945. v_sql);
  2946. n_line_no:=n_line_no+1;
  2947. ENDIF;
  2948. v_sql:='CREATEROLE'||rec_cur_role.role||';';
  2949. insert_rec(n_line_no,
  2950. v_object_type,
  2951. v_username,
  2952. rec_cur_role.role,
  2953. v_sql);
  2954. n_line_no:=n_line_no+1;
  2955. v_sql:=v_prompt||'GRANTPRISTOROLE:'||rec_cur_role.role;
  2956. insert_rec(n_line_no,
  2957. v_object_type,
  2958. v_username,
  2959. rec_cur_role.role,
  2960. v_sql);
  2961. n_line_no:=n_line_no+1;
  2962. OPENcur_role_pris(rec_cur_role.role);
  2963. LOOP
  2964. FETCHcur_role_pris
  2965. INTOrec_cur_role_pris;
  2966. EXITWHENcur_role_pris%NOTFOUND;
  2967. IFrec_cur_role_pris.type='SYS'THEN
  2968. IFrec_cur_role_pris.grantable='NO'THEN
  2969. v_option:='';
  2970. ELSE
  2971. v_option:='WITHADMINOPTION';
  2972. ENDIF;
  2973. v_sql:='GRANT'||rec_cur_role_pris.privilege||'TO'||
  2974. rec_cur_role_pris.role||v_option||';';
  2975. insert_rec(n_line_no,
  2976. v_object_type,
  2977. v_username,
  2978. rec_cur_role.role,
  2979. v_sql);
  2980. n_line_no:=n_line_no+1;
  2981. ELSE
  2982. IFrec_cur_role_pris.grantable='NO'THEN
  2983. v_option:='';
  2984. ELSE
  2985. v_option:='WITHGRANTOPTION';
  2986. ENDIF;
  2987. IFrec_cur_role_pris.column_nameISNOTNULLTHEN
  2988. v_sql:='GRANT'||rec_cur_role_pris.privilege||'('||
  2989. rec_cur_role_pris.column_name||')ON'||
  2990. rec_cur_role_pris.owner||'.'||
  2991. rec_cur_role_pris.table_name||'TO'||
  2992. rec_cur_role_pris.role||v_option||';';
  2993. ELSE
  2994. v_sql:='GRANT'||rec_cur_role_pris.privilege||'ON'||
  2995. rec_cur_role_pris.owner||'.'||
  2996. rec_cur_role_pris.table_name||'TO'||
  2997. rec_cur_role_pris.role||v_option||';';
  2998. ENDIF;
  2999. insert_rec(n_line_no,
  3000. v_object_type,
  3001. v_username,
  3002. rec_cur_role.role,
  3003. v_sql);
  3004. n_line_no:=n_line_no+1;
  3005. ENDIF;
  3006. ENDLOOP;
  3007. CLOSEcur_role_pris;
  3008. v_sql:='';
  3009. insert_rec(n_line_no,
  3010. v_object_type,
  3011. v_username,
  3012. rec_cur_role.role,
  3013. v_sql);
  3014. n_line_no:=n_line_no+1;
  3015. ENDIF;
  3016. ENDLOOP;
  3017. CLOSEcur_role;
  3018. COMMIT;
  3019. END;
  3020. PROCEDUREpro_priv_sql(p_v_gen_drop_sqlVARCHAR2default'T',
  3021. p_v_gen_create_sqlVARCHAR2default'T',
  3022. p_v_display_prompt_infoVARCHAR2default'T')AS
  3023. v_sqlVARCHAR2(2000);
  3024. v_optionVARCHAR2(200);
  3025. n_max_idNUMBER(38,0);
  3026. v_max_valVARCHAR2(1000);
  3027. v_object_typeVARCHAR2(30);
  3028. v_promptVARCHAR2(30);
  3029. v_usernameVARCHAR2(30);
  3030. n_countnumber(10,0);
  3031. CURSORcur_privIS
  3032. SELECTprivilege,
  3033. owner,
  3034. table_name,
  3035. grantee,
  3036. 'GRANT'||privilege||'ON'||owner||'.'||table_name||
  3037. 'TO'||grantee||
  3038. decode(grantable,'NO','','WITHGRANTOPTION')||';'SQL_TEXT
  3039. FROMuser_tab_privs
  3040. WHEREGRANTOR=(SELECTusernameFROMuser_users)
  3041. ORDERBYowner,table_name;
  3042. rec_cur_privcur_priv%rowtype;
  3043. CURSORcur_col_privIS
  3044. SELECTprivilege,
  3045. owner,
  3046. column_name,
  3047. table_name,
  3048. grantee,
  3049. 'GRANT'||privilege||''||column_name||'ON'||owner||'.'||
  3050. table_name||'TO'||grantee||
  3051. decode(grantable,'NO','','WITHGRANTOPTION')||';'SQL_TEXT
  3052. FROMuser_col_privs
  3053. WHEREGRANTOR=(SELECTusernameFROMuser_users)
  3054. ORDERBYowner,table_name;
  3055. rec_cur_col_privcur_col_priv%rowtype;
  3056. CURSORcur_sys_privIS
  3057. SELECTusername,
  3058. privilege,
  3059. 'GRANT'||privilege||'TO'||username||
  3060. decode(admin_option,'NO','','WITHADMINOPTION')||';'SQL_TEXT
  3061. FROMuser_sys_privs
  3062. ORDERBYusername;
  3063. rec_cur_sys_privcur_sys_priv%rowtype;
  3064. v_privVARCHAR2(50);
  3065. n_line_noNUMBER(38,0);
  3066. PROCEDUREinsert_rec(p_line_noINTEGER,
  3067. p_object_typeVARCHAR2,
  3068. p_user_nameVARCHAR2,
  3069. p_object_nameVARCHAR2,
  3070. p_stringVARCHAR2)IS
  3071. BEGIN
  3072. INSERTINTOtemp_for_pkg_gen_sql2000_temp
  3073. (line_no,object_type,user_name,object_name,sql_text)
  3074. VALUES
  3075. (p_line_no,p_object_type,p_user_name,p_object_name,p_string);
  3076. END;
  3077. BEGIN
  3078. n_line_no:=1;
  3079. v_object_type:=UPPER('PRIV');
  3080. v_prompt:='--prompt';
  3081. n_count:=1;
  3082. SELECTUSERNAMEINTOv_usernameFROMUSER_USERS;
  3083. DELETEtemp_for_pkg_gen_sql2000_tempWHEREOBJECT_TYPE=v_object_type;
  3084. COMMIT;
  3085. OPENcur_priv;
  3086. LOOP
  3087. FETCHcur_priv
  3088. INTOrec_cur_priv;
  3089. EXITWHENcur_priv%NOTFOUND;
  3090. IFp_v_gen_create_sql='T'THEN
  3091. IFp_v_display_prompt_info='T'THEN
  3092. v_sql:=v_prompt||'GRANTPRIVILEGE:'||
  3093. rec_cur_priv.privilege||'ON'||rec_cur_priv.owner||'.'||
  3094. rec_cur_priv.table_name||'TO'||
  3095. rec_cur_priv.grantee;
  3096. insert_rec(n_line_no,
  3097. v_object_type,
  3098. v_username,
  3099. 'tabpriv',
  3100. v_sql);
  3101. n_line_no:=n_line_no+1;
  3102. ENDIF;
  3103. v_sql:=rec_cur_priv.sql_text;
  3104. insert_rec(n_line_no,v_object_type,v_username,'tabpriv',v_sql);
  3105. n_line_no:=n_line_no+1;
  3106. v_sql:='';
  3107. insert_rec(n_line_no,v_object_type,v_username,'tabpriv',v_sql);
  3108. n_line_no:=n_line_no+1;
  3109. ENDIF;
  3110. ENDLOOP;
  3111. CLOSEcur_priv;
  3112. OPENcur_col_priv;
  3113. LOOP
  3114. FETCHcur_col_priv
  3115. INTOrec_cur_col_priv;
  3116. EXITWHENcur_col_priv%NOTFOUND;
  3117. IFn_count=1THEN
  3118. v_sql:='--***********************';
  3119. insert_rec(n_line_no,v_object_type,v_username,'tabpriv',v_sql);
  3120. n_line_no:=n_line_no+1;
  3121. n_count:=n_count+1;
  3122. ENDIF;
  3123. v_sql:='';
  3124. insert_rec(n_line_no,v_object_type,v_username,'tabpriv',v_sql);
  3125. n_line_no:=n_line_no+1;
  3126. IFp_v_display_prompt_info='T'THEN
  3127. v_sql:=v_prompt||'GRANTCOLPRIVILEGE:'||
  3128. rec_cur_col_priv.privilege||'ON'||
  3129. rec_cur_col_priv.owner||'.'||
  3130. rec_cur_col_priv.table_name||'TO'||
  3131. rec_cur_col_priv.grantee;
  3132. insert_rec(n_line_no,v_object_type,v_username,'colpriv',v_sql);
  3133. n_line_no:=n_line_no+1;
  3134. ENDIF;
  3135. v_sql:=rec_cur_col_priv.sql_text;
  3136. insert_rec(n_line_no,v_object_type,v_username,'colpriv',v_sql);
  3137. n_line_no:=n_line_no+1;
  3138. v_sql:='';
  3139. insert_rec(n_line_no,v_object_type,v_username,'colpriv',v_sql);
  3140. n_line_no:=n_line_no+1;
  3141. ENDLOOP;
  3142. CLOSEcur_col_priv;
  3143. n_count:=1;
  3144. OPENcur_sys_priv;
  3145. LOOP
  3146. FETCHcur_sys_priv
  3147. INTOrec_cur_sys_priv;
  3148. EXITWHENcur_sys_priv%NOTFOUND;
  3149. IFn_count=1THEN
  3150. v_sql:='';
  3151. insert_rec(n_line_no,v_object_type,v_username,'syspriv',v_sql);
  3152. n_line_no:=n_line_no+1;
  3153. v_sql:='PROMPT***********YoumustthefollowingsqlasauserwithDBApriv,othersyouwillgeterrors!
  3154. ************';
  3155. insert_rec(n_line_no,v_object_type,v_username,'syspriv',v_sql);
  3156. n_line_no:=n_line_no+1;
  3157. v_sql:='PROMPT***********Wecommentthefollowsql!************';
  3158. insert_rec(n_line_no,v_object_type,v_username,'syspriv',v_sql);
  3159. n_line_no:=n_line_no+1;
  3160. v_sql:='';
  3161. insert_rec(n_line_no,v_object_type,v_username,'syspriv',v_sql);
  3162. n_line_no:=n_line_no+1;
  3163. n_count:=n_count+1;
  3164. ENDIF;
  3165. IFp_v_display_prompt_info='T'THEN
  3166. v_sql:=v_prompt||'GRANTSYSTEMPRIVILEGE:'||
  3167. rec_cur_sys_priv.privilege||'TO'||
  3168. rec_cur_sys_priv.username;
  3169. insert_rec(n_line_no,v_object_type,v_username,'syspriv',v_sql);
  3170. n_line_no:=n_line_no+1;
  3171. ENDIF;
  3172. v_sql:='--'||rec_cur_sys_priv.sql_text;
  3173. insert_rec(n_line_no,v_object_type,v_username,'syspriv',v_sql);
  3174. n_line_no:=n_line_no+1;
  3175. v_sql:='';
  3176. insert_rec(n_line_no,v_object_type,v_username,'syspriv',v_sql);
  3177. n_line_no:=n_line_no+1;
  3178. ENDLOOP;
  3179. CLOSEcur_sys_priv;
  3180. COMMIT;
  3181. END;
  3182. PROCEDUREpro_pkgprofuntri_sql(p_v_gen_drop_sqlVARCHAR2default'T',
  3183. p_v_gen_create_sqlVARCHAR2default'T',
  3184. p_v_display_prompt_infoVARCHAR2default'T',
  3185. p_v_separ_fileVARCHAR2default'T',
  3186. p_v_file_pathVARCHAR2default'C:/')AS
  3187. v_sqlVARCHAR2(2000);
  3188. v_object_typeVARCHAR2(30);
  3189. v_promptVARCHAR2(30);
  3190. v_file_pathVARCHAR2(600);
  3191. v_notionchar(1);
  3192. v_usernameVARCHAR2(30);
  3193. CURSORcur_ProFunPkg_nameIS
  3194. SELECTdistincttype,us.name
  3195. FROMuser_sourceus
  3196. WHEREtype<>'PACKAGEBODY'
  3197. ANDus.name<>upper('pkg_gen_user_sql')
  3198. ORDERBYus.type,us.name;
  3199. CURSORcur_ProFunPkg_code(c_obj_nameVARCHAR2,c_obj_typeVARCHAR2)IS
  3200. SELECTline,type,text
  3201. FROMuser_sourceus
  3202. WHERENAME=c_obj_name
  3203. ANDtype=c_obj_type
  3204. ORDERBYtype,line;
  3205. v_object_nameVARCHAR2(50);
  3206. n_line_noNUMBER(38,0);
  3207. PROCEDUREinsert_rec(p_line_noINTEGER,
  3208. p_object_typeVARCHAR2,
  3209. p_user_nameVARCHAR2,
  3210. p_object_nameVARCHAR2,
  3211. p_stringVARCHAR2)IS
  3212. BEGIN
  3213. INSERTINTOtemp_for_pkg_gen_sql4000_temp
  3214. (line_no,object_type,user_name,object_name,sql_text)
  3215. VALUES
  3216. (p_line_no,p_object_type,p_user_name,p_object_name,p_string);
  3217. END;
  3218. BEGIN
  3219. n_line_no:=1;
  3220. v_file_path:=p_v_file_path;
  3221. v_prompt:='--prompt';
  3222. SELECTusernameINTOv_usernameFROMuser_users;
  3223. --findthenotionbetweenthedictionary
  3224. IFinstr(p_v_file_path,'/')>0THEN
  3225. v_notion:='/';
  3226. ELSE
  3227. v_notion:='/';
  3228. ENDIF;
  3229. IFsubstr(v_file_path,length(v_file_path))<>v_notionTHEN
  3230. v_file_path:=v_file_path||v_notion;
  3231. ENDIF;
  3232. DELETEtemp_for_pkg_gen_sql4000_temp
  3233. WHEREOBJECT_TYPEIN
  3234. ('PACKAGEBODY','PACKAGE','PROCEDURE','FUNCTION',
  3235. 'SEPAR_PROCS','SEPAR_FUNCS','SEPAR_PKG_HEADS',
  3236. 'SEPAR_PKG_BODYS','SEPAR_PKGS','TRIGGER','SEPAR_TRIS');
  3237. COMMIT;
  3238. FORrec_ProFunPkg_nameINcur_ProFunPkg_nameLOOP
  3239. v_object_type:=rec_ProFunPkg_name.type;
  3240. v_sql:='--~~~~~~~~~~~~~~~~~~~~'||rec_ProFunPkg_name.type||
  3241. ':'||rec_ProFunPkg_name.name||
  3242. 'START;~~~~~~~~~~~~~~~~~~~~';
  3243. insert_rec(n_line_no,
  3244. v_object_type,
  3245. v_username,
  3246. rec_ProFunPkg_name.name,
  3247. v_sql);
  3248. n_line_no:=n_line_no+1;
  3249. v_sql:='';
  3250. insert_rec(n_line_no,
  3251. v_object_type,
  3252. v_username,
  3253. rec_ProFunPkg_name.name,
  3254. v_sql);
  3255. n_line_no:=n_line_no+1;
  3256. IFp_v_gen_drop_sql='T'ANDv_object_type<>'PACKAGEBODY'THEN
  3257. IFp_v_display_prompt_info='T'THEN
  3258. v_sql:=v_prompt||'DROP'||rec_ProFunPkg_name.type||''||
  3259. rec_ProFunPkg_name.name;
  3260. insert_rec(n_line_no,
  3261. v_object_type,
  3262. v_username,
  3263. rec_ProFunPkg_name.name,
  3264. v_sql);
  3265. n_line_no:=n_line_no+1;
  3266. ENDIF;
  3267. v_sql:='DROP'||rec_ProFunPkg_name.type||''||
  3268. rec_ProFunPkg_name.type||''||rec_ProFunPkg_name.name||';';
  3269. insert_rec(n_line_no,
  3270. v_object_type,
  3271. v_username,
  3272. rec_ProFunPkg_name.name,
  3273. v_sql);
  3274. n_line_no:=n_line_no+1;
  3275. v_sql:='';
  3276. insert_rec(n_line_no,
  3277. v_object_type,
  3278. v_username,
  3279. rec_ProFunPkg_name.name,
  3280. v_sql);
  3281. n_line_no:=n_line_no+1;
  3282. ENDIF;
  3283. IFp_v_gen_create_sql='T'THEN
  3284. IFp_v_display_prompt_info='T'THEN
  3285. v_sql:=v_prompt||'CREATE'||rec_ProFunPkg_name.type||''||
  3286. rec_ProFunPkg_name.name;
  3287. insert_rec(n_line_no,
  3288. v_object_type,
  3289. v_username,
  3290. rec_ProFunPkg_name.name,
  3291. v_sql);
  3292. n_line_no:=n_line_no+1;
  3293. ENDIF;
  3294. FORrec_ProFunPkg_codeINcur_ProFunPkg_code(rec_ProFunPkg_name.name,
  3295. rec_ProFunPkg_name.type)LOOP
  3296. IFrec_ProFunPkg_code.line=1THEN
  3297. v_sql:='CREATEORREPLACE'||rec_ProFunPkg_code.text;
  3298. ELSE
  3299. v_sql:=rec_ProFunPkg_code.text;
  3300. ENDIF;
  3301. insert_rec(n_line_no,
  3302. v_object_type,
  3303. v_username,
  3304. rec_ProFunPkg_name.name,
  3305. v_sql);
  3306. n_line_no:=n_line_no+1;
  3307. ENDLOOP;
  3308. v_sql:='/';
  3309. insert_rec(n_line_no,
  3310. v_object_type,
  3311. v_username,
  3312. rec_ProFunPkg_name.name,
  3313. v_sql);
  3314. n_line_no:=n_line_no+1;
  3315. v_sql:='@'||lower(rec_ProFunPkg_name.name)||'.sql';
  3316. IFv_object_type='PROCEDURE'THEN
  3317. insert_rec(n_line_no,
  3318. v_object_type,
  3319. v_username,
  3320. 'START_PROCS',
  3321. v_sql);
  3322. ELSIFv_object_type='FUNCTION'THEN
  3323. insert_rec(n_line_no,
  3324. v_object_type,
  3325. v_username,
  3326. 'START_FUNCS',
  3327. v_sql);
  3328. ELSIFv_object_type='PACKAGE'orv_object_type='PACKAGEBODY'THEN
  3329. insert_rec(n_line_no,
  3330. v_object_type,
  3331. v_username,
  3332. 'START_PKGS',
  3333. v_sql);
  3334. n_line_no:=n_line_no+1;
  3335. v_sql:='@'||lower(rec_ProFunPkg_name.name)||'.haad.sql';
  3336. insert_rec(n_line_no,
  3337. v_object_type,
  3338. v_username,
  3339. 'START_PKG_HS',
  3340. v_sql);
  3341. n_line_no:=n_line_no+1;
  3342. v_sql:='@'||lower(rec_ProFunPkg_name.name)||'.body.sql';
  3343. insert_rec(n_line_no,
  3344. v_object_type,
  3345. v_username,
  3346. 'START_PKG_BS',
  3347. v_sql);
  3348. ELSIFv_object_type='TRIGGER'THEN
  3349. insert_rec(n_line_no,
  3350. v_object_type,
  3351. v_username,
  3352. 'START_TRIS',
  3353. v_sql);
  3354. ELSIFv_object_type='TYPE'orv_object_type='TYPEBODY'THEN
  3355. insert_rec(n_line_no,
  3356. v_object_type,
  3357. v_username,
  3358. 'START_TYPES',
  3359. v_sql);
  3360. n_line_no:=n_line_no+1;
  3361. v_sql:='@'||lower(rec_ProFunPkg_name.name)||'.haad.sql';
  3362. insert_rec(n_line_no,
  3363. v_object_type,
  3364. v_username,
  3365. 'START_TYPE_HS',
  3366. v_sql);
  3367. n_line_no:=n_line_no+1;
  3368. v_sql:='@'||lower(rec_ProFunPkg_name.name)||'.body.sql';
  3369. insert_rec(n_line_no,
  3370. v_object_type,
  3371. v_username,
  3372. 'START_TYPE_BS',
  3373. v_sql);
  3374. ENDIF;
  3375. n_line_no:=n_line_no+1;
  3376. v_sql:='';
  3377. insert_rec(n_line_no,
  3378. 'START_PROCS',
  3379. v_username,
  3380. rec_ProFunPkg_name.name,
  3381. v_sql);
  3382. n_line_no:=n_line_no+1;
  3383. v_sql:='';
  3384. insert_rec(n_line_no,
  3385. v_object_type,
  3386. v_username,
  3387. rec_ProFunPkg_name.name,
  3388. v_sql);
  3389. n_line_no:=n_line_no+1;
  3390. IFrec_ProFunPkg_name.type='PACKAGE'THEN
  3391. FORrec_ProFunPkg_codeINcur_ProFunPkg_code(rec_ProFunPkg_name.name,
  3392. rec_ProFunPkg_name.type||
  3393. 'BODY')LOOP
  3394. IFrec_ProFunPkg_code.line=1THEN
  3395. v_sql:='CREATEORREPLACE'||rec_ProFunPkg_code.text;
  3396. ELSE
  3397. v_sql:=rec_ProFunPkg_code.text;
  3398. ENDIF;
  3399. insert_rec(n_line_no,
  3400. rec_ProFunPkg_name.type||'BODY',
  3401. v_username,
  3402. rec_ProFunPkg_name.name,
  3403. v_sql);
  3404. n_line_no:=n_line_no+1;
  3405. ENDLOOP;
  3406. v_sql:='/';
  3407. insert_rec(n_line_no,
  3408. rec_ProFunPkg_name.type||'BODY',
  3409. v_username,
  3410. rec_ProFunPkg_name.name,
  3411. v_sql);
  3412. n_line_no:=n_line_no+1;
  3413. v_sql:='';
  3414. insert_rec(n_line_no,
  3415. rec_ProFunPkg_name.type||'BODY',
  3416. v_username,
  3417. rec_ProFunPkg_name.name,
  3418. v_sql);
  3419. n_line_no:=n_line_no+1;
  3420. ENDIF;
  3421. v_sql:='--~~~~~~~~~~~~~~~~~~~~'||rec_ProFunPkg_name.type||
  3422. ':'||rec_ProFunPkg_name.name||
  3423. 'END;~~~~~~~~~~~~~~~~~~~~';
  3424. insert_rec(n_line_no,
  3425. v_object_type,
  3426. v_username,
  3427. rec_ProFunPkg_name.name,
  3428. v_sql);
  3429. n_line_no:=n_line_no+1;
  3430. v_sql:='';
  3431. insert_rec(n_line_no,
  3432. v_object_type,
  3433. v_username,
  3434. rec_ProFunPkg_name.name,
  3435. v_sql);
  3436. n_line_no:=n_line_no+1;
  3437. ENDIF;
  3438. IFv_object_type='PROCEDURE'THEN
  3439. v_sql:='spool'||v_file_path||'procedures'||v_notion||
  3440. 'separ_files'||v_notion||
  3441. lower(rec_ProFunPkg_name.name)||'.sql';
  3442. insert_rec(n_line_no,
  3443. 'SEPAR_PROCS',
  3444. v_username,
  3445. rec_ProFunPkg_name.name,
  3446. v_sql);
  3447. n_line_no:=n_line_no+1;
  3448. v_sql:='SELECTrtrim(sql_text)FROMtemp_for_pkg_gen_sql4000_temp';
  3449. insert_rec(n_line_no,
  3450. 'SEPAR_PROCS',
  3451. v_username,
  3452. rec_ProFunPkg_name.name,
  3453. v_sql);
  3454. n_line_no:=n_line_no+1;
  3455. v_sql:='WHEREOBJECT_TYPE=''PROCEDURE''ANDOBJECT_NAME='''||
  3456. rec_ProFunPkg_name.name||'''ORDERBYline_no;';
  3457. insert_rec(n_line_no,
  3458. 'SEPAR_PROCS',
  3459. v_username,
  3460. rec_ProFunPkg_name.name,
  3461. v_sql);
  3462. n_line_no:=n_line_no+1;
  3463. v_sql:='spooloff';
  3464. insert_rec(n_line_no,
  3465. 'SEPAR_PROCS',
  3466. v_username,
  3467. rec_ProFunPkg_name.name,
  3468. v_sql);
  3469. n_line_no:=n_line_no+1;
  3470. v_sql:='';
  3471. insert_rec(n_line_no,
  3472. 'SEPAR_PROCS',
  3473. v_username,
  3474. rec_ProFunPkg_name.name,
  3475. v_sql);
  3476. n_line_no:=n_line_no+1;
  3477. ELSIFv_object_type='FUNCTION'THEN
  3478. v_sql:='spool'||v_file_path||'functions'||v_notion||
  3479. 'separ_files'||v_notion||
  3480. lower(rec_ProFunPkg_name.name)||'.sql';
  3481. insert_rec(n_line_no,
  3482. 'SEPAR_FUNCS',
  3483. v_username,
  3484. rec_ProFunPkg_name.name,
  3485. v_sql);
  3486. n_line_no:=n_line_no+1;
  3487. v_sql:='SELECTrtrim(sql_text)FROMtemp_for_pkg_gen_sql4000_temp';
  3488. insert_rec(n_line_no,
  3489. 'SEPAR_FUNCS',
  3490. v_username,
  3491. rec_ProFunPkg_name.name,
  3492. v_sql);
  3493. n_line_no:=n_line_no+1;
  3494. v_sql:='WHEREOBJECT_TYPE=''FUNCTION''ANDOBJECT_NAME='''||
  3495. rec_ProFunPkg_name.name||'''ORDERBYline_no;';
  3496. insert_rec(n_line_no,
  3497. 'SEPAR_FUNCS',
  3498. v_username,
  3499. rec_ProFunPkg_name.name,
  3500. v_sql);
  3501. n_line_no:=n_line_no+1;
  3502. v_sql:='spooloff';
  3503. insert_rec(n_line_no,
  3504. 'SEPAR_FUNCS',
  3505. v_username,
  3506. rec_ProFunPkg_name.name,
  3507. v_sql);
  3508. n_line_no:=n_line_no+1;
  3509. v_sql:='';
  3510. insert_rec(n_line_no,
  3511. 'SEPAR_FUNCS',
  3512. v_username,
  3513. rec_ProFunPkg_name.name,
  3514. v_sql);
  3515. n_line_no:=n_line_no+1;
  3516. ELSIFv_object_type='TRIGGER'THEN
  3517. v_sql:='spool'||v_file_path||'triggers'||v_notion||
  3518. 'separ_files'||v_notion||
  3519. lower(rec_ProFunPkg_name.name)||'.sql';
  3520. insert_rec(n_line_no,
  3521. 'SEPAR_TRIS',
  3522. v_username,
  3523. rec_ProFunPkg_name.name,
  3524. v_sql);
  3525. n_line_no:=n_line_no+1;
  3526. v_sql:='SELECTrtrim(sql_text)FROMtemp_for_pkg_gen_sql4000_temp';
  3527. insert_rec(n_line_no,
  3528. 'SEPAR_TRIS',
  3529. v_username,
  3530. rec_ProFunPkg_name.name,
  3531. v_sql);
  3532. n_line_no:=n_line_no+1;
  3533. v_sql:='WHEREOBJECT_TYPE=''TRIGGER''ANDOBJECT_NAME='''||
  3534. rec_ProFunPkg_name.name||'''ORDERBYline_no;';
  3535. insert_rec(n_line_no,
  3536. 'SEPAR_TRIS',
  3537. v_username,
  3538. rec_ProFunPkg_name.name,
  3539. v_sql);
  3540. n_line_no:=n_line_no+1;
  3541. v_sql:='spooloff';
  3542. insert_rec(n_line_no,
  3543. 'SEPAR_TRIS',
  3544. v_username,
  3545. rec_ProFunPkg_name.name,
  3546. v_sql);
  3547. n_line_no:=n_line_no+1;
  3548. v_sql:='';
  3549. insert_rec(n_line_no,
  3550. 'SEPAR_TRIS',
  3551. v_username,
  3552. rec_ProFunPkg_name.name,
  3553. v_sql);
  3554. n_line_no:=n_line_no+1;
  3555. ELSIFv_object_type='PACKAGE'THEN
  3556. --生成可以将包头放在一个文件中的批处理文件
  3557. v_sql:='spool'||v_file_path||'packages'||v_notion||
  3558. 'separ_headbobdy_file'||v_notion||
  3559. lower(rec_ProFunPkg_name.name)||'.head.sql;';
  3560. insert_rec(n_line_no,
  3561. 'SEPAR_PKG_HEADS',
  3562. v_username,
  3563. rec_ProFunPkg_name.name,
  3564. v_sql);
  3565. n_line_no:=n_line_no+1;
  3566. v_sql:='SELECTrtrim(sql_text)FROMtemp_for_pkg_gen_sql4000_temp';
  3567. insert_rec(n_line_no,
  3568. 'SEPAR_PKG_HEADS',
  3569. v_username,
  3570. rec_ProFunPkg_name.name,
  3571. v_sql);
  3572. n_line_no:=n_line_no+1;
  3573. v_sql:='WHEREOBJECT_TYPE=''PACKAGE''ANDOBJECT_NAME='''||
  3574. rec_ProFunPkg_name.name||'''ORDERBYline_no;';
  3575. insert_rec(n_line_no,
  3576. 'SEPAR_PKG_HEADS',
  3577. v_username,
  3578. rec_ProFunPkg_name.name,
  3579. v_sql);
  3580. n_line_no:=n_line_no+1;
  3581. v_sql:='spooloff';
  3582. insert_rec(n_line_no,
  3583. 'SEPAR_PKG_HEADS',
  3584. v_username,
  3585. rec_ProFunPkg_name.name,
  3586. v_sql);
  3587. n_line_no:=n_line_no+1;
  3588. v_sql:='';
  3589. insert_rec(n_line_no,
  3590. 'SEPAR_PKG_HEADS',
  3591. v_username,
  3592. rec_ProFunPkg_name.name,
  3593. v_sql);
  3594. n_line_no:=n_line_no+1;
  3595. --生成可以将包体放在一个文件中的批处理文件
  3596. v_sql:='spool'||v_file_path||'packages'||v_notion||
  3597. 'separ_headbobdy_file'||v_notion||
  3598. lower(rec_ProFunPkg_name.name)||'.body.sql;';
  3599. insert_rec(n_line_no,
  3600. 'SEPAR_PKG_BODYS',
  3601. v_username,
  3602. rec_ProFunPkg_name.name,
  3603. v_sql);
  3604. n_line_no:=n_line_no+1;
  3605. v_sql:='SELECTrtrim(sql_text)FROMtemp_for_pkg_gen_sql4000_temp';
  3606. insert_rec(n_line_no,
  3607. 'SEPAR_PKG_BODYS',
  3608. v_username,
  3609. rec_ProFunPkg_name.name,
  3610. v_sql);
  3611. n_line_no:=n_line_no+1;
  3612. v_sql:='WHEREOBJECT_TYPE=''PACKAGEBODY''ANDOBJECT_NAME='''||
  3613. rec_ProFunPkg_name.name||'''ORDERBYline_no;';
  3614. insert_rec(n_line_no,
  3615. 'SEPAR_PKG_BODYS',
  3616. v_username,
  3617. rec_ProFunPkg_name.name,
  3618. v_sql);
  3619. n_line_no:=n_line_no+1;
  3620. v_sql:='spooloff;';
  3621. insert_rec(n_line_no,
  3622. 'SEPAR_PKG_BODYS',
  3623. v_username,
  3624. rec_ProFunPkg_name.name,
  3625. v_sql);
  3626. n_line_no:=n_line_no+1;
  3627. v_sql:='';
  3628. insert_rec(n_line_no,
  3629. 'SEPAR_PKG_BODYS',
  3630. v_username,
  3631. rec_ProFunPkg_name.name,
  3632. v_sql);
  3633. n_line_no:=n_line_no+1;
  3634. v_sql:='';
  3635. insert_rec(n_line_no,
  3636. 'SEPAR_PKG_HEADS',
  3637. v_username,
  3638. rec_ProFunPkg_name.name,
  3639. v_sql);
  3640. n_line_no:=n_line_no+1;
  3641. --thepackageheadandpackagebodyallowinthesamefile
  3642. v_sql:='spool'||v_file_path||'packages'||v_notion||
  3643. 'separ_files'||v_notion||
  3644. lower(rec_ProFunPkg_name.name)||'.sql;';
  3645. insert_rec(n_line_no,
  3646. 'SEPAR_PKGS',
  3647. v_username,
  3648. rec_ProFunPkg_name.name,
  3649. v_sql);
  3650. n_line_no:=n_line_no+1;
  3651. v_sql:='SELECTrtrim(sql_text)FROMtemp_for_pkg_gen_sql4000_temp';
  3652. insert_rec(n_line_no,
  3653. 'SEPAR_PKGS',
  3654. v_username,
  3655. rec_ProFunPkg_name.name,
  3656. v_sql);
  3657. n_line_no:=n_line_no+1;
  3658. v_sql:='WHEREOBJECT_TYPElike''%PACKAGE%''ANDOBJECT_NAME='''||
  3659. rec_ProFunPkg_name.name||'''ORDERBYline_no;';
  3660. insert_rec(n_line_no,
  3661. 'SEPAR_PKGS',
  3662. v_username,
  3663. rec_ProFunPkg_name.name,
  3664. v_sql);
  3665. n_line_no:=n_line_no+1;
  3666. v_sql:='spooloff;';
  3667. insert_rec(n_line_no,
  3668. 'SEPAR_PKGS',
  3669. v_username,
  3670. rec_ProFunPkg_name.name,
  3671. v_sql);
  3672. n_line_no:=n_line_no+1;
  3673. v_sql:='';
  3674. insert_rec(n_line_no,
  3675. 'SEPAR_PKGS',
  3676. v_username,
  3677. rec_ProFunPkg_name.name,
  3678. v_sql);
  3679. n_line_no:=n_line_no+1;
  3680. ENDIF;
  3681. ENDLOOP;
  3682. --生成批量运行生成各个文件的批文件
  3683. v_sql:='spool'||v_file_path||'procedures'||v_notion||
  3684. 'separ_files'||v_notion||'start_procs.sql';
  3685. insert_rec(n_line_no,'SEPAR_PROCS',v_username,'SEPAR_PROCS',v_sql);
  3686. n_line_no:=n_line_no+1;
  3687. v_sql:='SELECTrtrim(sql_text)FROMtemp_for_pkg_gen_sql4000_temp';
  3688. insert_rec(n_line_no,'SEPAR_PROCS',v_username,'SEPAR_PROCS',v_sql);
  3689. n_line_no:=n_line_no+1;
  3690. v_sql:='WHEREOBJECT_TYPE=''PROCEDURE''ANDOBJECT_NAME=''START_PROCS''ORDERBYline_no;';
  3691. insert_rec(n_line_no,'SEPAR_PROCS',v_username,'SEPAR_PROCS',v_sql);
  3692. n_line_no:=n_line_no+1;
  3693. v_sql:='spooloff';
  3694. insert_rec(n_line_no,'SEPAR_PROCS',v_username,'SEPAR_PROCS',v_sql);
  3695. n_line_no:=n_line_no+1;
  3696. v_sql:='';
  3697. insert_rec(n_line_no,'SEPAR_PROCS',v_username,'SEPAR_PROCS',v_sql);
  3698. n_line_no:=n_line_no+1;
  3699. v_sql:='spool'||v_file_path||'functions'||v_notion||
  3700. 'separ_files'||v_notion||'start_funcs.sql';
  3701. insert_rec(n_line_no,'SEPAR_FUNCS',v_username,'SEPAR_FUNCS',v_sql);
  3702. n_line_no:=n_line_no+1;
  3703. v_sql:='SELECTrtrim(sql_text)FROMtemp_for_pkg_gen_sql4000_temp';
  3704. insert_rec(n_line_no,'SEPAR_FUNCS',v_username,'SEPAR_FUNCS',v_sql);
  3705. n_line_no:=n_line_no+1;
  3706. v_sql:='WHEREOBJECT_TYPE=''FUNCTION''ANDOBJECT_NAME=''START_FUNCS''ORDERBYline_no;';
  3707. insert_rec(n_line_no,'SEPAR_FUNCS',v_username,'SEPAR_FUNCS',v_sql);
  3708. n_line_no:=n_line_no+1;
  3709. v_sql:='spooloff';
  3710. insert_rec(n_line_no,'SEPAR_FUNCS',v_username,'SEPAR_FUNCS',v_sql);
  3711. n_line_no:=n_line_no+1;
  3712. v_sql:='';
  3713. insert_rec(n_line_no,'SEPAR_FUNCS',v_username,'SEPAR_FUNCS',v_sql);
  3714. n_line_no:=n_line_no+1;
  3715. v_sql:='spool'||v_file_path||'triggers'||v_notion||
  3716. 'separ_files'||v_notion||'start_tris.sql';
  3717. insert_rec(n_line_no,'SEPAR_TRIS',v_username,'SEPAR_TRIS',v_sql);
  3718. n_line_no:=n_line_no+1;
  3719. v_sql:='SELECTrtrim(sql_text)FROMtemp_for_pkg_gen_sql4000_temp';
  3720. insert_rec(n_line_no,'SEPAR_TRIS',v_username,'SEPAR_TRIS',v_sql);
  3721. n_line_no:=n_line_no+1;
  3722. v_sql:='WHEREOBJECT_TYPE=''TRIGGER''ANDOBJECT_NAME=''SEPAR_TRIS''ORDERBYline_no;';
  3723. insert_rec(n_line_no,'SEPAR_TRIS',v_username,'SEPAR_TRIS',v_sql);
  3724. n_line_no:=n_line_no+1;
  3725. v_sql:='spooloff';
  3726. insert_rec(n_line_no,'SEPAR_TRIS',v_username,'SEPAR_TRIS',v_sql);
  3727. n_line_no:=n_line_no+1;
  3728. v_sql:='';
  3729. insert_rec(n_line_no,'SEPAR_TRIS',v_username,'SEPAR_TRIS',v_sql);
  3730. n_line_no:=n_line_no+1;
  3731. v_sql:='spool'||v_file_path||'packages'||v_notion||
  3732. 'separ_headbobdy_file'||v_notion||'start_pkg_heads.sql;';
  3733. insert_rec(n_line_no,
  3734. 'SEPAR_PKG_HEADS',
  3735. v_username,
  3736. 'SEPAR_PKG_HEADS',
  3737. v_sql);
  3738. n_line_no:=n_line_no+1;
  3739. v_sql:='SELECTrtrim(sql_text)FROMtemp_for_pkg_gen_sql4000_temp';
  3740. insert_rec(n_line_no,
  3741. 'SEPAR_PKG_HEADS',
  3742. v_username,
  3743. 'SEPAR_PKG_HEADS',
  3744. v_sql);
  3745. n_line_no:=n_line_no+1;
  3746. v_sql:='WHEREOBJECT_TYPE=''PACKAGE''ANDOBJECT_NAME=''START_PKG_HS''ORDERBYline_no;';
  3747. insert_rec(n_line_no,
  3748. 'SEPAR_PKG_HEADS',
  3749. v_username,
  3750. 'SEPAR_PKG_HEADS',
  3751. v_sql);
  3752. n_line_no:=n_line_no+1;
  3753. v_sql:='spooloff';
  3754. insert_rec(n_line_no,
  3755. 'SEPAR_PKG_HEADS',
  3756. v_username,
  3757. 'SEPAR_PKG_HEADS',
  3758. v_sql);
  3759. n_line_no:=n_line_no+1;
  3760. v_sql:='';
  3761. insert_rec(n_line_no,
  3762. 'SEPAR_PKG_HEADS',
  3763. v_username,
  3764. 'SEPAR_PKG_HEADS',
  3765. v_sql);
  3766. n_line_no:=n_line_no+1;
  3767. v_sql:='spool'||v_file_path||'packages'||v_notion||
  3768. 'separ_headbobdy_file'||v_notion||'start_pkg_bodys.sql;';
  3769. insert_rec(n_line_no,
  3770. 'SEPAR_PKG_BODYS',
  3771. v_username,
  3772. 'SEPAR_PKG_BODYS',
  3773. v_sql);
  3774. n_line_no:=n_line_no+1;
  3775. v_sql:='SELECTrtrim(sql_text)FROMtemp_for_pkg_gen_sql4000_temp';
  3776. insert_rec(n_line_no,
  3777. 'SEPAR_PKG_BODYS',
  3778. v_username,
  3779. 'SEPAR_PKG_BODYS',
  3780. v_sql);
  3781. n_line_no:=n_line_no+1;
  3782. v_sql:='WHEREOBJECT_TYPE=''PACKAGE''ANDOBJECT_NAME=''START_PKG_BS''ORDERBYline_no;';
  3783. insert_rec(n_line_no,
  3784. 'SEPAR_PKG_BODYS',
  3785. v_username,
  3786. 'SEPAR_PKG_BODYS',
  3787. v_sql);
  3788. n_line_no:=n_line_no+1;
  3789. v_sql:='spooloff';
  3790. insert_rec(n_line_no,
  3791. 'SEPAR_PKG_BODYS',
  3792. v_username,
  3793. 'SEPAR_PKG_BODYS',
  3794. v_sql);
  3795. n_line_no:=n_line_no+1;
  3796. v_sql:='';
  3797. insert_rec(n_line_no,'SEPAR_PKGS',v_username,'SEPAR_PKGS',v_sql);
  3798. n_line_no:=n_line_no+1;
  3799. v_sql:='spool'||v_file_path||'packages'||v_notion||
  3800. 'separ_files'||v_notion||'start_pkgs.sql;';
  3801. insert_rec(n_line_no,'SEPAR_PKGS',v_username,'SEPAR_PKGS',v_sql);
  3802. n_line_no:=n_line_no+1;
  3803. v_sql:='SELECTrtrim(sql_text)FROMtemp_for_pkg_gen_sql4000_temp';
  3804. insert_rec(n_line_no,'SEPAR_PKGS',v_username,'SEPAR_PKGS',v_sql);
  3805. n_line_no:=n_line_no+1;
  3806. v_sql:='WHEREOBJECT_TYPE=''PACKAGE''ANDOBJECT_NAME=''START_PKGS''ORDERBYline_no;';
  3807. insert_rec(n_line_no,'SEPAR_PKGS',v_username,'SEPAR_PKGS',v_sql);
  3808. n_line_no:=n_line_no+1;
  3809. v_sql:='spooloff';
  3810. insert_rec(n_line_no,'SEPAR_PKGS',v_username,'SEPAR_PKGS',v_sql);
  3811. n_line_no:=n_line_no+1;
  3812. v_sql:='';
  3813. insert_rec(n_line_no,'SEPAR_PKGS',v_username,'SEPAR_PKGS',v_sql);
  3814. n_line_no:=n_line_no+1;
  3815. COMMIT;
  3816. END;
  3817. ENDpkg_gen_user_sql;
  3818. /
  3819. showerr
  3820. setechooff
  3821. setfeedbackoff
  3822. setnewpagenone
  3823. setpagesize0
  3824. setverifyoff
  3825. setpagesize0
  3826. settermoff
  3827. settrimson
  3828. setlinesize5005
  3829. setheadingoff
  3830. settimingoff
  3831. setverifyoff
  3832. setnumwidth38
  3833. --生成start
  3834. execpkg_gen_user_sql.pro_gen_start_sql('&&file_dic')
  3835. spool&&file_dic/start_all.sql
  3836. SELECTrtrim(sql_text)
  3837. FROMtemp_for_pkg_gen_sql2000_temp
  3838. WHEREOBJECT_TYPE='START_SQL'
  3839. ORDERBYline_no;
  3840. spooloff
  3841. --生成创建表的sql语句
  3842. execpkg_gen_user_sql.pro_tab_sql_tab8('F','T','F','T');
  3843. spool&&file_dic/cre_tables.sql
  3844. SELECTrtrim(sql_text)
  3845. FROMtemp_for_pkg_gen_sql2000_temp
  3846. WHEREOBJECT_TYPE='TABLE_8'
  3847. ORDERBYline_no;
  3848. spooloff
  3849. --生成创建索引的sql语句
  3850. execpkg_gen_user_sql.pro_indx_sql('F','T','F','T')
  3851. spool&&file_dic/cre_indexes.sql
  3852. SELECTsql_text
  3853. FROMtemp_for_pkg_gen_sql2000_temp
  3854. WHEREOBJECT_TYPE='INDEX'
  3855. ORDERBYline_no;
  3856. spooloff
  3857. --生成创建主键约束的sql语句
  3858. execpkg_gen_user_sql.pro_con_sql('P','F','T','T','T');
  3859. spool&&file_dic/cre_pri_constraint.sql
  3860. SELECTrtrim(sql_text)
  3861. FROMtemp_for_pkg_gen_sql2000_temp
  3862. WHEREOBJECT_TYPE='CONSTRAINT'
  3863. ORDERBYline_no;
  3864. spooloff
  3865. --生成创建出主键约束的其它约束的sql语句
  3866. execpkg_gen_user_sql.pro_con_sql('NOT_PRI','F','T','F','T');
  3867. spool&&file_dic/cre_not_pri_constraint.sql
  3868. SELECTrtrim(sql_text)
  3869. FROMtemp_for_pkg_gen_sql2000_temp
  3870. WHEREOBJECT_TYPE='CONSTRAINT'
  3871. ORDERBYline_no;
  3872. spooloff
  3873. --生成创建所有约束的sql语句
  3874. execpkg_gen_user_sql.pro_con_sql('A','F','T','T','T');
  3875. spool&&file_dic/cre_constraints.sql
  3876. SELECTrtrim(sql_text)
  3877. FROMtemp_for_pkg_gen_sql2000_temp
  3878. WHEREOBJECT_TYPE='CONSTRAINT'
  3879. ORDERBYline_no;
  3880. spooloff
  3881. --生成重建索引的sql语句
  3882. execpkg_gen_user_sql.pro_reb_indx_sql('F','F')
  3883. spool&&file_dic/reb_indexes.sql
  3884. SELECTsql_text
  3885. FROMtemp_for_pkg_gen_sql2000_temp
  3886. WHEREOBJECT_TYPE='REBUILD_INDEX'
  3887. ORDERBYline_no;
  3888. spooloff
  3889. --生成创建视图的sql语句
  3890. execpkg_gen_user_sql.pro_view_sql('F','T','T');
  3891. spool&&file_dic/cre_views.sql
  3892. SELECTsql_text
  3893. FROMtemp_for_pkg_gen_sql4000_temp
  3894. WHEREOBJECT_TYPE='VIEW'
  3895. ORDERBYline_no;
  3896. spooloff
  3897. --生成创建序列的sql语句
  3898. execpkg_gen_user_sql.pro_seq_next_val_sql('F');
  3899. spool&&file_dic/cre_sequences.sql
  3900. SELECTsql_text
  3901. FROMtemp_for_pkg_gen_sql2000_temp
  3902. WHEREOBJECT_TYPE='SEQUENCE'
  3903. ORDERBYline_no;
  3904. spooloff
  3905. --生成创建初始序列的sql语句,每个序列的开始值为1
  3906. execpkg_gen_user_sql.pro_seq_init_val_sql('F');
  3907. spool&&file_dic/cre_sequences_init.sql
  3908. SELECTsql_text
  3909. FROMtemp_for_pkg_gen_sql2000_temp
  3910. WHEREOBJECT_TYPE='SEQUENCE_INIT'
  3911. ORDERBYline_no;
  3912. spooloff
  3913. --生成创建同义词的sql语句
  3914. execpkg_gen_user_sql.pro_synonym_sql('F')
  3915. spool&&file_dic/cre_synonyms.sql
  3916. SELECTrtrim(sql_text)
  3917. FROMtemp_for_pkg_gen_sql2000_temp
  3918. WHEREOBJECT_TYPE='SYNONYM'
  3919. ORDERBYline_no;
  3920. spooloff
  3921. --生成创建job的sql语句
  3922. execpkg_gen_user_sql.pro_job_sql('F')
  3923. spool&&file_dic/cre_jobs.sql
  3924. SELECTrtrim(sql_text)
  3925. FROMtemp_for_pkg_gen_sql4000_temp
  3926. WHEREOBJECT_TYPE='JOB'
  3927. ORDERBYline_no;
  3928. spooloff
  3929. --生成创建数据库链的sql语句
  3930. execpkg_gen_user_sql.pro_dl_sql('F')
  3931. spool&&file_dic/cre_db_links.sql
  3932. SELECTrtrim(sql_text)
  3933. FROMtemp_for_pkg_gen_sql2000_temp
  3934. WHEREOBJECT_TYPE='DL'
  3935. ORDERBYline_no;
  3936. spooloff
  3937. --生成创建角色的sql语句
  3938. execpkg_gen_user_sql.pro_role_sql('F')
  3939. spool&&file_dic/cre_roles.sql
  3940. SELECTrtrim(sql_text)
  3941. FROMtemp_for_pkg_gen_sql2000_temp
  3942. WHEREOBJECT_TYPE='ROLE'
  3943. ORDERBYline_no;
  3944. spooloff
  3945. --生成创建授权的sql语句
  3946. execpkg_gen_user_sql.pro_priv_sql('F')
  3947. spool&&file_dic/cre_privs.sql
  3948. SELECTrtrim(sql_text)
  3949. FROMtemp_for_pkg_gen_sql2000_temp
  3950. WHEREOBJECT_TYPE='PRIV'
  3951. ORDERBYline_no;
  3952. spooloff
  3953. --生成创建存储过程的sql语句,所有存储过程放在一个文件中
  3954. execpkg_gen_user_sql.pro_pkgprofuntri_sql('F','T','T','T','&&file_dic')
  3955. spool&&file_dic/procedures/procedures.sql
  3956. SELECTrtrim(sql_text)
  3957. FROMtemp_for_pkg_gen_sql4000_temp
  3958. WHEREOBJECT_TYPE='PROCEDURE'
  3959. ANDlower(rtrim(sql_text))notlike'@%.sql'
  3960. ORDERBYline_no;
  3961. spooloff
  3962. --生成创建函数的sql语句,所有函数放在一个文件中
  3963. spool&&file_dic/functions/functions.sql
  3964. SELECTrtrim(sql_text)
  3965. FROMtemp_for_pkg_gen_sql4000_temp
  3966. WHEREOBJECT_TYPE='FUNCTION'
  3967. ANDlower(rtrim(sql_text))notlike'@%.sql'
  3968. ORDERBYline_no;
  3969. spooloff
  3970. --生成创建包的sql语句,所有包放在一个文件中
  3971. spool&&file_dic/packages/packages.sql
  3972. SELECTrtrim(sql_text)
  3973. FROMtemp_for_pkg_gen_sql4000_temp
  3974. WHEREOBJECT_TYPElike'%PACKAGE%'
  3975. ANDlower(rtrim(sql_text))notlike'@%.sql'
  3976. ORDERBYline_no;
  3977. spooloff
  3978. --生成创建触发器的sql语句
  3979. spool&&file_dic/triggers/triggers.sql
  3980. SELECTrtrim(sql_text)
  3981. FROMtemp_for_pkg_gen_sql4000_temp
  3982. WHEREOBJECT_TYPE='TRIGGER'
  3983. ORDERBYline_no;
  3984. spooloff
  3985. --生成创建存储过程的sql语句,每个存储过程放在单独的文件中
  3986. spool&&file_dic/temp_sql/separ_pros.sql
  3987. SELECTrtrim(sql_text)
  3988. FROMtemp_for_pkg_gen_sql4000_temp
  3989. WHEREOBJECT_TYPE='SEPAR_PROCS'
  3990. ORDERBYline_no;
  3991. spooloff
  3992. @&&file_dic/temp_sql/separ_pros.sql
  3993. --生成创建函数的sql语句,每个函数放在单独的文件中
  3994. spool&&file_dic/temp_sql/separ_funcs.sql
  3995. SELECTrtrim(sql_text)
  3996. FROMtemp_for_pkg_gen_sql4000_temp
  3997. WHEREOBJECT_TYPE='SEPAR_FUNCS'
  3998. ORDERBYline_no;
  3999. spooloff
  4000. @&&file_dic/temp_sql/separ_funcs.sql
  4001. --生成创建包的sql语句,每个包放在单独的文件中
  4002. spool&&file_dic/temp_sql/separ_pkgs.sql
  4003. SELECTrtrim(sql_text)
  4004. FROMtemp_for_pkg_gen_sql4000_temp
  4005. WHEREOBJECT_TYPElike'%SEPAR_PKGS%'
  4006. ORDERBYline_no;
  4007. spooloff
  4008. @&&file_dic/temp_sql/separ_pkgs.sql
  4009. --生成创建存储过程的sql语句,每个包的声明与包体各放在单独的文件中
  4010. spool&&file_dic/temp_sql/separ_hb_pkgs.sql
  4011. SELECTrtrim(sql_text)
  4012. FROMtemp_for_pkg_gen_sql4000_temp
  4013. WHEREOBJECT_TYPEin('SEPAR_PKG_HEADS','SEPAR_PKG_BODYS')
  4014. ORDERBYobject_name,OBJECT_TYPEdesc,line_no;
  4015. spooloff
  4016. @&&file_dic/temp_sql/separ_hb_pkgs.sql
  4017. --生成创建触发器的sql语句,每个触发器放在单独的文件中
  4018. spool&&file_dic/temp_sql/separ_tris.sql
  4019. SELECTrtrim(sql_text)
  4020. FROMtemp_for_pkg_gen_sql4000_temp
  4021. WHEREOBJECT_TYPE='SEPAR_TRIS'
  4022. ORDERBYline_no;
  4023. spooloff
  4024. @&&file_dic/temp_sql/separ_tris.sql
  4025. setechoon
  4026. setfeedbackon
  4027. setnewpage1
  4028. setpagesize500
  4029. setlinesize80
  4030. setverifyon
  4031. settermon
  4032. settrimson
  4033. setlinesize600
  4034. setheadingon
  4035. settimingoff
  4036. setverifyon
  4037. setnumwidth15
  4038. droptabletemp_for_pkg_gen_sql2000_temp;
  4039. droptabletemp_for_pkg_gen_sql4000_temp;
  4040. droppackagepkg_gen_user_sql;
来自: http://www.oracle.com.cn/viewthread.php?tid=69847&extra=page%3D1%26amp%3Bfilter%3Ddigest
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值