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

 

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

前言:
  这是我用很长时间才写的存储包,其间经历了多次修改,以适应多种情况,今将其贡献出来,如果能读懂这个存储包,恭喜你,你的oracle知识已经达到一定程度了,而且这不失为一个学习oracle存储过程的模板,掌握它之后你可以自如的写存储包,存储过程,和函数了。

  在我的实际工作中我发现它的功能很强,可以生成我们常用的对象的创建语句,这在很多情况下比较好用
1。想导出创建用户下的对象的sql语句。
2。有时我们用copy命令与create table as .... 命令在2个数据库之间建立一个用户的所有数据的拷贝时,只能拷贝数据,而如各个约束,索引则不能导过来,此时,该脚本生成的sql语句正好可以弥补这一缺点。

不好意思独享该脚本,共享出来,忘大家共同进步。

版权所有人: 徐玉金

备注:用户可以根据实际需要修改、使用、发布该脚本,但是不能修改版权所有人


适用的数据库:8i, 9i数据库下该脚本通用

功能:导出一个用户的数据结构,包括表、视图、索引、约束、存储过程、触发器、函数、序列等等的定义,并且每个定义为一个文件
       导出的各个对象的定义格式比较规范。
       如表的定义为:
        prompt  Create Table BBNACTIVEHISTORY
        CREATE TABLE test(
                USERID                        VARCHAR2(20)        NOT NULL,
                SPUSERID                VARCHAR2(30)        NOT NULL,
                PRODUCTID                VARCHAR2(20)        NOT NULL,
                GAMETYPE                NUMBER        NOT NULL,
                STARTTIME                DATE        NOT NULL,
                CHARGED                        CHAR(1)        default        'N'                NOT NULL
        );
      
      每个存储过程有多个参数,可以控制输出何种形式的内容,如可以只生成删除表的sql,可以在生成的创建表与索引的语句上加上storage子句等等。

运行 user_dll_sql.sql的准备工作:

1.  修改win_mkdir.bat文件,以便生成存放生成脚本的基本目录及其子目录
        win_mkdir.bat文件生成上面所需要的所有目录
        打开win_mkdir.bat文件,修改BASE_DIC变量的值,如c:/temp/,该目录是存放生成的脚本文件的基本目录
       
       
2.        运行 win_mkdir.bat文件创建必要的目录

3.        用sql*plus以想导出数据结构的用户登陆到数据库
        运行user_dll_sql.sql 生成文件的路径文件,生成所有的ddl语句
        运行文件时,将存放生成脚本的基本目录作为参数(与步骤1改的基本目录一样)传入, ?要根据需要改为实际的目录
        SQL> @?/user_ddl_sql.sql c:/temp/
       

说明:
        运行win_mkdir.bat,文件后,会自动在生成脚本的基本目录下产生如下目录:
        procedures, functions, triggers, packages, temp_sql.
        每个目录的作用如下:
        procedures: 该目录存放存储过程, 有子目录separ_files, 该目录下的每个文件都是一个存储过程的源代码
        functions: 该目录存放函数, 有子目录separ_files, 该目录下的每个文件都是一个函数的源代码
        triggers: 该目录存放触发器, 有子目录separ_files, 该目录下的每个文件都是一个触发器的源代码
        packages: 该目录存放包, 有子目录separ_files, 该目录下的每个文件都是一个包的源代码
                                                        有子目录separ_headbobdy_file, 该目录下的每个文件都是一个包的包头或包体的源代码
        temp_sql:存放生成的临时文件
  1. DEFINE file_dic=1
  2. CREATE TABLE temp_for_pkg_gen_sql4000_temp 
  3. (   line_no         NUMBER(38,0), 
  4.     object_type     VARCHAR2(30),
  5.     user_name       VARCHAR2(30),
  6.     object_name     VARCHAR2(200),
  7.     sql_text        VARCHAR2(4000)
  8. );
  9. -- synonym, job, db_link, role, user_type 
  10. CREATE TABLE temp_for_pkg_gen_sql2000_temp 
  11. (   line_no         NUMBER(38,0), 
  12.     object_type     VARCHAR2(30),
  13.     user_name       VARCHAR2(30),
  14.     object_name     VARCHAR2(200),
  15.     sql_text        VARCHAR2(2000)
  16. );
  17. DELETE temp_for_pkg_gen_sql4000_temp;
  18. DELETE temp_for_pkg_gen_sql2000_temp;
  19. COMMIT;
  20. CREATE OR REPLACE PACKAGE pkg_gen_user_sql AS
  21.   -- 产生start脚本
  22.   PROCEDURE pro_gen_start_sql(p_v_file_path VARCHAR2 default 'C:/');
  23.   FUNCTION fun_return_table_name_tab4(p_v_table_name  VARCHAR2,
  24.                                       p_n_col_max_len NUMBER) RETURN VARCHAR2;
  25.   FUNCTION fun_return_table_name_tab8(p_v_table_name  VARCHAR2,
  26.                                       p_n_col_max_len NUMBER) RETURN VARCHAR2;
  27.   -- generate sql for create tables;
  28.   PROCEDURE pro_tab_sql_tab4(p_v_gen_drop_sql        VARCHAR2 default 'T',
  29.                              p_v_gen_create_sql      VARCHAR2 default 'T',
  30.                              p_v_gen_store_clause    VARCHAR2 default 'T',
  31.                              p_v_display_prompt_info VARCHAR2 default 'T');
  32.   PROCEDURE pro_tab_sql_tab8(p_v_gen_drop_sql        VARCHAR2 default 'T',
  33.                              p_v_gen_create_sql      VARCHAR2 default 'T',
  34.                              p_v_gen_store_clause    VARCHAR2 default 'T',
  35.                              p_v_display_prompt_info VARCHAR2 default 'T');
  36.   PROCEDURE pro_con_sql(p_v_con_type            VARCHAR2 default 'ALL',
  37.                         p_v_gen_drop_sql        VARCHAR2 default 'T',
  38.                         p_v_gen_create_sql      VARCHAR2 default 'T',
  39.                         p_v_gen_null_chk        VARCHAR2 default 'T',
  40.                         p_v_display_prompt_info VARCHAR2 default 'T');
  41.   PROCEDURE pro_indx_sql(p_v_gen_drop_sql        VARCHAR2 default 'T',
  42.                          p_v_gen_create_sql      VARCHAR2 default 'T',
  43.                          p_v_gen_store_clause    VARCHAR2 default 'T',
  44.                          p_v_gen_ts_only         VARCHAR2 default 'F',
  45.                          p_v_display_prompt_info VARCHAR2 default 'T');
  46.   -- 重建索引
  47.   PROCEDURE pro_reb_indx_sql(p_v_gen_store_clause    VARCHAR2 default 'T',
  48.                              p_v_rebuild_online      VARCHAR2 default 'T',
  49.                              p_v_display_prompt_info VARCHAR2 default 'T');
  50.   PROCEDURE pro_view_sql(p_v_gen_drop_sql        VARCHAR2 default 'T',
  51.                          p_v_gen_create_sql      VARCHAR2 default 'T',
  52.                          p_v_display_prompt_info VARCHAR2 default 'T');
  53.   PROCEDURE pro_seq_max_val_sql(p_v_gen_drop_sql        VARCHAR2 default 'T',
  54.                                 p_v_gen_create_sql      VARCHAR2 default 'T',
  55.                                 p_v_display_prompt_info VARCHAR2 default 'T');
  56.   PROCEDURE pro_seq_next_val_sql(p_v_gen_drop_sql        VARCHAR2 default 'T',
  57.                                  p_v_gen_create_sql      VARCHAR2 default 'T',
  58.                                  p_v_display_prompt_info VARCHAR2 default 'T');
  59.   PROCEDURE pro_seq_init_val_sql(p_v_gen_drop_sql        VARCHAR2 default 'T',
  60.                                  p_v_gen_create_sql      VARCHAR2 default 'T',
  61.                                  p_v_display_prompt_info VARCHAR2 default 'T');
  62.   PROCEDURE pro_synonym_sql(p_v_gen_drop_sql        VARCHAR2 default 'T',
  63.                             p_v_gen_create_sql      VARCHAR2 default 'T',
  64.                             p_v_display_prompt_info VARCHAR2 default 'T');
  65.   PROCEDURE pro_job_sql(p_v_gen_drop_sql        VARCHAR2 default 'T',
  66.                         p_v_gen_create_sql      VARCHAR2 default 'T',
  67.                         p_v_display_prompt_info VARCHAR2 default 'T');
  68.   PROCEDURE pro_dl_sql(p_v_gen_drop_sql        VARCHAR2 default 'T',
  69.                        p_v_gen_create_sql      VARCHAR2 default 'T',
  70.                        p_v_display_prompt_info VARCHAR2 default 'T');
  71.   PROCEDURE pro_role_sql(p_v_gen_drop_sql        VARCHAR2 default 'T',
  72.                          p_v_gen_create_sql      VARCHAR2 default 'T',
  73.                          p_v_display_prompt_info VARCHAR2 default 'T');
  74.   PROCEDURE pro_priv_sql(p_v_gen_drop_sql        VARCHAR2 default 'T',
  75.                          p_v_gen_create_sql      VARCHAR2 default 'T',
  76.                          p_v_display_prompt_info VARCHAR2 default 'T');
  77.   PROCEDURE pro_pkgprofuntri_sql(p_v_gen_drop_sql        VARCHAR2 default 'T',
  78.                                  p_v_gen_create_sql      VARCHAR2 default 'T',
  79.                                  p_v_display_prompt_info VARCHAR2 default 'T',
  80.                                  p_v_separ_file          VARCHAR2 default 'T',
  81.                                  p_v_file_path           VARCHAR2 default 'C:/');
  82. END pkg_gen_user_sql;
  83. /
  84. show err
  85. show err
  86. CREATE OR REPLACE PACKAGE BODY pkg_gen_user_sql AS
  87.   PROCEDURE pro_gen_start_sql(p_v_file_path VARCHAR2 default 'C:/') AS
  88.     v_username    VARCHAR2(30);
  89.     v_object_type VARCHAR2(30);
  90.     n_line_no     NUMBER(100);
  91.     v_sql         VARCHAR2(2000);
  92.     v_prompt      VARCHAR2(30);
  93.     v_file_path   VARCHAR2(600);
  94.     v_notion      char(1);
  95.     PROCEDURE insert_rec(p_line_no     INTEGER,
  96.                          p_object_type VARCHAR2,
  97.                          p_user_name   VARCHAR2,
  98.                          p_view_name   VARCHAR2,
  99.                          p_string      VARCHAR2) IS
  100.     BEGIN
  101.       INSERT INTO temp_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.   
  111.     -- find the notion between the dictionary
  112.     IF instr(p_v_file_path, '/') > 0 THEN
  113.       v_notion := '/';
  114.     ELSE
  115.       v_notion := '/';
  116.     END IF;
  117.   
  118.     IF substr(v_file_path, length(v_file_path)) <> v_notion THEN
  119.       v_file_path := v_file_path || v_notion;
  120.     END IF;
  121.   
  122.     SELECT username INTO v_username FROM user_users;
  123.   
  124.     DELETE temp_for_pkg_gen_sql2000_temp WHERE object_type = v_object_type;
  125.     COMMIT;
  126.   
  127.     n_line_no := 1;
  128.   
  129.     v_sql := '@ ' || v_file_path || 'cre_tables.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.   
  133.     v_sql := '@ ' || v_file_path || 'cre_sequences.sql';
  134.     insert_rec(n_line_no, v_object_type, v_username, v_object_type, v_sql);
  135.     n_line_no := n_line_no + 1;
  136.   
  137.     v_sql := '@ ' || v_file_path || 'cre_synonyms.sql';
  138.     insert_rec(n_line_no, v_object_type, v_username, v_object_type, v_sql);
  139.     n_line_no := n_line_no + 1;
  140.   
  141.     v_sql := '@ ' || v_file_path || 'cre_views.sql';
  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.   
  145.     v_sql := '@ ' || v_file_path || 'functions/';
  146.     insert_rec(n_line_no, v_object_type, v_username, v_object_type, v_sql);
  147.     n_line_no := n_line_no + 1;
  148.   
  149.     v_sql := '@ ' || v_file_path || 'procedures/';
  150.     insert_rec(n_line_no, v_object_type, v_username, v_object_type, v_sql);
  151.     n_line_no := n_line_no + 1;
  152.   
  153.     v_sql := '@ ' || v_file_path || 'packages/';
  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.   
  157.     v_sql := '@ ' || v_file_path || 'triggers/';
  158.     insert_rec(n_line_no, v_object_type, v_username, v_object_type, v_sql);
  159.     n_line_no := n_line_no + 1;
  160.   
  161.     v_sql := '@ ' || v_file_path || 'cre_synonyms.sql';
  162.     insert_rec(n_line_no, v_object_type, v_username, v_object_type, v_sql);
  163.     n_line_no := n_line_no + 1;
  164.   
  165.     v_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.   
  169.     v_sql := '-- *****      import data ***** -- ';
  170.     insert_rec(n_line_no, v_object_type, v_username, v_object_type, v_sql);
  171.     n_line_no := n_line_no + 1;
  172.   
  173.     v_sql := '    ';
  174.     insert_rec(n_line_no, v_object_type, v_username, v_object_type, v_sql);
  175.     n_line_no := n_line_no + 1;
  176.   
  177.     v_sql := '@ ' || v_file_path || 'cre_indexes.sql';
  178.     insert_rec(n_line_no, v_object_type, v_username, v_object_type, v_sql);
  179.     n_line_no := n_line_no + 1;
  180.   
  181.     v_sql := '@ ' || v_file_path || 'cre_pri_constraint.sql';
  182.     insert_rec(n_line_no, v_object_type, v_username, v_object_type, v_sql);
  183.     n_line_no := n_line_no + 1;
  184.   
  185.     v_sql := '@ ' || v_file_path || 'cre_not_pri_constraint.sql';
  186.     insert_rec(n_line_no, v_object_type, v_username, v_object_type, v_sql);
  187.     n_line_no := n_line_no + 1;
  188.   
  189.     v_sql := '@ ' || v_file_path || 'cre_db_links.sql';
  190.     insert_rec(n_line_no, v_object_type, v_username, v_object_type, v_sql);
  191.     n_line_no := n_line_no + 1;
  192.   
  193.     COMMIT;
  194.   END;
  195.   FUNCTION fun_return_table_name_tab4(p_v_table_name  VARCHAR2,
  196.                                       p_n_col_max_len NUMBER) RETURN VARCHAR2 AS
  197.     v_table_name  VARCHAR2(100);
  198.     v_temp        VARCHAR2(100);
  199.     n_col_max_len NUMBER;
  200.   BEGIN
  201.     v_table_name  := trim(p_v_table_name);
  202.     n_col_max_len := p_n_col_max_len;
  203.     v_temp        := v_table_name;
  204.   
  205.     WHILE mod(length(v_temp), 4) <> 0 LOOP
  206.       v_temp := v_temp || ' ';
  207.     END LOOP;
  208.     IF mod(length(v_table_name), 4) <> 0 THEN
  209.       v_table_name := v_table_name || chr(9);
  210.     END IF;
  211.   
  212.     WHILE length(v_temp) < n_col_max_len LOOP
  213.       v_table_name := v_table_name || chr(9);
  214.       v_temp       := v_temp || '    ';
  215.     END LOOP;
  216.   
  217.     RETURN v_table_name;
  218.   END;
  219.   FUNCTION fun_return_table_name_tab8(p_v_table_name  VARCHAR2,
  220.                                       p_n_col_max_len NUMBER) RETURN VARCHAR2 AS
  221.     v_table_name  VARCHAR2(100);
  222.     v_temp        VARCHAR2(100);
  223.     n_col_max_len NUMBER;
  224.   BEGIN
  225.     v_table_name  := trim(p_v_table_name);
  226.     n_col_max_len := p_n_col_max_len;
  227.     v_temp        := v_table_name;
  228.   
  229.     WHILE mod(length(v_temp), 8) <> 0 LOOP
  230.       v_temp := v_temp || ' ';
  231.     END LOOP;
  232.     IF mod(length(v_table_name), 8) <> 0 THEN
  233.       v_table_name := v_table_name || chr(9);
  234.     END IF;
  235.   
  236.     WHILE length(v_temp) < n_col_max_len LOOP
  237.       v_table_name := v_table_name || chr(9);
  238.       v_temp       := v_temp || '        ';
  239.     END LOOP;
  240.   
  241.     RETURN v_table_name;
  242.   END;
  243.   PROCEDURE pro_tab_sql_tab4(p_v_gen_drop_sql        VARCHAR2 default 'T',
  244.                              p_v_gen_create_sql      VARCHAR2 default 'T',
  245.                              p_v_gen_store_clause    VARCHAR2 default 'T',
  246.                              p_v_display_prompt_info VARCHAR2 default 'T') AS
  247.     CURSOR cur_tables is
  248.       SELECT table_name,
  249.              tablespace_name,
  250.              pct_free,
  251.              pct_used,
  252.              ini_trans,
  253.              max_trans,
  254.              initial_extent,
  255.              next_extent,
  256.              min_extents,
  257.              max_extents,
  258.              pct_increase,
  259.              freelists,
  260.              freelist_groups,
  261.              buffer_pool,
  262.              decode(logging, 'YES''LOGGING''NOLOGGING') logging
  263.         FROM user_tables
  264.        WHERE lower(TABLE_NAME) NOT IN
  265.              ('temp_for_pkg_gen_sql2000_temp',
  266.               'temp_for_pkg_gen_sql4000_temp')
  267.        ORDER BY table_name;
  268.   
  269.     CURSOR cur_cols(t_name VARCHAR2) is
  270.       SELECT table_name,
  271.              column_name,
  272.              data_type,
  273.              data_length,
  274.              data_precision,
  275.              data_scale,
  276.              nullable,
  277.              data_default
  278.         FROM user_tab_columns
  279.        WHERE table_name = t_name
  280.        ORDER BY column_id;
  281.   
  282.     v_tab_name            VARCHAR2(40);
  283.     v_tabsp_name          VARCHAR2(40);
  284.     n_mpct_free           user_tables.pct_free%TYPE;
  285.     n_mpct_used           user_tables.pct_used%TYPE;
  286.     n_mini_trans          user_tables.ini_trans%TYPE;
  287.     n_mmax_trans          user_tables.max_trans%TYPE;
  288.     n_mini_ext            user_tables.initial_extent%TYPE;
  289.     n_mnext_ext           user_tables.next_extent%TYPE;
  290.     n_mmin_ext            user_tables.min_extents%TYPE;
  291.     n_mmax_ext            user_tables.max_extents%TYPE;
  292.     n_mpct_inc            user_tables.pct_increase%TYPE;
  293.     n_freelists           user_tables.freelists%TYPE;
  294.     n_freelist_groups     user_tables.freelist_groups%TYPE;
  295.     v_buffer_pool         user_tables.buffer_pool%TYPE;
  296.     v_logging             VARCHAR2(15);
  297.     col_name              VARCHAR2(40);
  298.     ct                    NUMBER := 0;
  299.     n_line_no             NUMBER := 0;
  300.     col_content           VARCHAR2(120);
  301.     n_col_max_len         NUMBER(100);
  302.     v_default_val         VARCHAR2(4000);
  303.     v_gen_drop_tab_sql    VARCHAR2(10);
  304.     v_gen_create_tab_sql  VARCHAR2(10);
  305.     v_gen_store_clause    VARCHAR2(10);
  306.     v_display_prompt_info VARCHAR2(10);
  307.     v_username            VARCHAR2(30);
  308.     v_sql                 VARCHAR2(2000);
  309.     n_position            NUMBER(60);
  310.     v_object_type         VARCHAR2(10);
  311.     v_prompt              VARCHAR2(10);
  312.     PROCEDURE insert_rec(p_line_no     INTEGER,
  313.                          p_object_type VARCHAR2,
  314.                          p_user_name   VARCHAR2,
  315.                          p_object_name VARCHAR2,
  316.                          p_string      VARCHAR2) IS
  317.     BEGIN
  318.       INSERT INTO temp_for_pkg_gen_sql2000_temp
  319.         (line_no, object_type, user_name, object_name, sql_text)
  320.       VALUES
  321.         (p_line_no, p_object_type, p_user_name, p_object_name, p_string);
  322.     END;
  323.   BEGIN
  324.     v_gen_drop_tab_sql    := p_v_gen_drop_sql;
  325.     v_gen_create_tab_sql  := p_v_gen_create_sql;
  326.     v_gen_store_clause    := p_v_gen_store_clause;
  327.     v_display_prompt_info := p_v_display_prompt_info;
  328.     v_prompt              := '-- prompt ';
  329.     v_object_type         := 'TABLE_4';
  330.     n_line_no             := 1;
  331.   
  332.     SELECT username INTO v_username FROM user_users;
  333.   
  334.     DELETE temp_for_pkg_gen_sql2000_temp WHERE OBJECT_TYPE = v_object_type;
  335.     COMMIT;
  336.   
  337.     FOR cur_tables_rec IN cur_tables LOOP
  338.       v_tab_name        := cur_tables_rec.table_name;
  339.       v_tabsp_name      := cur_tables_rec.tablespace_name;
  340.       n_mpct_free       := cur_tables_rec.pct_free;
  341.       n_mpct_used       := cur_tables_rec.pct_used;
  342.       n_mini_trans      := cur_tables_rec.ini_trans;
  343.       n_mmax_trans      := cur_tables_rec.max_trans;
  344.       n_mini_ext        := cur_tables_rec.initial_extent;
  345.       n_mnext_ext       := cur_tables_rec.next_extent;
  346.       n_mmin_ext        := cur_tables_rec.min_extents;
  347.       n_mmax_ext        := cur_tables_rec.max_extents;
  348.       n_mpct_inc        := nvl(cur_tables_rec.pct_increase, 0);
  349.       n_freelists       := cur_tables_rec.freelists;
  350.       n_freelist_groups := cur_tables_rec.freelist_groups;
  351.       v_buffer_pool     := cur_tables_rec.buffer_pool;
  352.       v_logging         := cur_tables_rec.logging;
  353.     
  354.       IF v_gen_drop_tab_sql = 'T' THEN
  355.         IF upper(v_display_prompt_info) = 'T' THEN
  356.           v_sql := v_prompt || ' Drop Table ' || v_tab_name;
  357.           insert_rec(n_line_no,
  358.                      v_object_type,
  359.                      v_username,
  360.                      v_tab_name,
  361.                      v_sql);
  362.           n_line_no := n_line_no + 1;
  363.         END IF;
  364.       
  365.         v_sql := 'ALTER TABLE ' || v_tab_name ||
  366.                  ' drop primary key cascade;';
  367.         insert_rec(n_line_no, v_object_type, v_username, v_tab_name, v_sql);
  368.         n_line_no := n_line_no + 1;
  369.       
  370.         v_sql := 'DROP TABLE ' || v_tab_name || ' cascade constraint;';
  371.         insert_rec(n_line_no, v_object_type, v_username, v_tab_name, v_sql);
  372.         n_line_no := n_line_no + 1;
  373.       
  374.         v_sql := '                                   ';
  375.         insert_rec(n_line_no, v_object_type, v_username, v_tab_name, v_sql);
  376.         n_line_no := n_line_no + 1;
  377.       END IF;
  378.     
  379.       IF upper(v_gen_create_tab_sql) = 'T' THEN
  380.         IF upper(v_display_prompt_info) = 'T' THEN
  381.           v_sql := v_prompt || ' Create Table ' || v_tab_name;
  382.           insert_rec(n_line_no,
  383.                      v_object_type,
  384.                      v_username,
  385.                      v_tab_name,
  386.                      v_sql);
  387.           n_line_no := n_line_no + 1;
  388.         END IF;
  389.       
  390.         v_sql := 'CREATE TABLE ' || v_tab_name || '(';
  391.         insert_rec(n_line_no, v_object_type, v_username, v_tab_name, v_sql);
  392.         n_line_no := n_line_no + 1;
  393.       
  394.         -- 找到最长的列名的长度
  395.         n_col_max_len := 1;
  396.         FOR cur_cols_rec IN cur_cols(v_tab_name) LOOP
  397.           IF n_col_max_len < length(trim(cur_cols_rec.column_name)) THEN
  398.             n_col_max_len := length(trim(cur_cols_rec.column_name));
  399.           END IF;
  400.         END LOOP;
  401.       
  402.         ct := 0;
  403.       
  404.         FOR cur_cols_rec IN cur_cols(v_tab_name) LOOP
  405.           ct            := ct + 1;
  406.           v_default_val := cur_cols_rec.data_default;
  407.           v_default_val := trim(v_default_val);
  408.           n_position    := instr(v_default_val, chr(10), -1);
  409.           WHILE n_position > 0 LOOP
  410.             IF n_position = length(v_default_val) THEN
  411.               v_default_val := substr(v_default_val, 1, n_position - 1);
  412.             ELSE
  413.               v_default_val := substr(v_default_val, 1, n_position - 1) ||
  414.                                substr(v_default_val, n_position + 1);
  415.             END IF;
  416.             n_position := instr(v_default_val, chr(10), -1);
  417.           END LOOP;
  418.           n_position := instr(v_default_val, chr(9), -1);
  419.           IF n_position = length(v_default_val) THEN
  420.             v_default_val := substr(v_default_val, 1, n_position - 1);
  421.           END IF;
  422.           IF ct = 1 THEN
  423.             INSERT INTO temp_for_pkg_gen_sql2000_temp
  424.               (line_no, object_type, user_name, object_name, sql_text)
  425.             VALUES
  426.               (n_line_no,
  427.                v_object_type,
  428.                v_username,
  429.                v_tab_name,
  430.                chr(9) ||
  431.                pkg_gen_user_sql.fun_return_table_name_tab4(trim(cur_cols_rec.column_name),
  432.                                                            n_col_max_len) ||
  433.                chr(9) || trim(cur_cols_rec.data_type) ||
  434.                decode(cur_cols_rec.data_type,
  435.                       'VARCHAR2',
  436.                       '(' || to_char(cur_cols_rec.data_length) || ')',
  437.                       'VARCHAR',
  438.                       '(' || to_char(cur_cols_rec.data_length) || ')',
  439.                       'NVARCHAR2',
  440.                       '(' || to_char(cur_cols_rec.data_length) || ')',
  441.                       'NVARCHAR',
  442.                       '(' || to_char(cur_cols_rec.data_length) || ')',
  443.                       'CHAR',
  444.                       '(' || to_char(cur_cols_rec.data_length) || ')',
  445.                       'NCHAR',
  446.                       '(' || to_char(cur_cols_rec.data_length) || ')',
  447.                       'NUMBER',
  448.                       decode(cur_cols_rec.data_precision,
  449.                              null,
  450.                              '',
  451.                              '(' || to_char(cur_cols_rec.data_precision) ||
  452.                              decode(cur_cols_rec.data_scale,
  453.                                     null,
  454.                                     ')',
  455.                                     ',' || to_char(cur_cols_rec.data_scale) || ')')),
  456.                       '') ||
  457.                decode(cur_cols_rec.nullable,
  458.                       'Y',
  459.                       decode(v_default_val,
  460.                              null,
  461.                              ',',
  462.                              chr(9) || 'default' || chr(9) || v_default_val || ','),
  463.                       decode(v_default_val,
  464.                              null,
  465.                              chr(9) || 'NOT NULL,',
  466.                              chr(9) || 'default' || chr(9) || v_default_val ||
  467.                              chr(9) || chr(9) || 'NOT NULL,')));
  468.           
  469.             n_line_no := n_line_no + 1;
  470.           ELSE
  471.             INSERT INTO temp_for_pkg_gen_sql2000_temp
  472.               (line_no, object_type, user_name, object_name, sql_text)
  473.             VALUES
  474.               (n_line_no,
  475.                v_object_type,
  476.                v_username,
  477.                v_tab_name,
  478.                chr(9) ||
  479.                pkg_gen_user_sql.fun_return_table_name_tab4(trim(cur_cols_rec.column_name),
  480.                                                            n_col_max_len) ||
  481.                chr(9) || trim(cur_cols_rec.data_type) ||
  482.                decode(cur_cols_rec.data_type,
  483.                       'VARCHAR2',
  484.                       '(' || to_char(cur_cols_rec.data_length) || ')',
  485.                       'VARCHAR',
  486.                       '(' || to_char(cur_cols_rec.data_length) || ')',
  487.                       'NVARCHAR2',
  488.                       '(' || to_char(cur_cols_rec.data_length) || ')',
  489.                       'NVARCHAR',
  490.                       '(' || to_char(cur_cols_rec.data_length) || ')',
  491.                       'CHAR',
  492.                       '(' || to_char(cur_cols_rec.data_length) || ')',
  493.                       'NCHAR',
  494.                       '(' || to_char(cur_cols_rec.data_length) || ')',
  495.                       'NUMBER',
  496.                       decode(cur_cols_rec.data_precision,
  497.                              null,
  498.                              '',
  499.                              '(' || to_char(cur_cols_rec.data_precision) ||
  500.                              decode(cur_cols_rec.data_scale,
  501.                                     null,
  502.                                     ')',
  503.                                     ',' || to_char(cur_cols_rec.data_scale) || ')')),
  504.                       '') ||
  505.                decode(cur_cols_rec.nullable,
  506.                       'Y',
  507.                       decode(v_default_val,
  508.                              null,
  509.                              ',',
  510.                              chr(9) || 'default' || chr(9) || v_default_val || ','),
  511.                       decode(v_default_val,
  512.                              null,
  513.                              chr(9) || 'NOT NULL,',
  514.                              chr(9) || 'default' || chr(9) || v_default_val ||
  515.                              chr(9) || chr(9) || 'NOT NULL,')));
  516.             n_line_no := n_line_no + 1;
  517.           END IF;
  518.         END LOOP;
  519.       
  520.         SELECT rtrim(sql_text)
  521.           into col_content
  522.           FROM temp_for_pkg_gen_sql2000_temp
  523.          WHERE line_no = n_line_no - 1
  524.            AND object_type = v_object_type;
  525.         col_content := substr(col_content, 1, length(col_content) - 1);
  526.       
  527.         UPDATE temp_for_pkg_gen_sql2000_temp
  528.            SET sql_text = col_content
  529.          WHERE line_no = n_line_no - 1
  530.            AND object_type = v_object_type;
  531.       
  532.         v_sql := ')';
  533.         insert_rec(n_line_no, v_object_type, v_username, v_tab_name, v_sql);
  534.         n_line_no := n_line_no + 1;
  535.       
  536.         IF v_gen_store_clause = 'T' THEN
  537.         
  538.           v_sql := v_logging;
  539.           insert_rec(n_line_no,
  540.                      v_object_type,
  541.                      v_username,
  542.                      v_tab_name,
  543.                      v_sql);
  544.           n_line_no := n_line_no + 1;
  545.         
  546.           v_sql := 'TABLESPACE ' || v_tabsp_name;
  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.         
  554.           v_sql := 'PCTFREE ' || n_mpct_free || chr(9) || 'PCTUSED ' ||
  555.                    n_mpct_used;
  556.           insert_rec(n_line_no,
  557.                      v_object_type,
  558.                      v_username,
  559.                      v_tab_name,
  560.                      v_sql);
  561.           n_line_no := n_line_no + 1;
  562.         
  563.           v_sql := 'INITRANS ' || n_mini_trans || chr(9) || 'MAXTRANS ' ||
  564.                    n_mmax_trans;
  565.           insert_rec(n_line_no,
  566.                      v_object_type,
  567.                      v_username,
  568.                      v_tab_name,
  569.                      v_sql);
  570.           n_line_no := n_line_no + 1;
  571.         
  572.           v_sql := 'STORAGE (';
  573.           insert_rec(n_line_no,
  574.                      v_object_type,
  575.                      v_username,
  576.                      v_tab_name,
  577.                      v_sql);
  578.           n_line_no := n_line_no + 1;
  579.         
  580.           v_sql := chr(9) || 'INITIAL ' || n_mini_ext;
  581.           insert_rec(n_line_no,
  582.                      v_object_type,
  583.                      v_username,
  584.                      v_tab_name,
  585.                      v_sql);
  586.           n_line_no := n_line_no + 1;
  587.         
  588.           IF n_mnext_ext IS NOT NULL THEN
  589.             UPDATE temp_for_pkg_gen_sql2000_temp
  590.                SET sql_text = sql_text || chr(9) || 'NEXT ' ||
  591.                               to_char(n_mnext_ext)
  592.              WHERE line_no = n_line_no - 1
  593.                AND object_type = v_object_type;
  594.           END IF;
  595.         
  596.           UPDATE temp_for_pkg_gen_sql2000_temp
  597.              SET sql_text = sql_text || chr(9) || 'PCTINCREASE ' ||
  598.                             to_char(n_mpct_inc)
  599.            WHERE line_no = n_line_no - 1
  600.              AND object_type = v_object_type;
  601.         
  602.           v_sql := chr(9) || 'FREELISTS ' || to_char(n_freelists);
  603.           insert_rec(n_line_no,
  604.                      v_object_type,
  605.                      v_username,
  606.                      v_tab_name,
  607.                      v_sql);
  608.           n_line_no := n_line_no + 1;
  609.         
  610.           UPDATE temp_for_pkg_gen_sql2000_temp
  611.              SET sql_text = sql_text || chr(9) || 'FREELIST GROUPS ' ||
  612.                             to_char(n_freelist_groups)
  613.            WHERE line_no = n_line_no - 1
  614.              AND object_type = v_object_type;
  615.         
  616.           v_sql := chr(9) || 'BUFFER_POOL ' || v_buffer_pool;
  617.           insert_rec(n_line_no,
  618.                      v_object_type,
  619.                      v_username,
  620.                      v_tab_name,
  621.                      v_sql);
  622.           n_line_no := n_line_no + 1;
  623.         
  624.           UPDATE temp_for_pkg_gen_sql2000_temp
  625.              SET sql_text = sql_text || ');'
  626.            WHERE line_no = n_line_no - 1
  627.              AND object_type = v_object_type;
  628.         ELSE
  629.           UPDATE temp_for_pkg_gen_sql2000_temp
  630.              SET sql_text = sql_text || ';'
  631.            WHERE line_no = n_line_no - 1
  632.              AND object_type = v_object_type;
  633.         END IF;
  634.       
  635.         v_sql := '                                   ';
  636.         insert_rec(n_line_no, v_object_type, v_username, v_tab_name, v_sql);
  637.         n_line_no := n_line_no + 1;
  638.       END IF;
  639.     END LOOP;
  640.     COMMIT;
  641.   END;
  642.   PROCEDURE pro_tab_sql_tab8(p_v_gen_drop_sql        VARCHAR2 default 'T',
  643.                              p_v_gen_create_sql      VARCHAR2 default 'T',
  644.                              p_v_gen_store_clause    VARCHAR2 default 'T',
  645.                              p_v_display_prompt_info VARCHAR2 default 'T') AS
  646.     CURSOR cur_tables IS
  647.       SELECT table_name,
  648.              tablespace_name,
  649.              pct_free,
  650.              pct_used,
  651.              ini_trans,
  652.              max_trans,
  653.              initial_extent,
  654.              next_extent,
  655.              min_extents,
  656.              max_extents,
  657.              pct_increase,
  658.              freelists,
  659.              freelist_groups,
  660.              buffer_pool,
  661.              decode(logging, 'YES''LOGGING''NOLOGGING') logging
  662.         FROM user_tables
  663.        WHERE lower(TABLE_NAME) NOT IN
  664.              ('temp_for_pkg_gen_sql2000_temp',
  665.               'temp_for_pkg_gen_sql4000_temp')
  666.        ORDER BY table_name;
  667.   
  668.     CURSOR cur_cols(t_name VARCHAR2) IS
  669.       SELECT table_name,
  670.              column_name,
  671.              data_type,
  672.              data_length,
  673.              data_precision,
  674.              data_scale,
  675.              nullable,
  676.              data_default
  677.         FROM user_tab_columns
  678.        WHERE table_name = t_name
  679.        ORDER BY column_id;
  680.   
  681.     v_tab_name            VARCHAR2(40);
  682.     v_tabsp_name          VARCHAR2(40);
  683.     n_mpct_free           user_tables.pct_free%TYPE;
  684.     n_mpct_used           user_tables.pct_used%TYPE;
  685.     n_mini_trans          user_tables.ini_trans%TYPE;
  686.     n_mmax_trans          user_tables.max_trans%TYPE;
  687.     n_mini_ext            user_tables.initial_extent%TYPE;
  688.     n_mnext_ext           user_tables.next_extent%TYPE;
  689.     n_mmin_ext            user_tables.min_extents%TYPE;
  690.     n_mmax_ext            user_tables.max_extents%TYPE;
  691.     n_mpct_inc            user_tables.pct_increase%TYPE;
  692.     n_freelists           user_tables.freelists%TYPE;
  693.     n_freelist_groups     user_tables.freelist_groups%TYPE;
  694.     v_buffer_pool         user_tables.buffer_pool%TYPE;
  695.     v_logging             VARCHAR2(15);
  696.     col_name              VARCHAR2(40);
  697.     ct                    NUMBER := 0;
  698.     n_line_no             NUMBER := 0;
  699.     col_content           VARCHAR2(120);
  700.     n_col_max_len         NUMBER(100);
  701.     v_default_val         VARCHAR2(4000);
  702.     v_gen_drop_tab_sql    VARCHAR2(10);
  703.     v_gen_create_tab_sql  VARCHAR2(10);
  704.     v_gen_store_clause    VARCHAR2(10);
  705.     v_display_prompt_info VARCHAR2(10);
  706.     v_username            VARCHAR2(30);
  707.     v_sql                 VARCHAR2(2000);
  708.     n_position            NUMBER(60);
  709.     v_object_type         VARCHAR2(10);
  710.     v_prompt              VARCHAR2(10);
  711.     PROCEDURE insert_rec(p_line_no     INTEGER,
  712.                          p_object_type VARCHAR2,
  713.                          p_user_name   VARCHAR2,
  714.                          p_object_name VARCHAR2,
  715.                          p_string      VARCHAR2) IS
  716.     BEGIN
  717.       INSERT INTO temp_for_pkg_gen_sql2000_temp
  718.         (line_no, object_type, user_name, object_name, sql_text)
  719.       VALUES
  720.         (p_line_no, p_object_type, p_user_name, p_object_name, p_string);
  721.     END;
  722.   BEGIN
  723.     v_gen_drop_tab_sql    := p_v_gen_drop_sql;
  724.     v_gen_create_tab_sql  := p_v_gen_create_sql;
  725.     v_gen_store_clause    := p_v_gen_store_clause;
  726.     v_display_prompt_info := p_v_display_prompt_info;
  727.     v_prompt              := '-- prompt ';
  728.     v_object_type         := 'TABLE_8';
  729.     n_line_no             := 1;
  730.   
  731.     SELECT username INTO v_username FROM user_users;
  732.   
  733.     DELETE temp_for_pkg_gen_sql2000_temp WHERE OBJECT_TYPE = v_object_type;
  734.     COMMIT;
  735.   
  736.     FOR cur_tables_rec IN cur_tables LOOP
  737.       v_tab_name        := cur_tables_rec.table_name;
  738.       v_tabsp_name      := cur_tables_rec.tablespace_name;
  739.       n_mpct_free       := cur_tables_rec.pct_free;
  740.       n_mpct_used       := cur_tables_rec.pct_used;
  741.       n_mini_trans      := cur_tables_rec.ini_trans;
  742.       n_mmax_trans      := cur_tables_rec.max_trans;
  743.       n_mini_ext        := cur_tables_rec.initial_extent;
  744.       n_mnext_ext       := cur_tables_rec.next_extent;
  745.       n_mmin_ext        := cur_tables_rec.min_extents;
  746.       n_mmax_ext        := cur_tables_rec.max_extents;
  747.       n_mpct_inc        := nvl(cur_tables_rec.pct_increase, 0);
  748.       n_freelists       := cur_tables_rec.freelists;
  749.       n_freelist_groups := cur_tables_rec.freelist_groups;
  750.       v_buffer_pool     := cur_tables_rec.buffer_pool;
  751.       v_logging         := cur_tables_rec.logging;
  752.     
  753.       IF v_gen_drop_tab_sql = 'T' THEN
  754.         IF upper(v_display_prompt_info) = 'T' THEN
  755.           v_sql := v_prompt || ' Drop Table ' || v_tab_name;
  756.           insert_rec(n_line_no,
  757.                      v_object_type,
  758.                      v_username,
  759.                      v_tab_name,
  760.                      v_sql);
  761.           n_line_no := n_line_no + 1;
  762.         END IF;
  763.       
  764.         v_sql := 'ALTER TABLE ' || v_tab_name ||
  765.                  ' drop primary key cascade;';
  766.         insert_rec(n_line_no, v_object_type, v_username, v_tab_name, v_sql);
  767.         n_line_no := n_line_no + 1;
  768.       
  769.         v_sql := 'DROP TABLE ' || v_tab_name || ' cascade constraint;';
  770.         insert_rec(n_line_no, v_object_type, v_username, v_tab_name, v_sql);
  771.         n_line_no := n_line_no + 1;
  772.       
  773.         v_sql := '                                   ';
  774.         insert_rec(n_line_no, v_object_type, v_username, v_tab_name, v_sql);
  775.         n_line_no := n_line_no + 1;
  776.       END IF;
  777.     
  778.       IF upper(v_gen_create_tab_sql) = 'T' THEN
  779.         IF upper(v_display_prompt_info) = 'T' THEN
  780.           v_sql := v_prompt || ' Create Table ' || v_tab_name;
  781.           insert_rec(n_line_no,
  782.                      v_object_type,
  783.                      v_username,
  784.                      v_tab_name,
  785.                      v_sql);
  786.           n_line_no := n_line_no + 1;
  787.         END IF;
  788.       
  789.         v_sql := 'CREATE TABLE ' || v_tab_name || '(';
  790.         insert_rec(n_line_no, v_object_type, v_username, v_tab_name, v_sql);
  791.         n_line_no := n_line_no + 1;
  792.       
  793.         -- 找到最长的列名的长度
  794.         n_col_max_len := 1;
  795.         FOR cur_cols_rec IN cur_cols(v_tab_name) LOOP
  796.           IF n_col_max_len < length(trim(cur_cols_rec.column_name)) THEN
  797.             n_col_max_len := length(trim(cur_cols_rec.column_name));
  798.           END IF;
  799.         END LOOP;
  800.       
  801.         ct := 0;
  802.       
  803.         FOR cur_cols_rec IN cur_cols(v_tab_name) LOOP
  804.           ct            := ct + 1;
  805.           v_default_val := cur_cols_rec.data_default;
  806.           v_default_val := trim(v_default_val);
  807.           n_position    := instr(v_default_val, chr(10), -1);
  808.           WHILE n_position > 0 LOOP
  809.             IF n_position = length(v_default_val) THEN
  810.               v_default_val := substr(v_default_val, 1, n_position - 1);
  811.             ELSE
  812.               v_default_val := substr(v_default_val, 1, n_position - 1) ||
  813.                                substr(v_default_val, n_position + 1);
  814.             END IF;
  815.             n_position := instr(v_default_val, chr(10), -1);
  816.           END LOOP;
  817.           n_position := instr(v_default_val, chr(9), -1);
  818.           IF n_position = length(v_default_val) THEN
  819.             v_default_val := substr(v_default_val, 1, n_position - 1);
  820.           END IF;
  821.           IF ct = 1 THEN
  822.             INSERT INTO temp_for_pkg_gen_sql2000_temp
  823.               (line_no, object_type, user_name, object_name, sql_text)
  824.             VALUES
  825.               (n_line_no,
  826.                v_object_type,
  827.                v_username,
  828.                v_tab_name,
  829.                chr(9) ||
  830.                pkg_gen_user_sql.fun_return_table_name_tab8(trim(cur_cols_rec.column_name),
  831.                                                            n_col_max_len) ||
  832.                chr(9) || trim(cur_cols_rec.data_type) ||
  833.                decode(cur_cols_rec.data_type,
  834.                       'VARCHAR2',
  835.                       '(' || to_char(cur_cols_rec.data_length) || ')',
  836.                       'VARCHAR',
  837.                       '(' || to_char(cur_cols_rec.data_length) || ')',
  838.                       'NVARCHAR2',
  839.                       '(' || to_char(cur_cols_rec.data_length) || ')',
  840.                       'NVARCHAR',
  841.                       '(' || to_char(cur_cols_rec.data_length) || ')',
  842.                       'CHAR',
  843.                       '(' || to_char(cur_cols_rec.data_length) || ')',
  844.                       'NCHAR',
  845.                       '(' || to_char(cur_cols_rec.data_length) || ')',
  846.                       'NUMBER',
  847.                       decode(cur_cols_rec.data_precision,
  848.                              null,
  849.                              '',
  850.                              '(' || to_char(cur_cols_rec.data_precision) ||
  851.                              decode(cur_cols_rec.data_scale,
  852.                                     null,
  853.                                     ')',
  854.                                     ',' || to_char(cur_cols_rec.data_scale) || ')')),
  855.                       '') ||
  856.                decode(cur_cols_rec.nullable,
  857.                       'Y',
  858.                       decode(v_default_val,
  859.                              null,
  860.                              ',',
  861.                              chr(9) || 'default' || chr(9) || v_default_val || ','),
  862.                       decode(v_default_val,
  863.                              null,
  864.                              chr(9) || 'NOT NULL,',
  865.                              chr(9) || 'default' || chr(9) || v_default_val ||
  866.                              chr(9) || chr(9) || 'NOT NULL,')));
  867.           
  868.             n_line_no := n_line_no + 1;
  869.           ELSE
  870.             INSERT INTO temp_for_pkg_gen_sql2000_temp
  871.               (line_no, object_type, user_name, object_name, sql_text)
  872.             VALUES
  873.               (n_line_no,
  874.                v_object_type,
  875.                v_username,
  876.                v_tab_name,
  877.                chr(9) ||
  878.                pkg_gen_user_sql.fun_return_table_name_tab8(trim(cur_cols_rec.column_name),
  879.                                                            n_col_max_len) ||
  880.                chr(9) || trim(cur_cols_rec.data_type) ||
  881.                decode(cur_cols_rec.data_type,
  882.                       'VARCHAR2',
  883.                       '(' || to_char(cur_cols_rec.data_length) || ')',
  884.                       'VARCHAR',
  885.                       '(' || to_char(cur_cols_rec.data_length) || ')',
  886.                       'NVARCHAR2',
  887.                       '(' || to_char(cur_cols_rec.data_length) || ')',
  888.                       'NVARCHAR',
  889.                       '(' || to_char(cur_cols_rec.data_length) || ')',
  890.                       'CHAR',
  891.                       '(' || to_char(cur_cols_rec.data_length) || ')',
  892.                       'NCHAR',
  893.                       '(' || to_char(cur_cols_rec.data_length) || ')',
  894.                       'NUMBER',
  895.                       decode(cur_cols_rec.data_precision,
  896.                              null,
  897.                              '',
  898.                              '(' || to_char(cur_cols_rec.data_precision) ||
  899.                              decode(cur_cols_rec.data_scale,
  900.                                     null,
  901.                                     ')',
  902.                                     ',' || to_char(cur_cols_rec.data_scale) || ')')),
  903.                       '') ||
  904.                decode(cur_cols_rec.nullable,
  905.                       'Y',
  906.                       decode(v_default_val,
  907.                              null,
  908.                              ',',
  909.                              chr(9) || 'default' || chr(9) || v_default_val || ','),
  910.                       decode(v_default_val,
  911.                              null,
  912.                              chr(9) || 'NOT NULL,',
  913.                              chr(9) || 'default' || chr(9) || v_default_val ||
  914.                              chr(9) || chr(9) || 'NOT NULL,')));
  915.             n_line_no := n_line_no + 1;
  916.           END IF;
  917.         END LOOP;
  918.       
  919.         SELECT rtrim(sql_text)
  920.           into col_content
  921.           FROM temp_for_pkg_gen_sql2000_temp
  922.          WHERE line_no = n_line_no - 1
  923.            AND object_type = v_object_type;
  924.         col_content := substr(col_content, 1, length(col_content) - 1);
  925.       
  926.         UPDATE temp_for_pkg_gen_sql2000_temp
  927.            SET sql_text = col_content
  928.          WHERE line_no = n_line_no - 1
  929.            AND object_type = v_object_type;
  930.       
  931.         v_sql := ')';
  932.         insert_rec(n_line_no, v_object_type, v_username, v_tab_name, v_sql);
  933.         n_line_no := n_line_no + 1;
  934.       
  935.         IF v_gen_store_clause = 'T' THEN
  936.         
  937.           v_sql := v_logging;
  938.           insert_rec(n_line_no,
  939.                      v_object_type,
  940.                      v_username,
  941.                      v_tab_name,
  942.                      v_sql);
  943.           n_line_no := n_line_no + 1;
  944.         
  945.           v_sql := 'TABLESPACE ' || v_tabsp_name;
  946.           insert_rec(n_line_no,
  947.                      v_object_type,
  948.                      v_username,
  949.                      v_tab_name,
  950.                      v_sql);
  951.           n_line_no := n_line_no + 1;
  952.         
  953.           v_sql := 'PCTFREE ' || n_mpct_free || chr(9) || 'PCTUSED ' ||
  954.                    n_mpct_used;
  955.           insert_rec(n_line_no,
  956.                      v_object_type,
  957.                      v_username,
  958.                      v_tab_name,
  959.                      v_sql);
  960.           n_line_no := n_line_no + 1;
  961.         
  962.           v_sql := 'INITRANS ' || n_mini_trans || chr(9) || 'MAXTRANS ' ||
  963.                    n_mmax_trans;
  964.           insert_rec(n_line_no,
  965.                      v_object_type,
  966.                      v_username,
  967.                      v_tab_name,
  968.                      v_sql);
  969.           n_line_no := n_line_no + 1;
  970.         
  971.           v_sql := 'STORAGE (';
  972.           insert_rec(n_line_no,
  973.                      v_object_type,
  974.                      v_username,
  975.                      v_tab_name,
  976.                      v_sql);
  977.           n_line_no := n_line_no + 1;
  978.         
  979.           v_sql := chr(9) || 'INITIAL ' || n_mini_ext;
  980.           insert_rec(n_line_no,
  981.                      v_object_type,
  982.                      v_username,
  983.                      v_tab_name,
  984.                      v_sql);
  985.           n_line_no := n_line_no + 1;
  986.         
  987.           IF n_mnext_ext IS NOT NULL THEN
  988.             UPDATE temp_for_pkg_gen_sql2000_temp
  989.                SET sql_text = sql_text || chr(9) || 'NEXT ' ||
  990.                               to_char(n_mnext_ext)
  991.              WHERE line_no = n_line_no - 1
  992.                AND object_type = v_object_type;
  993.           END IF;
  994.         
  995.           UPDATE temp_for_pkg_gen_sql2000_temp
  996.              SET sql_text = sql_text || chr(9) || 'PCTINCREASE ' ||
  997.                             to_char(n_mpct_inc)
  998.            WHERE line_no = n_line_no - 1
  999.              AND object_type = v_object_type;
  1000.         
  1001.           v_sql := chr(9) || 'FREELISTS ' || to_char(n_freelists);
  1002.           insert_rec(n_line_no,
  1003.                      v_object_type,
  1004.                      v_username,
  1005.                      v_tab_name,
  1006.                      v_sql);
  1007.           n_line_no := n_line_no + 1;
  1008.         
  1009.           UPDATE temp_for_pkg_gen_sql2000_temp
  1010.              SET sql_text = sql_text || chr(9) || 'FREELIST GROUPS ' ||
  1011.                             to_char(n_freelist_groups)
  1012.            WHERE line_no = n_line_no - 1
  1013.              AND object_type = v_object_type;
  1014.         
  1015.           v_sql := chr(9) || 'BUFFER_POOL ' || v_buffer_pool;
  1016.           insert_rec(n_line_no,
  1017.                      v_object_type,
  1018.                      v_username,
  1019.                      v_tab_name,
  1020.                      v_sql);
  1021.           n_line_no := n_line_no + 1;
  1022.         
  1023.           UPDATE temp_for_pkg_gen_sql2000_temp
  1024.              SET sql_text = sql_text || ');'
  1025.            WHERE line_no = n_line_no - 1
  1026.              AND object_type = v_object_type;
  1027.         ELSE
  1028.           UPDATE temp_for_pkg_gen_sql2000_temp
  1029.              SET sql_text = sql_text || ';'
  1030.            WHERE line_no = n_line_no - 1
  1031.              AND object_type = v_object_type;
  1032.         END IF;
  1033.       
  1034.         v_sql := '                                   ';
  1035.         insert_rec(n_line_no, v_object_type, v_username, v_tab_name, v_sql);
  1036.         n_line_no := n_line_no + 1;
  1037.       END IF;
  1038.     END LOOP;
  1039.     COMMIT;
  1040.   END;
  1041.   PROCEDURE pro_con_sql(p_v_con_type            VARCHAR2 default 'ALL',
  1042.                         p_v_gen_drop_sql        VARCHAR2 default 'T',
  1043.                         p_v_gen_create_sql      VARCHAR2 default 'T',
  1044.                         p_v_gen_null_chk        VARCHAR2 default 'T',
  1045.                         p_v_display_prompt_info VARCHAR2 default 'T') AS
  1046.     CURSOR cur_tables is
  1047.       SELECT table_name FROM user_tables ORDER BY table_name;
  1048.   
  1049.     CURSOR cur_con_cols(c_name VARCHAR2) IS
  1050.       SELECT column_name
  1051.         FROM user_cons_columns
  1052.        WHERE constraint_name = c_name
  1053.        ORDER BY position;
  1054.   
  1055.     type ref_cur is REF CURSOR; -- 定义一个ref 类型的游标
  1056.     cur_cons ref_cur; -- 定义游标变量
  1057.     TYPE type_con IS RECORD(
  1058.       constraint_name   user_constraints.constraint_name%type,
  1059.       r_constraint_name user_constraints.r_constraint_name%type,
  1060.       constraint_type   user_constraints.constraint_type%type,
  1061.       search_condition  user_constraints.search_condition%type);
  1062.   
  1063.     cur_cons_rec          type_con;
  1064.     v_tab_name            VARCHAR2(40);
  1065.     v_table_name          VARCHAR2(40);
  1066.     v_type                VARCHAR2(1);
  1067.     n_ct                  NUMBER := 0;
  1068.     n_line_no             NUMBER := 0;
  1069.     v_con_type            VARCHAR2(10);
  1070.     v_con_sql             VARCHAR2(500);
  1071.     v_sql                 VARCHAR2(2000);
  1072.     v_gen_drop_con_sql    VARCHAR2(10);
  1073.     v_display_prompt_info VARCHAR2(10);
  1074.     v_gen_create_con_sql  VARCHAR2(10);
  1075.     v_gen_null_chk        VARCHAR2(10);
  1076.     v_username            VARCHAR2(30);
  1077.     v_object_type         VARCHAR2(30);
  1078.     v_prompt              VARCHAR2(30);
  1079.     v_search_condition    VARCHAR2(1000);
  1080.     PROCEDURE insert_rec(p_line_no     INTEGER,
  1081.                          p_object_type VARCHAR2,
  1082.                          p_user_name   VARCHAR2,
  1083.                          p_con_name    VARCHAR2,
  1084.                          p_string      VARCHAR2) IS
  1085.     BEGIN
  1086.       INSERT INTO temp_for_pkg_gen_sql2000_temp
  1087.         (line_no, object_type, user_name, object_name, sql_text)
  1088.       VALUES
  1089.         (p_line_no, p_object_type, p_user_name, p_con_name, p_string);
  1090.     END;
  1091.   BEGIN
  1092.     v_con_type            := p_v_con_type;
  1093.     v_gen_drop_con_sql    := p_v_gen_drop_sql;
  1094.     v_display_prompt_info := p_v_display_prompt_info;
  1095.     v_gen_create_con_sql  := p_v_gen_create_sql;
  1096.     v_gen_null_chk        := p_v_gen_null_chk;
  1097.   
  1098.     v_object_type := 'CONSTRAINT';
  1099.     v_prompt      := '-- prompt ';
  1100.     n_line_no     := 1;
  1101.   
  1102.     SELECT username INTO v_username FROM user_users;
  1103.   
  1104.     DELETE FROM temp_for_pkg_gen_sql2000_temp
  1105.      WHERE object_type = v_object_type;
  1106.   
  1107.     COMMIT;
  1108.   
  1109.     FOR cur_tables_rec IN cur_tables LOOP
  1110.       v_tab_name := trim(cur_tables_rec.table_name);
  1111.     
  1112.       -- Get the constraint info for specified table
  1113.       v_con_sql := 'SELECT constraint_name, r_constraint_name, ';
  1114.       v_con_sql := v_con_sql || '       constraint_type, search_condition ';
  1115.       v_con_sql := v_con_sql || 'FROM user_constraints ';
  1116.       IF upper(v_con_type) <> 'ALL' AND upper(v_con_type) <> 'A' AND
  1117.          upper(v_con_type) <> 'NOT_PRI' THEN
  1118.         v_con_sql := v_con_sql || 'WHERE  table_name = ''' || v_tab_name ||
  1119.                      ''' AND constraint_type = ''' || upper(v_con_type) ||
  1120.                      ''' ';
  1121.       ELSIF upper(v_con_type) = 'NOT_PRI' THEN
  1122.         v_con_sql := v_con_sql || 'WHERE  table_name = ''' || v_tab_name ||
  1123.                      ''' AND constraint_type <> ''P'' ';
  1124.       ELSE
  1125.         v_con_sql := v_con_sql || 'WHERE  table_name = ''' || v_tab_name ||
  1126.                      ''' ';
  1127.       END IF;
  1128.       v_con_sql := v_con_sql || 'ORDER BY constraint_name';
  1129.     
  1130.       OPEN cur_cons FOR v_con_sql;
  1131.       LOOP
  1132.         FETCH cur_cons
  1133.           INTO cur_cons_rec;
  1134.         EXIT WHEN cur_cons%NOTFOUND;
  1135.       
  1136.         v_type             := cur_cons_rec.constraint_type;
  1137.         v_search_condition := cur_cons_rec.search_condition;
  1138.       
  1139.         IF upper(v_gen_drop_con_sql) = 'T' THEN
  1140.         
  1141.           IF v_gen_null_chk = 'F' AND v_type = 'C' AND
  1142.              instr(v_search_condition, 'IS NOT NULL') > 0 THEN
  1143.             -- do null
  1144.             v_gen_null_chk := v_gen_null_chk;
  1145.           ELSE
  1146.             IF upper(v_display_prompt_info) = 'T' THEN
  1147.               -- insert prompt info
  1148.               INSERT INTO temp_for_pkg_gen_sql2000_temp
  1149.                 (line_no, object_type, user_name, object_name, sql_text)
  1150.               VALUES
  1151.                 (n_line_no,
  1152.                  v_object_type,
  1153.                  v_username,
  1154.                  cur_cons_rec.constraint_name,
  1155.                  v_prompt || ' Drop constraints : ' || v_tab_name || '.' ||
  1156.                  trim(cur_cons_rec.constraint_name) || ';  Type : ' ||
  1157.                  decode(v_type,
  1158.                         'C',
  1159.                         'CHECK',
  1160.                         'P',
  1161.                         'PRIMARY KEY',
  1162.                         'U',
  1163.                         'UNIQUE',
  1164.                         'R',
  1165.                         'FROEIGN RELATION',
  1166.                         v_type));
  1167.               n_line_no := n_line_no + 1;
  1168.             END IF;
  1169.           
  1170.             v_sql := 'alter table ' || v_tab_name || ' drop constraint ' ||
  1171.                      cur_cons_rec.constraint_name || ';';
  1172.             insert_rec(n_line_no,
  1173.                        v_object_type,
  1174.                        v_username,
  1175.                        cur_cons_rec.constraint_name,
  1176.                        v_sql);
  1177.             n_line_no := n_line_no + 1;
  1178.           
  1179.             v_sql := '                    ';
  1180.             insert_rec(n_line_no,
  1181.                        v_object_type,
  1182.                        v_username,
  1183.                        cur_cons_rec.constraint_name,
  1184.                        v_sql);
  1185.             n_line_no := n_line_no + 1;
  1186.           END IF;
  1187.         END IF;
  1188.       
  1189.         IF upper(v_gen_create_con_sql) = 'T' THEN
  1190.           IF v_gen_null_chk = 'F' AND v_type = 'C' AND
  1191.              instr(v_search_condition, 'IS NOT NULL') > 0 THEN
  1192.             -- do null
  1193.             v_gen_null_chk := v_gen_null_chk;
  1194.           ELSE
  1195.             IF upper(v_display_prompt_info) = 'T' THEN
  1196.               -- insert prompt info
  1197.               INSERT INTO temp_for_pkg_gen_sql2000_temp
  1198.                 (line_no, object_type, user_name, object_name, sql_text)
  1199.               VALUES
  1200.                 (n_line_no,
  1201.                  v_object_type,
  1202.                  v_username,
  1203.                  cur_cons_rec.constraint_name,
  1204.                  v_prompt || ' Add constraints : ' || v_tab_name || '.' ||
  1205.                  trim(cur_cons_rec.constraint_name) || ';  Type : ' ||
  1206.                  decode(v_type,
  1207.                         'C',
  1208.                         'CHECK',
  1209.                         'P',
  1210.                         'PRIMARY KEY',
  1211.                         'U',
  1212.                         'UNIQUE',
  1213.                         'R',
  1214.                         'FROEIGN RELATION',
  1215.                         v_type));
  1216.               n_line_no := n_line_no + 1;
  1217.             END IF;
  1218.           
  1219.             v_sql := 'alter table ' || v_tab_name || ' add constraint ' ||
  1220.                      trim(cur_cons_rec.constraint_name);
  1221.             insert_rec(n_line_no,
  1222.                        v_object_type,
  1223.                        v_username,
  1224.                        cur_cons_rec.constraint_name,
  1225.                        v_sql);
  1226.             n_line_no := n_line_no + 1;
  1227.           
  1228.             IF v_type = 'C' THEN
  1229.               v_sql := '     check( ' ||
  1230.                        trim(cur_cons_rec.search_condition);
  1231.               insert_rec(n_line_no,
  1232.                          v_object_type,
  1233.                          v_username,
  1234.                          cur_cons_rec.constraint_name,
  1235.                          v_sql);
  1236.               n_line_no := n_line_no + 1;
  1237.             END IF;
  1238.           
  1239.             n_ct := 0;
  1240.           
  1241.             FOR cur_con_cols_rec IN cur_con_cols(cur_cons_rec.constraint_name) LOOP
  1242.               n_ct := n_ct + 1;
  1243.             
  1244.               IF n_ct = 1 THEN
  1245.                 IF v_type = 'R' THEN
  1246.                   v_sql := '     foreign key( ' ||
  1247.                            trim(cur_con_cols_rec.column_name);
  1248.                   insert_rec(n_line_no,
  1249.                              v_object_type,
  1250.                              v_username,
  1251.                              cur_cons_rec.constraint_name,
  1252.                              v_sql);
  1253.                   n_line_no := n_line_no + 1;
  1254.                 END IF;
  1255.               
  1256.                 IF v_type = 'P' THEN
  1257.                   v_sql := '     primary key( ' ||
  1258.                            trim(cur_con_cols_rec.column_name);
  1259.                   insert_rec(n_line_no,
  1260.                              v_object_type,
  1261.                              v_username,
  1262.                              cur_cons_rec.constraint_name,
  1263.                              v_sql);
  1264.                   n_line_no := n_line_no + 1;
  1265.                 END IF;
  1266.               
  1267.                 IF v_type = 'U' THEN
  1268.                   v_sql := '     unique( ' ||
  1269.                            trim(cur_con_cols_rec.column_name);
  1270.                   insert_rec(n_line_no,
  1271.                              v_object_type,
  1272.                              v_username,
  1273.                              cur_cons_rec.constraint_name,
  1274.                              v_sql);
  1275.                   n_line_no := n_line_no + 1;
  1276.                 END IF;
  1277.               
  1278.               ELSE
  1279.                 UPDATE temp_for_pkg_gen_sql2000_temp
  1280.                    SET sql_text = rtrim(sql_text) || ' , ' ||
  1281.                                   trim(cur_con_cols_rec.column_name)
  1282.                  WHERE line_no = n_line_no - 1
  1283.                    AND object_type = v_object_type;
  1284.               END IF;
  1285.             
  1286.             END LOOP;
  1287.           
  1288.             UPDATE temp_for_pkg_gen_sql2000_temp
  1289.                SET sql_text = rtrim(sql_text) || ' )'
  1290.              WHERE line_no = n_line_no - 1
  1291.                AND object_type = v_object_type;
  1292.           
  1293.             IF v_type = 'R' THEN
  1294.               SELECT table_name
  1295.                 into v_table_name
  1296.                 FROM user_constraints
  1297.                WHERE constraint_name = cur_cons_rec.r_constraint_name;
  1298.             
  1299.               n_ct := 0;
  1300.             
  1301.               FOR cur_con_cols_rec IN cur_con_cols(cur_cons_rec.r_constraint_name) LOOP
  1302.               
  1303.                 n_ct := n_ct + 1;
  1304.               
  1305.                 IF n_ct = 1 THEN
  1306.                   v_sql := '     references ' || v_table_name || '( ';
  1307.                   insert_rec(n_line_no,
  1308.                              v_object_type,
  1309.                              v_username,
  1310.                              cur_cons_rec.constraint_name,
  1311.                              v_sql);
  1312.                   n_line_no := n_line_no + 1;
  1313.                 
  1314.                   UPDATE temp_for_pkg_gen_sql2000_temp
  1315.                      SET sql_text = rtrim(sql_text) ||
  1316.                                     trim(cur_con_cols_rec.column_name)
  1317.                    WHERE line_no = n_line_no - 1
  1318.                      AND object_type = v_object_type;
  1319.                 ELSE
  1320.                   UPDATE temp_for_pkg_gen_sql2000_temp
  1321.                      SET sql_text = rtrim(sql_text) || ' , ' ||
  1322.                                     trim(cur_con_cols_rec.column_name)
  1323.                    WHERE line_no = n_line_no - 1
  1324.                      AND object_type = v_object_type;
  1325.                 END IF;
  1326.               END LOOP;
  1327.             
  1328.               UPDATE temp_for_pkg_gen_sql2000_temp
  1329.                  SET sql_text = rtrim(sql_text) || ' )'
  1330.                WHERE line_no = n_line_no - 1
  1331.                  AND object_type = v_object_type;
  1332.             ELSE
  1333.               IF v_type = 'P' or v_type = 'U' THEN
  1334.                 UPDATE temp_for_pkg_gen_sql2000_temp
  1335.                    SET sql_text = rtrim(sql_text) || ' USING INDEX '
  1336.                  WHERE line_no = n_line_no - 1
  1337.                    AND object_type = v_object_type;
  1338.               END IF;
  1339.             END IF;
  1340.           
  1341.             UPDATE temp_for_pkg_gen_sql2000_temp
  1342.                SET sql_text = sql_text || ';'
  1343.              WHERE line_no = n_line_no - 1
  1344.                AND object_type = v_object_type;
  1345.           
  1346.             v_sql := '         ';
  1347.             insert_rec(n_line_no,
  1348.                        v_object_type,
  1349.                        v_username,
  1350.                        cur_cons_rec.constraint_name,
  1351.                        v_sql);
  1352.             n_line_no := n_line_no + 1;
  1353.           END IF;
  1354.         END IF;
  1355.       END LOOP;
  1356.       CLOSE cur_cons;
  1357.     END LOOP;
  1358.     COMMIT;
  1359.   END;
  1360.   PROCEDURE pro_indx_sql(p_v_gen_drop_sql        VARCHAR2 default 'T',
  1361.                          p_v_gen_create_sql      VARCHAR2 default 'T',
  1362.                          p_v_gen_store_clause    VARCHAR2 default 'T',
  1363.                          p_v_gen_ts_only         VARCHAR2 default 'F',
  1364.                          p_v_display_prompt_info VARCHAR2 default 'T') AS
  1365.     CURSOR cur_indxes IS
  1366.       SELECT index_name,
  1367.              table_owner,
  1368.              table_name,
  1369.              index_type,
  1370.              uniqueness,
  1371.              tablespace_name,
  1372.              ini_trans,
  1373.              max_trans,
  1374.              initial_extent,
  1375.              next_extent,
  1376.              min_extents,
  1377.              max_extents,
  1378.              pct_increase,
  1379.              pct_free,
  1380.              freelists,
  1381.              freelist_groups,
  1382.              buffer_pool,
  1383.              decode(logging, 'YES''LOGGING''NOLOGGING') logging
  1384.         FROM user_indexes
  1385.        WHERE index_type <> 'LOB'
  1386.        ORDER BY index_name;
  1387.   
  1388.     CURSOR cur_cols(c_ind VARCHAR2, c_tab VARCHAR2) IS
  1389.       SELECT column_name
  1390.         FROM user_ind_columns
  1391.        WHERE index_name = c_ind
  1392.          AND table_name = c_tab
  1393.        ORDER BY column_position;
  1394.     CURSOR cur_fun_expression(c_ind VARCHAR2, c_tab VARCHAR2) IS
  1395.       SELECT column_expression
  1396.         FROM user_ind_expressions
  1397.        WHERE index_name = c_ind
  1398.          and table_name = c_tab;
  1399.     v_index_name          user_indexes.index_name%TYPE;
  1400.     v_table_owner         user_indexes.table_owner%TYPE;
  1401.     v_table_name          user_indexes.table_name%TYPE;
  1402.     v_index_type          user_indexes.index_type%TYPE;
  1403.     v_uniqueness          user_indexes.uniqueness%TYPE;
  1404.     v_tablespace_name     user_indexes.tablespace_name%TYPE;
  1405.     n_ini_trans           user_indexes.ini_trans%TYPE;
  1406.     n_max_trans           user_indexes.max_trans%TYPE;
  1407.     n_initial_extent      user_indexes.initial_extent%TYPE;
  1408.     n_next_extent         user_indexes.next_extent%TYPE;
  1409.     n_min_extents         user_indexes.min_extents%TYPE;
  1410.     n_max_extents         user_indexes.max_extents%TYPE;
  1411.     n_pct_increase        user_indexes.pct_increase%TYPE;
  1412.     n_pct_free            user_indexes.pct_free%TYPE;
  1413.     n_freelists           user_indexes.freelists%TYPE;
  1414.     n_freelist_groups     user_indexes.freelist_groups%TYPE;
  1415.     v_buffer_pool         user_indexes.buffer_pool%TYPE;
  1416.     v_logging             VARCHAR2(15);
  1417.     lv_column_name        user_ind_columns.column_name%TYPE;
  1418.     b_first_rec           BOOLEAN;
  1419.     v_string              VARCHAR2(800);
  1420.     n_line_no             NUMBER := 0;
  1421.     v_gen_drop_indx_sql   VARCHAR2(10);
  1422.     v_gen_create_indx_sql VARCHAR2(10);
  1423.     v_gen_store_clause    VARCHAR2(10);
  1424.     v_display_prompt_info VARCHAR2(10);
  1425.     v_gen_ts_only         VARCHAR2(10);
  1426.     n_temp                NUMBER(100);
  1427.     v_object_type         VARCHAR2(30);
  1428.     v_prompt              VARCHAR2(30);
  1429.     v_username            VARCHAR2(30);
  1430.     procedure insert_rec(p_line_no     INTEGER,
  1431.                          p_object_type VARCHAR2,
  1432.                          p_user_name   VARCHAR2,
  1433.                          p_index_name  VARCHAR2,
  1434.                          p_string      VARCHAR2) IS
  1435.     BEGIN
  1436.       INSERT INTO temp_for_pkg_gen_sql2000_temp
  1437.         (line_no, object_type, user_name, object_name, sql_text)
  1438.       VALUES
  1439.         (p_line_no, p_object_type, p_user_name, p_index_name, p_string);
  1440.     END;
  1441.   BEGIN
  1442.     v_gen_drop_indx_sql   := p_v_gen_drop_sql;
  1443.     v_gen_create_indx_sql := p_v_gen_create_sql;
  1444.     v_gen_store_clause    := p_v_gen_store_clause;
  1445.     v_gen_ts_only         := p_v_gen_ts_only;
  1446.     v_display_prompt_info := p_v_display_prompt_info;
  1447.     v_object_type         := 'INDEX';
  1448.     v_prompt              := '-- prompt ';
  1449.   
  1450.     SELECT username INTO v_username FROM user_users;
  1451.   
  1452.     DELETE FROM temp_for_pkg_gen_sql2000_temp
  1453.      WHERE object_type = v_object_type;
  1454.     COMMIT;
  1455.   
  1456.     n_line_no := 1;
  1457.   
  1458.     OPEN cur_indxes;
  1459.     LOOP
  1460.       FETCH cur_indxes
  1461.         INTO v_index_name, v_table_owner, v_table_name, v_index_type, v_uniqueness, v_tablespace_name, n_ini_trans, 
  1462. n_max_trans, n_initial_extent, n_next_extent, n_min_extents, n_max_extents, n_pct_increase, n_pct_free, n_freelists, 
  1463. n_freelist_groups, v_buffer_pool, v_logging;
  1464.       EXIT WHEN cur_indxes%NOTFOUND;
  1465.     
  1466.       b_first_rec := TRUE;
  1467.     
  1468.       IF upper(v_gen_drop_indx_sql) = 'T' THEN
  1469.         IF upper(v_display_prompt_info) = 'T' THEN
  1470.           IF v_uniqueness = 'UNIQUE' AND v_index_type = 'NORMAL' THEN
  1471.           
  1472.             v_string := v_prompt || ' DROP UNIQUE INDEX ' ||
  1473.                         lower(v_index_name);
  1474.           ELSIF v_uniqueness <> 'UNIQUE' AND v_index_type = 'NORMAL' THEN
  1475.           
  1476.             v_string := v_prompt || ' DROP   INDEX ' || lower(v_index_name);
  1477.           ELSIF v_index_type = 'BITMAP' THEN
  1478.             v_string := v_prompt || ' DROP   BITMAP INDEX ' ||
  1479.                         lower(v_index_name);
  1480.           ELSIF v_uniqueness = 'UNIQUE' AND v_index_type = 'NORMAL/REV' THEN
  1481.           
  1482.             v_string := v_prompt || ' DROP   UNIQUE, REVERSE INDEX ' ||
  1483.                         lower(v_index_name);
  1484.           ELSIF v_uniqueness <> 'UNIQUE' AND v_index_type = 'NORMAL/REV' THEN
  1485.           
  1486.             v_string := v_prompt || ' DROP REVERSE INDEX ' ||
  1487.                         lower(v_index_name);
  1488.           ELSIF v_uniqueness = 'UNIQUE' AND
  1489.                 v_index_type = 'FUNCTION-BASED NORMAL' THEN
  1490.           
  1491.             v_string := v_prompt || ' DROP   UNIQUE, FUNCTION INDEX ' ||
  1492.                         lower(v_index_name);
  1493.           ELSIF v_uniqueness <> 'UNIQUE' AND
  1494.                 v_index_type = 'FUNCTION-BASED NORMAL' THEN
  1495.           
  1496.             v_string := v_prompt || ' DROP FUNCTION INDEX ' ||
  1497.                         lower(v_index_name);
  1498.           END IF;
  1499.         
  1500.           insert_rec(n_line_no,
  1501.                      v_object_type,
  1502.                      v_username,
  1503.                      v_index_name,
  1504.                      v_string);
  1505.           n_line_no := n_line_no + 1;
  1506.         END IF;
  1507.       
  1508.         v_string := 'DROP INDEX ' || lower(v_index_name) || ';';
  1509.         insert_rec(n_line_no,
  1510.                    v_object_type,
  1511.                    v_username,
  1512.                    v_index_name,
  1513.                    v_string);
  1514.         n_line_no := n_line_no + 1;
  1515.       
  1516.         v_string := '                                                  ';
  1517.         insert_rec(n_line_no,
  1518.                    v_object_type,
  1519.                    v_username,
  1520.                    v_index_name,
  1521.                    v_string);
  1522.         n_line_no := n_line_no + 1;
  1523.       END IF;
  1524.     
  1525.       IF upper(v_gen_create_indx_sql) = 'T' THEN
  1526.         IF upper(p_v_display_prompt_info) = 'T' THEN
  1527.           IF v_uniqueness = 'UNIQUE' AND v_index_type = 'NORMAL' THEN
  1528.           
  1529.             v_string := v_prompt || ' CREATE UNIQUE INDEX ' ||
  1530.                         lower(v_index_name);
  1531.           ELSIF v_uniqueness <> 'UNIQUE' AND v_index_type = 'NORMAL' THEN
  1532.           
  1533.             v_string := v_prompt || ' CREATE INDEX ' || lower(v_index_name);
  1534.           ELSIF v_index_type = 'BITMAP' THEN
  1535.           
  1536.             v_string := v_prompt || ' CREATE BITMAP INDEX ' ||
  1537.                         lower(v_index_name);
  1538.           ELSIF v_uniqueness = 'UNIQUE' AND v_index_type = 'NORMAL/REV' THEN
  1539.           
  1540.             v_string := v_prompt || ' CREATE UNIQUE, REVERSE INDEX ' ||
  1541.                         lower(v_index_name);
  1542.           ELSIF v_uniqueness <> 'UNIQUE' AND v_index_type = 'NORMAL/REV' THEN
  1543.           
  1544.             v_string := v_prompt || ' CREATE REVERSE INDEX ' ||
  1545.                         lower(v_index_name);
  1546.           ELSIF v_uniqueness = 'UNIQUE' AND
  1547.                 v_index_type = 'FUNCTION-BASED NORMAL' THEN
  1548.           
  1549.             v_string := v_prompt || ' CREATE UNIQUE, FUNCTION INDEX ' ||
  1550.                         lower(v_index_name);
  1551.           ELSIF v_uniqueness <> 'UNIQUE' AND
  1552.                 v_index_type = 'FUNCTION-BASED NORMAL' THEN
  1553.           
  1554.             v_string := v_prompt || ' CREATE FUNCTION INDEX ' ||
  1555.                         lower(v_index_name);
  1556.           END IF;
  1557.         
  1558.           insert_rec(n_line_no,
  1559.                      v_object_type,
  1560.                      v_username,
  1561.                      v_index_name,
  1562.                      v_string);
  1563.           n_line_no := n_line_no + 1;
  1564.         END IF;
  1565.       
  1566.         IF v_uniqueness = 'UNIQUE' AND v_index_type = 'NORMAL' THEN
  1567.         
  1568.           v_string := 'CREATE UNIQUE INDEX ' || lower(v_index_name);
  1569.           insert_rec(n_line_no,
  1570.                      v_object_type,
  1571.                      v_username,
  1572.                      v_index_name,
  1573.                      v_string);
  1574.           n_line_no := n_line_no + 1;
  1575.         ELSIF v_uniqueness <> 'UNIQUE' AND v_index_type = 'NORMAL' THEN
  1576.         
  1577.           v_string := 'CREATE INDEX ' || lower(v_index_name);
  1578.           insert_rec(n_line_no,
  1579.                      v_object_type,
  1580.                      v_username,
  1581.                      v_index_name,
  1582.                      v_string);
  1583.           n_line_no := n_line_no + 1;
  1584.         ELSIF v_index_type = 'BITMAP' THEN
  1585.         
  1586.           v_string := 'CREATE BITMAP INDEX ' || lower(v_index_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.         ELSIF v_uniqueness = 'UNIQUE' AND v_index_type = 'NORMAL/REV' THEN
  1594.         
  1595.           v_string := 'CREATE UNIQUE INDEX ' || lower(v_index_name);
  1596.           insert_rec(n_line_no,
  1597.                      v_object_type,
  1598.                      v_username,
  1599.                      v_index_name,
  1600.                      v_string);
  1601.           n_line_no := n_line_no + 1;
  1602.         ELSIF v_uniqueness <> 'UNIQUE' AND v_index_type = 'NORMAL/REV' THEN
  1603.         
  1604.           v_string := 'CREATE INDEX ' || lower(v_index_name);
  1605.           insert_rec(n_line_no,
  1606.                      v_object_type,
  1607.                      v_username,
  1608.                      v_index_name,
  1609.                      v_string);
  1610.           n_line_no := n_line_no + 1;
  1611.         ELSIF v_uniqueness = 'UNIQUE' AND
  1612.               v_index_type = 'FUNCTION-BASED NORMAL' THEN
  1613.         
  1614.           v_string := 'CREATE UNIQUE INDEX ' || lower(v_index_name);
  1615.           insert_rec(n_line_no,
  1616.                      v_object_type,
  1617.                      v_username,
  1618.                      v_index_name,
  1619.                      v_string);
  1620.           n_line_no := n_line_no + 1;
  1621.         ELSIF v_uniqueness <> 'UNIQUE' AND
  1622.               v_index_type = 'FUNCTION-BASED NORMAL' THEN
  1623.         
  1624.           v_string := 'CREATE INDEX ' || lower(v_index_name);
  1625.           insert_rec(n_line_no,
  1626.                      v_object_type,
  1627.                      v_username,
  1628.                      v_index_name,
  1629.                      v_string);
  1630.           n_line_no := n_line_no + 1;
  1631.         END IF;
  1632.         IF v_index_type <> 'FUNCTION-BASED NORMAL' THEN
  1633.           OPEN cur_cols(v_index_name, v_table_name);
  1634.           LOOP
  1635.             FETCH cur_cols
  1636.               INTO lv_column_name;
  1637.             EXIT WHEN cur_cols%NOTFOUND;
  1638.             IF (b_first_rec) THEN
  1639.               v_string    := chr(9) || 'ON ' || lower(v_table_name) || ' (';
  1640.               b_first_rec := FALSE;
  1641.             ELSE
  1642.               v_string := v_string || ', ';
  1643.             END IF;
  1644.             v_string := v_string || lower(lv_column_name);
  1645.           END LOOP;
  1646.           CLOSE cur_cols;
  1647.         ELSE
  1648.           OPEN cur_fun_expression(v_index_name, v_table_name);
  1649.           LOOP
  1650.             FETCH cur_fun_expression
  1651.               INTO lv_column_name;
  1652.             EXIT WHEN cur_fun_expression%NOTFOUND;
  1653.           
  1654.             lv_column_name := replace(lv_column_name, '"''');
  1655.             v_string       := chr(9) || 'ON ' || lower(v_table_name) || ' (';
  1656.             n_temp         := length(v_string);
  1657.             n_temp         := length(chr(9));
  1658.             v_string       := v_string || lower(lv_column_name);
  1659.           END LOOP;
  1660.           CLOSE cur_fun_expression;
  1661.         
  1662.         END IF;
  1663.       
  1664.         v_string := v_string || ')';
  1665.         insert_rec(n_line_no,
  1666.                    v_object_type,
  1667.                    v_username,
  1668.                    v_index_name,
  1669.                    v_string);
  1670.         n_line_no := n_line_no + 1;
  1671.       
  1672.         IF upper(v_gen_store_clause) = 'T' THEN
  1673.           v_string := null;
  1674.           v_string := v_logging;
  1675.           insert_rec(n_line_no,
  1676.                      v_object_type,
  1677.                      v_username,
  1678.                      v_index_name,
  1679.                      v_string);
  1680.           n_line_no := n_line_no + 1;
  1681.         
  1682.           v_string := 'PCTFREE ' || to_char(n_pct_free);
  1683.           insert_rec(n_line_no,
  1684.                      v_object_type,
  1685.                      v_username,
  1686.                      v_index_name,
  1687.                      v_string);
  1688.           n_line_no := n_line_no + 1;
  1689.         
  1690.           v_string := 'INITRANS ' || to_char(n_ini_trans) || ' MAXTRANS ' ||
  1691.                       to_char(n_max_trans);
  1692.           insert_rec(n_line_no,
  1693.                      v_object_type,
  1694.                      v_username,
  1695.                      v_index_name,
  1696.                      v_string);
  1697.           n_line_no := n_line_no + 1;
  1698.         
  1699.           v_string := 'TABLESPACE ' || v_tablespace_name || ' ';
  1700.           insert_rec(n_line_no,
  1701.                      v_object_type,
  1702.                      v_username,
  1703.                      v_index_name,
  1704.                      v_string);
  1705.           n_line_no := n_line_no + 1;
  1706.         
  1707.           v_string := 'STORAGE (';
  1708.           insert_rec(n_line_no,
  1709.                      v_object_type,
  1710.                      v_username,
  1711.                      v_index_name,
  1712.                      v_string);
  1713.           n_line_no := n_line_no + 1;
  1714.         
  1715.           v_string := chr(9) || 'INITIAL ' || to_char(n_initial_extent);
  1716.           IF n_next_extent IS NOT NULL THEN
  1717.             v_string := v_string || ' NEXT ' || to_char(n_next_extent);
  1718.           END IF;
  1719.           insert_rec(n_line_no,
  1720.                      v_object_type,
  1721.                      v_username,
  1722.                      v_index_name,
  1723.                      v_string);
  1724.           n_line_no := n_line_no + 1;
  1725.         
  1726.           v_string := chr(9) || 'MINEXTENTS ' || to_char(n_min_extents) ||
  1727.                       ' MAXEXTENTS ' || to_char(n_max_extents) ||
  1728.                       ' PCTINCREASE ' || to_char(nvl(n_pct_increase, 0));
  1729.           insert_rec(n_line_no,
  1730.                      v_object_type,
  1731.                      v_username,
  1732.                      v_index_name,
  1733.                      v_string);
  1734.           n_line_no := n_line_no + 1;
  1735.         
  1736.           v_string := chr(9) || 'FREELISTS ' || to_char(n_freelists) ||
  1737.                       ' FREELIST GROUPS ' || to_char(n_freelist_groups);
  1738.           insert_rec(n_line_no,
  1739.                      v_object_type,
  1740.                      v_username,
  1741.                      v_index_name,
  1742.                      v_string);
  1743.           n_line_no := n_line_no + 1;
  1744.         
  1745.           v_string := chr(9) || 'BUFFER_POOL ' || v_buffer_pool || ' ';
  1746.           insert_rec(n_line_no,
  1747.                      v_object_type,
  1748.                      v_username,
  1749.                      v_index_name,
  1750.                      v_string);
  1751.           n_line_no := n_line_no + 1;
  1752.         
  1753.           UPDATE temp_for_pkg_gen_sql2000_temp
  1754.              SET sql_text = sql_text || ')'
  1755.            WHERE line_no = n_line_no - 1
  1756.              AND object_type = v_object_type;
  1757.         ELSE
  1758.           IF upper(v_gen_store_clause) = 'F' AND upper(v_gen_ts_only) = 'T' THEN
  1759.             v_string := 'TABLESPACE ' || v_tablespace_name || ' ';
  1760.             insert_rec(n_line_no,
  1761.                        v_object_type,
  1762.                        v_username,
  1763.                        v_index_name,
  1764.                        v_string);
  1765.             n_line_no := n_line_no + 1;
  1766.           END IF;
  1767.         END IF;
  1768.       
  1769.         IF v_index_type <> 'NORMAL/REV' THEN
  1770.           UPDATE temp_for_pkg_gen_sql2000_temp
  1771.              SET sql_text = sql_text || ';'
  1772.            WHERE line_no = n_line_no - 1
  1773.              AND object_type = v_object_type;
  1774.         ELSE
  1775.           UPDATE temp_for_pkg_gen_sql2000_temp
  1776.              SET sql_text = sql_text || ' REVERSE;'
  1777.            WHERE line_no = n_line_no - 1
  1778.              AND object_type = v_object_type;
  1779.         END IF;
  1780.         v_string := '                                                  ';
  1781.         insert_rec(n_line_no,
  1782.                    v_object_type,
  1783.                    v_username,
  1784.                    v_index_name,
  1785.                    v_string);
  1786.         n_line_no := n_line_no + 1;
  1787.       END IF;
  1788.     END LOOP;
  1789.     CLOSE cur_indxes;
  1790.   
  1791.     SELECT COUNT(*) INTO n_temp FROM user_indexes WHERE index_type = 'LOB';
  1792.   
  1793.     IF n_temp > 0 THEN
  1794.       v_string := '                                                  ';
  1795.       insert_rec(n_line_no,
  1796.                  v_object_type,
  1797.                  v_username,
  1798.                  'LOB INDEX',
  1799.                  v_string);
  1800.       n_line_no := n_line_no + 1;
  1801.     
  1802.       v_string := '-- There is some LOB index, and we don''t list;';
  1803.       insert_rec(n_line_no,
  1804.                  v_object_type,
  1805.                  v_username,
  1806.                  'LOB INDEX',
  1807.                  v_string);
  1808.       n_line_no := n_line_no + 1;
  1809.     
  1810.       v_string := '                                                  ';
  1811.       insert_rec(n_line_no,
  1812.                  v_object_type,
  1813.                  v_username,
  1814.                  'LOB INDEX',
  1815.                  v_string);
  1816.       n_line_no := n_line_no + 1;
  1817.     
  1818.       v_string := '                                                  ';
  1819.       insert_rec(n_line_no,
  1820.                  v_object_type,
  1821.                  v_username,
  1822.                  'LOB INDEX',
  1823.                  v_string);
  1824.       n_line_no := n_line_no + 1;
  1825.     END IF;
  1826.   
  1827.     COMMIT;
  1828.   END;
  1829.   PROCEDURE pro_reb_indx_sql(p_v_gen_store_clause    VARCHAR2 default 'T',
  1830.                              p_v_rebuild_online      VARCHAR2 default 'T',
  1831.                              p_v_display_prompt_info VARCHAR2 default 'T') AS
  1832.     CURSOR cur_indxes IS
  1833.       SELECT index_name,
  1834.              table_owner,
  1835.              table_name,
  1836.              index_type,
  1837.              uniqueness,
  1838.              tablespace_name,
  1839.              ini_trans,
  1840.              max_trans,
  1841.              initial_extent,
  1842.              next_extent,
  1843.              min_extents,
  1844.              max_extents,
  1845.              pct_increase,
  1846.              pct_free,
  1847.              freelists,
  1848.              freelist_groups,
  1849.              buffer_pool,
  1850.              decode(logging, 'YES', 'LOGGING', 'NOLOGGING') logging
  1851.         FROM user_indexes
  1852.        WHERE index_type <> 'LOB'
  1853.        ORDER BY index_name;
  1854.   
  1855.     v_index_name          user_indexes.index_name%TYPE;
  1856.     v_table_owner         user_indexes.table_owner%TYPE;
  1857.     v_table_name          user_indexes.table_name%TYPE;
  1858.     v_index_type          user_indexes.index_type%TYPE;
  1859.     v_uniqueness          user_indexes.uniqueness%TYPE;
  1860.     v_tablespace_name     user_indexes.tablespace_name%TYPE;
  1861.     n_ini_trans           user_indexes.ini_trans%TYPE;
  1862.     n_max_trans           user_indexes.max_trans%TYPE;
  1863.     n_initial_extent      user_indexes.initial_extent%TYPE;
  1864.     n_next_extent         user_indexes.next_extent%TYPE;
  1865.     n_min_extents         user_indexes.min_extents%TYPE;
  1866.     n_max_extents         user_indexes.max_extents%TYPE;
  1867.     n_pct_increase        user_indexes.pct_increase%TYPE;
  1868.     n_pct_free            user_indexes.pct_free%TYPE;
  1869.     n_freelists           user_indexes.freelists%TYPE;
  1870.     n_freelist_groups     user_indexes.freelist_groups%TYPE;
  1871.     v_buffer_pool         user_indexes.buffer_pool%TYPE;
  1872.     v_logging             VARCHAR2(15);
  1873.     lv_column_name        user_ind_columns.column_name%TYPE;
  1874.     b_first_rec           BOOLEAN;
  1875.     v_string              VARCHAR2(800);
  1876.     n_line_no             NUMBER := 0;
  1877.     v_gen_store_clause    VARCHAR2(10);
  1878.     v_rebuild_online      VARCHAR2(10);
  1879.     v_display_prompt_info VARCHAR2(10);
  1880.     n_temp                NUMBER(10, 0);
  1881.     v_object_type         VARCHAR2(30);
  1882.     v_prompt              VARCHAR2(30);
  1883.     v_username            VARCHAR2(30);
  1884.     PROCEDURE insert_rec(p_line_no     INTEGER,
  1885.                          p_object_type VARCHAR2,
  1886.                          p_user_name   VARCHAR2,
  1887.                          p_index_name  VARCHAR2,
  1888.                          p_string      VARCHAR2) IS
  1889.     BEGIN
  1890.       INSERT INTO temp_for_pkg_gen_sql2000_temp
  1891.         (line_no, object_type, user_name, object_name, sql_text)
  1892.       VALUES
  1893.         (p_line_no, p_object_type, p_user_name, p_index_name, p_string);
  1894.     END;
  1895.   BEGIN
  1896.     v_gen_store_clause    := p_v_gen_store_clause;
  1897.     v_display_prompt_info := p_v_display_prompt_info;
  1898.     v_rebuild_online      := p_v_rebuild_online;
  1899.     v_object_type         := 'REBUILD_INDEX';
  1900.     v_prompt              := '-- prompt ';
  1901.   
  1902.     SELECT username INTO v_username FROM user_users;
  1903.   
  1904.     DELETE FROM temp_for_pkg_gen_sql2000_temp
  1905.      WHERE object_type = v_object_type;
  1906.     COMMIT;
  1907.   
  1908.     n_line_no := 1;
  1909.   
  1910.     OPEN cur_indxes;
  1911.     LOOP
  1912.       FETCH cur_indxes
  1913.         INTO v_index_name, v_table_owner, v_table_name, v_index_type, v_uniqueness, v_tablespace_name, n_ini_trans, 
  1914. n_max_trans, n_initial_extent, n_next_extent, n_min_extents, n_max_extents, n_pct_increase, n_pct_free, n_freelists, 
  1915. n_freelist_groups, v_buffer_pool, v_logging;
  1916.       EXIT WHEN cur_indxes%NOTFOUND;
  1917.     
  1918.       b_first_rec := TRUE;
  1919.     
  1920.       IF upper(p_v_display_prompt_info) = 'T' THEN
  1921.         IF v_rebuild_online = 'T' THEN
  1922.           v_string := v_prompt || ' REBUILD INDEX ' || lower(v_index_name) ||
  1923.                       ' ONLINE ';
  1924.         ELSE
  1925.           v_string := v_prompt || ' REBUILD INDEX ' || lower(v_index_name);
  1926.         END IF;
  1927.         insert_rec(n_line_no,
  1928.                    v_object_type,
  1929.                    v_username,
  1930.                    v_index_name,
  1931.                    v_string);
  1932.         n_line_no := n_line_no + 1;
  1933.       END IF;
  1934.     
  1935.       IF v_rebuild_online = 'T' THEN
  1936.         v_string := 'ALTER INDEX ' || lower(v_index_name) ||
  1937.                     ' REBUILD ONLINE ';
  1938.       ELSE
  1939.         v_string := 'ALTER INDEX ' || lower(v_index_name) || ' REBUILD ';
  1940.       END IF;
  1941.       insert_rec(n_line_no,
  1942.                  v_object_type,
  1943.                  v_username,
  1944.                  v_index_name,
  1945.                  v_string);
  1946.       n_line_no := n_line_no + 1;
  1947.     
  1948.       IF upper(v_gen_store_clause) = 'T' THEN
  1949.       
  1950.         v_string := null;
  1951.         v_string := v_logging;
  1952.         insert_rec(n_line_no,
  1953.                    v_object_type,
  1954.                    v_username,
  1955.                    v_index_name,
  1956.                    v_string);
  1957.         n_line_no := n_line_no + 1;
  1958.       
  1959.         v_string := 'PCTFREE ' || to_char(n_pct_free);
  1960.         insert_rec(n_line_no,
  1961.                    v_object_type,
  1962.                    v_username,
  1963.                    v_index_name,
  1964.                    v_string);
  1965.         n_line_no := n_line_no + 1;
  1966.       
  1967.         v_string := 'INITRANS ' || to_char(n_ini_trans) || ' MAXTRANS ' ||
  1968.                     to_char(n_max_trans);
  1969.         insert_rec(n_line_no,
  1970.                    v_object_type,
  1971.                    v_username,
  1972.                    v_index_name,
  1973.                    v_string);
  1974.         n_line_no := n_line_no + 1;
  1975.       
  1976.         v_string := 'TABLESPACE ' || v_tablespace_name || ' ';
  1977.         insert_rec(n_line_no,
  1978.                    v_object_type,
  1979.                    v_username,
  1980.                    v_index_name,
  1981.                    v_string);
  1982.         n_line_no := n_line_no + 1;
  1983.       
  1984.         v_string := 'STORAGE (';
  1985.         insert_rec(n_line_no,
  1986.                    v_object_type,
  1987.                    v_username,
  1988.                    v_index_name,
  1989.                    v_string);
  1990.         n_line_no := n_line_no + 1;
  1991.       
  1992.         v_string := chr(9) || 'INITIAL ' || to_char(n_initial_extent);
  1993.         IF n_next_extent IS NOT NULL THEN
  1994.           v_string := v_string || ' NEXT ' || to_char(n_next_extent);
  1995.         END IF;
  1996.         insert_rec(n_line_no,
  1997.                    v_object_type,
  1998.                    v_username,
  1999.                    v_index_name,
  2000.                    v_string);
  2001.         n_line_no := n_line_no + 1;
  2002.       
  2003.         v_string := chr(9) || 'MINEXTENTS ' || to_char(n_min_extents) ||
  2004.                     ' MAXEXTENTS ' || to_char(n_max_extents) ||
  2005.                     ' PCTINCREASE ' || to_char(nvl(n_pct_increase, 0));
  2006.         insert_rec(n_line_no,
  2007.                    v_object_type,
  2008.                    v_username,
  2009.                    v_index_name,
  2010.                    v_string);
  2011.         n_line_no := n_line_no + 1;
  2012.       
  2013.         IF n_freelists IS NOT NULL AND n_freelist_groups IS NOT NULL THEN
  2014.           v_string := chr(9) || 'FREELISTS ' || to_char(n_freelists) ||
  2015.                       ' FREELIST GROUPS ' || to_char(n_freelist_groups);
  2016.           insert_rec(n_line_no,
  2017.                      v_object_type,
  2018.                      v_username,
  2019.                      v_index_name,
  2020.                      v_string);
  2021.           n_line_no := n_line_no + 1;
  2022.         END IF;
  2023.       
  2024.         v_string := chr(9) || 'BUFFER_POOL ' || v_buffer_pool || ' ';
  2025.         insert_rec(n_line_no,
  2026.                    v_object_type,
  2027.                    v_username,
  2028.                    v_index_name,
  2029.                    v_string);
  2030.         n_line_no := n_line_no + 1;
  2031.       
  2032.         UPDATE temp_for_pkg_gen_sql2000_temp
  2033.            SET sql_text = sql_text || ')'
  2034.          WHERE line_no = n_line_no - 1
  2035.            AND object_type = v_object_type;
  2036.       END IF;
  2037.     
  2038.       UPDATE temp_for_pkg_gen_sql2000_temp
  2039.          SET sql_text = sql_text || ';'
  2040.        WHERE line_no = n_line_no - 1
  2041.          AND object_type = v_object_type;
  2042.     
  2043.       v_string := '                                                  ';
  2044.       insert_rec(n_line_no,
  2045.                  v_object_type,
  2046.                  v_username,
  2047.                  v_index_name,
  2048.                  v_string);
  2049.       n_line_no := n_line_no + 1;
  2050.     END LOOP;
  2051.     CLOSE cur_indxes;
  2052.   
  2053.     SELECT COUNT(*) INTO n_temp FROM user_indexes WHERE index_type = 'LOB';
  2054.   
  2055.     IF n_temp > 0 THEN
  2056.       v_string := '                                                  ';
  2057.       insert_rec(n_line_no,
  2058.                  v_object_type,
  2059.                  v_username,
  2060.                  'LOB INDEX',
  2061.                  v_string);
  2062.       n_line_no := n_line_no + 1;
  2063.     
  2064.       v_string := '-- There is some LOB index, and we don''t list;';
  2065.       insert_rec(n_line_no,
  2066.                  v_object_type,
  2067.                  v_username,
  2068.                  'LOB INDEX',
  2069.                  v_string);
  2070.       n_line_no := n_line_no + 1;
  2071.     
  2072.       v_string := '                                                  ';
  2073.       insert_rec(n_line_no,
  2074.                  v_object_type,
  2075.                  v_username,
  2076.                  'LOB INDEX',
  2077.                  v_string);
  2078.       n_line_no := n_line_no + 1;
  2079.     
  2080.       v_string := '                                                  ';
  2081.       insert_rec(n_line_no,
  2082.                  v_object_type,
  2083.                  v_username,
  2084.                  'LOB INDEX',
  2085.                  v_string);
  2086.       n_line_no := n_line_no + 1;
  2087.     END IF;
  2088.   
  2089.     COMMIT;
  2090.   END;
  2091.   PROCEDURE pro_view_sql(p_v_gen_drop_sql        VARCHAR2 default 'T',
  2092.                          p_v_gen_create_sql      VARCHAR2 default 'T',
  2093.                          p_v_display_prompt_info VARCHAR2 default 'T') AS
  2094.     CURSOR cur_views IS
  2095.       select view_name, text from user_views order by view_name;
  2096.     CURSOR cur_cols(v_name VARCHAR2) IS
  2097.       SELECT table_name,
  2098.              column_name,
  2099.              data_type,
  2100.              data_length,
  2101.              data_precision,
  2102.              data_scale,
  2103.              nullable,
  2104.              data_default
  2105.         FROM user_tab_columns
  2106.        WHERE table_name = v_name
  2107.        ORDER BY column_id;
  2108.     v_username    VARCHAR2(30);
  2109.     v_view_name   VARCHAR2(100);
  2110.     v_col_names   VARCHAR2(2000);
  2111.     v_text        VARCHAR2(30000);
  2112.     v_sql         VARCHAR2(30000);
  2113.     v_sql_temp    VARCHAR2(30000);
  2114.     n_line_no     NUMBER(100);
  2115.     n38_count     NUMBER(380);
  2116.     n_position    NUMBER(380);
  2117.     v_object_type VARCHAR2(30);
  2118.     v_prompt      VARCHAR2(30);
  2119.     PROCEDURE insert_rec(p_line_no     INTEGER,
  2120.                          p_object_type VARCHAR2,
  2121.                          p_user_name   VARCHAR2,
  2122.                          p_view_name   VARCHAR2,
  2123.                          p_string      VARCHAR2) IS
  2124.     BEGIN
  2125.       INSERT INTO temp_for_pkg_gen_sql4000_temp
  2126.         (line_no, object_type, user_name, object_name, sql_text)
  2127.       VALUES
  2128.         (p_line_no, p_object_type, p_user_name, p_view_name, p_string);
  2129.     END;
  2130.   BEGIN
  2131.   
  2132.     v_object_type := 'VIEW';
  2133.     v_prompt      := '-- prompt ';
  2134.   
  2135.     SELECT username INTO v_username FROM user_users;
  2136.   
  2137.     DELETE temp_for_pkg_gen_sql4000_temp WHERE object_type = v_object_type;
  2138.     COMMIT;
  2139.   
  2140.     n_line_no := 1;
  2141.   
  2142.     OPEN cur_views;
  2143.     LOOP
  2144.       FETCH cur_views
  2145.         INTO v_view_name, v_text;
  2146.       EXIT WHEN cur_views%NOTFOUND;
  2147.     
  2148.       IF upper(p_v_gen_drop_sql) = 'T' THEN
  2149.         IF upper(p_v_display_prompt_info) = 'T' THEN
  2150.           v_sql := v_prompt || ' DROP   VIEW ' || v_view_name;
  2151.           insert_rec(n_line_no,
  2152.                      v_object_type,
  2153.                      v_username,
  2154.                      v_view_name,
  2155.                      v_sql);
  2156.           n_line_no := n_line_no + 1;
  2157.         END IF;
  2158.       
  2159.         v_sql := 'DROP VIEW ' || v_view_name || ';';
  2160.         insert_rec(n_line_no,
  2161.                    v_object_type,
  2162.                    v_username,
  2163.                    v_view_name,
  2164.                    v_sql);
  2165.         n_line_no := n_line_no + 1;
  2166.       
  2167.         v_sql := '                         ';
  2168.         insert_rec(n_line_no,
  2169.                    v_object_type,
  2170.                    v_username,
  2171.                    v_view_name,
  2172.                    v_sql);
  2173.         n_line_no := n_line_no + 1;
  2174.       END IF;
  2175.     
  2176.       IF upper(p_v_gen_create_sql) = 'T' THEN
  2177.         IF upper(p_v_display_prompt_info) = 'T' THEN
  2178.           v_sql := v_prompt || ' CREATE VIEW ' || v_view_name;
  2179.           insert_rec(n_line_no,
  2180.                      v_object_type,
  2181.                      v_username,
  2182.                      v_view_name,
  2183.                      v_sql);
  2184.           n_line_no := n_line_no + 1;
  2185.         END IF;
  2186.       
  2187.         v_sql := 'CREATE OR REPLACE VIEW ' || v_view_name;
  2188.         insert_rec(n_line_no,
  2189.                    v_object_type,
  2190.                    v_username,
  2191.                    v_view_name,
  2192.                    v_sql);
  2193.         n_line_no := n_line_no + 1;
  2194.       
  2195.         v_sql := '(';
  2196.         insert_rec(n_line_no,
  2197.                    v_object_type,
  2198.                    v_username,
  2199.                    v_view_name,
  2200.                    v_sql);
  2201.         n_line_no := n_line_no + 1;
  2202.       
  2203.         v_col_names := '';
  2204.         n38_count   := 0;
  2205.         FOR cur_cols_rec IN cur_cols(v_view_name) LOOP
  2206.         
  2207.           v_col_names := v_col_names || cur_cols_rec.column_name || ', ';
  2208.           n38_count   := n38_count + 1;
  2209.           IF MOD(n38_count, 5) = 0 THEN
  2210.             v_sql := chr(9) || v_col_names;
  2211.             insert_rec(n_line_no,
  2212.                        v_object_type,
  2213.                        v_username,
  2214.                        v_view_name,
  2215.                        v_sql);
  2216.             n_line_no   := n_line_no + 1;
  2217.             v_col_names := '';
  2218.           END IF;
  2219.         END LOOP;
  2220.       
  2221.         IF length(v_col_names) > 2 THEN
  2222.           v_col_names := substr(v_col_names, 1, length(v_col_names) - 2);
  2223.           v_sql       := chr(9) || v_col_names;
  2224.           insert_rec(n_line_no,
  2225.                      v_object_type,
  2226.                      v_username,
  2227.                      v_view_name,
  2228.                      v_sql);
  2229.           n_line_no := n_line_no + 1;
  2230.         ELSE
  2231.           UPDATE temp_for_pkg_gen_sql4000_temp
  2232.              SET sql_text = substr(sql_text, 1, length(sql_text) - 2)
  2233.            WHERE line_no = n_line_no - 1
  2234.              AND object_type = v_object_type;
  2235.         END IF;
  2236.       
  2237.         v_sql := ')';
  2238.         insert_rec(n_line_no,
  2239.                    v_object_type,
  2240.                    v_username,
  2241.                    v_view_name,
  2242.                    v_sql);
  2243.         n_line_no := n_line_no + 1;
  2244.       
  2245.         v_sql := 'AS';
  2246.         insert_rec(n_line_no,
  2247.                    v_object_type,
  2248.                    v_username,
  2249.                    v_view_name,
  2250.                    v_sql);
  2251.         n_line_no := n_line_no + 1;
  2252.       
  2253.         v_text := replace(v_text, ','', ');
  2254.       
  2255.         v_sql := v_text;
  2256.         IF length(v_sql) > 3800 THEN
  2257.           WHILE length(v_sql) > 3800 LOOP
  2258.             n_position := instr(substr(v_sql, 13800), ',', -1);
  2259.             insert_rec(n_line_no,
  2260.                        v_object_type,
  2261.                        v_username,
  2262.                        v_view_name,
  2263.                        substr(v_sql, 1, n_position));
  2264.             v_sql := substr(v_sql, n_position + 1);
  2265.           END LOOP;
  2266.           insert_rec(n_line_no,
  2267.                      v_object_type,
  2268.                      v_username,
  2269.                      v_view_name,
  2270.                      v_sql);
  2271.         ELSE
  2272.           insert_rec(n_line_no,
  2273.                      v_object_type,
  2274.                      v_username,
  2275.                      v_view_name,
  2276.                      v_sql);
  2277.         END IF;
  2278.       
  2279.         n_line_no := n_line_no + 1;
  2280.       
  2281.         UPDATE temp_for_pkg_gen_sql4000_temp
  2282.            SET sql_text = sql_text || ';'
  2283.          WHERE line_no = n_line_no - 1
  2284.            AND object_type = v_object_type;
  2285.       
  2286.         v_sql := '                         ';
  2287.         insert_rec(n_line_no,
  2288.                    v_object_type,
  2289.                    v_username,
  2290.                    v_view_name,
  2291.                    v_sql);
  2292.         n_line_no := n_line_no + 1;
  2293.       
  2294.       END IF;
  2295.     END LOOP;
  2296.     CLOSE cur_views;
  2297.     COMMIT;
  2298.   END;
  2299.   PROCEDURE pro_seq_max_val_sql(p_v_gen_drop_sql        VARCHAR2 default 'T',
  2300.                                 p_v_gen_create_sql      VARCHAR2 default 'T',
  2301.                                 p_v_display_prompt_info VARCHAR2 default 'T') AS
  2302.     v_sql     VARCHAR2(500);
  2303.     n_max_id  NUMBER(380);
  2304.     v_max_val VARCHAR2(1000);
  2305.     CURSOR cur_etl_data IS
  2306.       SELECT table_name FROM user_tables;
  2307.     rec_etl_data cur_etl_data%rowtype;
  2308.     type ref_cur is REF CURSOR; -- 定义一个ref 类型的游标
  2309.     cur_id ref_cur;
  2310.     CURSOR cur_cols(t_name VARCHAR2) IS
  2311.       SELECT column_name, data_type
  2312.         FROM user_tab_columns
  2313.        WHERE table_name = t_name
  2314.        ORDER BY column_id;
  2315.     rec_col_name    cur_cols%rowtype;
  2316.     v_sequence_name VARCHAR2(50);
  2317.     n_line_no       NUMBER(380);
  2318.     v_object_type   VARCHAR2(30);
  2319.     v_prompt        VARCHAR2(30);
  2320.     v_username      VARCHAR2(30);
  2321.     PROCEDURE insert_rec(p_line_no       INTEGER,
  2322.                          p_object_type   VARCHAR2,
  2323.                          p_user_name     VARCHAR2,
  2324.                          p_sequence_name VARCHAR2,
  2325.                          p_string        VARCHAR2) IS
  2326.     BEGIN
  2327.       INSERT INTO temp_for_pkg_gen_sql2000_temp
  2328.         (line_no, object_type, user_name, object_name, sql_text)
  2329.       VALUES
  2330.         (p_line_no, p_object_type, p_user_name, p_sequence_name, p_string);
  2331.     END;
  2332.   BEGIN
  2333.     n_line_no     := 1;
  2334.     v_object_type := 'SEQUENCE_CHAR';
  2335.     v_prompt      := '-- prompt ';
  2336.   
  2337.     SELECT username INTO v_username FROM user_users;
  2338.   
  2339.     DELETE temp_for_pkg_gen_sql2000_temp WHERE object_type = v_object_type;
  2340.   
  2341.     COMMIT;
  2342.   
  2343.     OPEN cur_etl_data;
  2344.     LOOP
  2345.       FETCH cur_etl_data
  2346.         INTO rec_etl_data;
  2347.       EXIT WHEN cur_etl_data%NOTFOUND;
  2348.     
  2349.       -- 得到表的第一个列
  2350.       OPEN cur_cols(rec_etl_data.table_name);
  2351.       LOOP
  2352.         FETCH cur_cols
  2353.           INTO rec_col_name;
  2354.         EXIT WHEN cur_cols%NOTFOUND;
  2355.         EXIT;
  2356.       END LOOP;
  2357.       CLOSE cur_cols;
  2358.     
  2359.       IF rec_col_name.data_type = 'VARCHAR2' OR
  2360.          rec_col_name.data_type = 'VARCHAR' OR
  2361.          rec_col_name.data_type = 'CHAR' THEN
  2362.         BEGIN
  2363.           v_sql := 'SELECT max(to_NUMBER(' || rec_col_name.column_name ||
  2364.                    ')) FROM ' || rec_etl_data.table_name || '';
  2365.           OPEN cur_id FOR v_sql;
  2366.           LOOP
  2367.             FETCH cur_id
  2368.               INTO v_max_val;
  2369.             EXIT WHEN cur_id%NOTFOUND;
  2370.             EXIT;
  2371.           END LOOP;
  2372.           CLOSE cur_id;
  2373.         EXCEPTION
  2374.           WHEN others THEN
  2375.             IF cur_id%ISOPEN THEN
  2376.               CLOSE cur_id;
  2377.             END IF;
  2378.             v_max_val := '-1000';
  2379.         END;
  2380.       ELSIF rec_col_name.data_type = 'NUMBER' THEN
  2381.         v_sql := 'SELECT max(' || rec_col_name.column_name || ') FROM ' ||
  2382.                  rec_etl_data.table_name || '';
  2383.         OPEN cur_id FOR v_sql;
  2384.         LOOP
  2385.           FETCH cur_id
  2386.             INTO n_max_id;
  2387.           EXIT WHEN cur_id%NOTFOUND;
  2388.           EXIT;
  2389.         END LOOP;
  2390.         CLOSE cur_id;
  2391.       END IF;
  2392.     
  2393.       -- need modify, generate sequence name 
  2394.       v_sequence_name := 'seq_' || substr(rec_etl_data.table_name, 3) ||
  2395.                          '_id';
  2396.     
  2397.       IF p_v_gen_drop_sql = 'T' THEN
  2398.         IF p_v_display_prompt_info = 'T' THEN
  2399.           v_sql := v_prompt || ' DROP SEQUENCE ' || v_sequence_name;
  2400.           insert_rec(n_line_no,
  2401.                      v_object_type,
  2402.                      v_username,
  2403.                      v_sequence_name,
  2404.                      v_sql);
  2405.           n_line_no := n_line_no + 1;
  2406.         END IF;
  2407.       
  2408.         v_sql := 'DROP SEQUENCE ' || v_sequence_name || ';';
  2409.         insert_rec(n_line_no,
  2410.                    v_object_type,
  2411.                    v_username,
  2412.                    v_sequence_name,
  2413.                    v_sql);
  2414.         n_line_no := n_line_no + 1;
  2415.       
  2416.         v_sql := '                  ';
  2417.         insert_rec(n_line_no,
  2418.                    v_object_type,
  2419.                    v_username,
  2420.                    v_sequence_name,
  2421.                    v_sql);
  2422.         n_line_no := n_line_no + 1;
  2423.       END IF;
  2424.     
  2425.       IF p_v_gen_create_sql = 'T' THEN
  2426.         IF p_v_display_prompt_info = 'T' THEN
  2427.           v_sql := v_prompt || ' CREATE SEQUENCE ' || v_sequence_name;
  2428.           insert_rec(n_line_no,
  2429.                      v_object_type,
  2430.                      v_username,
  2431.                      v_sequence_name,
  2432.                      v_sql);
  2433.           n_line_no := n_line_no + 1;
  2434.         END IF;
  2435.       
  2436.         v_sql := 'CREATE SEQUENCE ' || v_sequence_name;
  2437.         insert_rec(n_line_no,
  2438.                    v_object_type,
  2439.                    v_username,
  2440.                    v_sequence_name,
  2441.                    v_sql);
  2442.         n_line_no := n_line_no + 1;
  2443.       
  2444.         -- handle the station : treate the sequence value as varchar column(primary key)
  2445.         IF rec_col_name.data_type = 'VARCHAR2' OR
  2446.            rec_col_name.data_type = 'VARCHAR' OR
  2447.            rec_col_name.data_type = 'CHAR' THEN
  2448.           v_sql := 'START WITH ' ||
  2449.                    to_char(to_number(nvl(v_max_val, '1')) + 1) || ' ';
  2450.         ELSIF rec_col_name.data_type = 'NUMBER' THEN
  2451.           v_sql := 'START WITH ' || TO_CHAR(nvl(n_max_id, 1) + 1) || ' ';
  2452.         END IF;
  2453.         insert_rec(n_line_no,
  2454.                    v_object_type,
  2455.                    v_username,
  2456.                    v_sequence_name,
  2457.                    v_sql);
  2458.         n_line_no := n_line_no + 1;
  2459.       
  2460.         v_sql := 'INCREMENT BY 1 ';
  2461.         insert_rec(n_line_no,
  2462.                    v_object_type,
  2463.                    v_username,
  2464.                    v_sequence_name,
  2465.                    v_sql);
  2466.         n_line_no := n_line_no + 1;
  2467.       
  2468.         v_sql := 'CACHE 100 NOCYCLE ';
  2469.         insert_rec(n_line_no,
  2470.                    v_object_type,
  2471.                    v_username,
  2472.                    v_sequence_name,
  2473.                    v_sql);
  2474.         n_line_no := n_line_no + 1;
  2475.       
  2476.         UPDATE temp_for_pkg_gen_sql2000_temp
  2477.            SET sql_text = sql_text || ';'
  2478.          WHERE line_no = n_line_no - 1
  2479.            AND object_type = v_object_type;
  2480.       
  2481.         v_sql := '  ';
  2482.         insert_rec(n_line_no,
  2483.                    v_object_type,
  2484.                    v_username,
  2485.                    v_sequence_name,
  2486.                    v_sql);
  2487.         n_line_no := n_line_no + 1;
  2488.       END IF;
  2489.     
  2490.     END LOOP;
  2491.     CLOSE cur_etl_data;
  2492.     COMMIT;
  2493.   END;
  2494.   PROCEDURE pro_seq_next_val_sql(p_v_gen_drop_sql        VARCHAR2 default 'T',
  2495.                                  p_v_gen_create_sql      VARCHAR2 default 'T',
  2496.                                  p_v_display_prompt_info VARCHAR2 default 'T') AS
  2497.     v_sql     VARCHAR2(2000);
  2498.     n_max_id  NUMBER(380);
  2499.     v_max_val VARCHAR2(1000);
  2500.     CURSOR cur_sequence IS
  2501.       SELECT * FROM user_sequences;
  2502.     rec_cur_sequence cur_sequence%rowtype;
  2503.     v_sequence_name  VARCHAR2(50);
  2504.     n_line_no        NUMBER(380);
  2505.     v_object_type    VARCHAR2(30);
  2506.     v_prompt         VARCHAR2(30);
  2507.     v_username       VARCHAR2(30);
  2508.     PROCEDURE insert_rec(p_line_no       INTEGER,
  2509.                          p_object_type   VARCHAR2,
  2510.                          p_user_name     VARCHAR2,
  2511.                          p_sequence_name VARCHAR2,
  2512.                          p_string        VARCHAR2) IS
  2513.     BEGIN
  2514.       INSERT INTO temp_for_pkg_gen_sql2000_temp
  2515.         (line_no, object_type, user_name, object_name, sql_text)
  2516.       VALUES
  2517.         (p_line_no, p_object_type, p_user_name, p_sequence_name, p_string);
  2518.     END;
  2519.   BEGIN
  2520.     n_line_no     := 1;
  2521.     v_object_type := 'SEQUENCE';
  2522.     v_prompt      := '-- prompt ';
  2523.   
  2524.     SELECT username INTO v_username FROM user_users;
  2525.   
  2526.     DELETE temp_for_pkg_gen_sql2000_temp WHERE object_type = v_object_type;
  2527.     COMMIT;
  2528.   
  2529.     OPEN cur_sequence;
  2530.     LOOP
  2531.       FETCH cur_sequence
  2532.         INTO rec_cur_sequence;
  2533.       EXIT WHEN cur_sequence%NOTFOUND;
  2534.     
  2535.       IF p_v_gen_drop_sql = 'T' THEN
  2536.         IF p_v_display_prompt_info = 'T' THEN
  2537.           v_sql := v_prompt || ' DROP SEQUENCE ' ||
  2538.                    rec_cur_sequence.sequence_name;
  2539.           insert_rec(n_line_no,
  2540.                      v_object_type,
  2541.                      v_username,
  2542.                      rec_cur_sequence.sequence_name,
  2543.                      v_sql);
  2544.           n_line_no := n_line_no + 1;
  2545.         END IF;
  2546.         v_sql := 'DROP SEQUENCE ' || rec_cur_sequence.sequence_name || ';';
  2547.         insert_rec(n_line_no,
  2548.                    v_object_type,
  2549.                    v_username,
  2550.                    rec_cur_sequence.sequence_name,
  2551.                    v_sql);
  2552.         n_line_no := n_line_no + 1;
  2553.       
  2554.         v_sql := '                  ';
  2555.         insert_rec(n_line_no,
  2556.                    v_object_type,
  2557.                    v_username,
  2558.                    rec_cur_sequence.sequence_name,
  2559.                    v_sql);
  2560.         n_line_no := n_line_no + 1;
  2561.       END IF;
  2562.     
  2563.       IF p_v_gen_create_sql = 'T' THEN
  2564.         IF p_v_display_prompt_info = 'T' THEN
  2565.           v_sql := v_prompt || ' CREATE SEQUENCE ' ||
  2566.                    rec_cur_sequence.sequence_name;
  2567.           insert_rec(n_line_no,
  2568.                      v_object_type,
  2569.                      v_username,
  2570.                      rec_cur_sequence.sequence_name,
  2571.                      v_sql);
  2572.           n_line_no := n_line_no + 1;
  2573.         END IF;
  2574.       
  2575.         v_sql := 'CREATE SEQUENCE ' || rec_cur_sequence.sequence_name;
  2576.         insert_rec(n_line_no,
  2577.                    v_object_type,
  2578.                    v_username,
  2579.                    rec_cur_sequence.sequence_name,
  2580.                    v_sql);
  2581.         n_line_no := n_line_no + 1;
  2582.       
  2583.         v_sql := 'MINVALUE ' || to_char(rec_cur_sequence.min_value);
  2584.         insert_rec(n_line_no,
  2585.                    v_object_type,
  2586.                    v_username,
  2587.                    rec_cur_sequence.sequence_name,
  2588.                    v_sql);
  2589.         n_line_no := n_line_no + 1;
  2590.       
  2591.         v_sql := 'MAXVALUE ' || to_char(rec_cur_sequence.max_value);
  2592.         insert_rec(n_line_no,
  2593.                    v_object_type,
  2594.                    v_username,
  2595.                    rec_cur_sequence.sequence_name,
  2596.                    v_sql);
  2597.         n_line_no := n_line_no + 1;
  2598.       
  2599.         v_sql := 'START WITH ' || to_char(rec_cur_sequence.last_number);
  2600.         insert_rec(n_line_no,
  2601.                    v_object_type,
  2602.                    v_username,
  2603.                    rec_cur_sequence.sequence_name,
  2604.                    v_sql);
  2605.         n_line_no := n_line_no + 1;
  2606.       
  2607.         v_sql := 'INCREMENT BY ' || to_char(rec_cur_sequence.increment_by);
  2608.         insert_rec(n_line_no,
  2609.                    v_object_type,
  2610.                    v_username,
  2611.                    rec_cur_sequence.sequence_name,
  2612.                    v_sql);
  2613.         n_line_no := n_line_no + 1;
  2614.       
  2615.         IF rec_cur_sequence.cache_size = 0 THEN
  2616.           v_sql := 'NOCACHE ';
  2617.         ELSE
  2618.           v_sql := 'CACHE ' || to_char(rec_cur_sequence.cache_size);
  2619.         END IF;
  2620.       
  2621.         IF rec_cur_sequence.cycle_flag = 'N' THEN
  2622.           v_sql := v_sql || ' NOCYCLE ';
  2623.         ELSE
  2624.           v_sql := v_sql || ' CYCLE ';
  2625.         END IF;
  2626.       
  2627.         insert_rec(n_line_no,
  2628.                    v_object_type,
  2629.                    v_username,
  2630.                    rec_cur_sequence.sequence_name,
  2631.                    v_sql);
  2632.         n_line_no := n_line_no + 1;
  2633.       
  2634.         UPDATE temp_for_pkg_gen_sql2000_temp
  2635.            SET sql_text = sql_text || ';'
  2636.          WHERE line_no = n_line_no - 1
  2637.            AND object_type = v_object_type;
  2638.       
  2639.         v_sql := '  ';
  2640.         insert_rec(n_line_no,
  2641.                    v_object_type,
  2642.                    v_username,
  2643.                    rec_cur_sequence.sequence_name,
  2644.                    v_sql);
  2645.         n_line_no := n_line_no + 1;
  2646.       END IF;
  2647.     
  2648.     END LOOP;
  2649.     CLOSE cur_sequence;
  2650.     COMMIT;
  2651.   END;
  2652.   PROCEDURE pro_seq_init_val_sql(p_v_gen_drop_sql        VARCHAR2 default 'T',
  2653.                                  p_v_gen_create_sql      VARCHAR2 default 'T',
  2654.                                  p_v_display_prompt_info VARCHAR2 default 'T') AS
  2655.     v_sql     VARCHAR2(2000);
  2656.     n_max_id  NUMBER(380);
  2657.     v_max_val VARCHAR2(1000);
  2658.     CURSOR cur_sequence IS
  2659.       SELECT * FROM user_sequences;
  2660.     rec_cur_sequence cur_sequence%rowtype;
  2661.     v_sequence_name  VARCHAR2(50);
  2662.     n_line_no        NUMBER(380);
  2663.     v_object_type    VARCHAR2(30);
  2664.     v_prompt         VARCHAR2(30);
  2665.     v_username       VARCHAR2(30);
  2666.     PROCEDURE insert_rec(p_line_no       INTEGER,
  2667.                          p_object_type   VARCHAR2,
  2668.                          p_user_name     VARCHAR2,
  2669.                          p_sequence_name VARCHAR2,
  2670.                          p_string        VARCHAR2) IS
  2671.     BEGIN
  2672.       INSERT INTO temp_for_pkg_gen_sql2000_temp
  2673.         (line_no, object_type, user_name, object_name, sql_text)
  2674.       VALUES
  2675.         (p_line_no, p_object_type, p_user_name, p_sequence_name, p_string);
  2676.     END;
  2677.   BEGIN
  2678.     n_line_no     := 1;
  2679.     v_object_type := 'SEQUENCE_INIT';
  2680.     v_prompt      := '-- prompt ';
  2681.   
  2682.     SELECT username INTO v_username FROM user_users;
  2683.   
  2684.     DELETE temp_for_pkg_gen_sql2000_temp WHERE object_type = v_object_type;
  2685.     COMMIT;
  2686.   
  2687.     OPEN cur_sequence;
  2688.     LOOP
  2689.       FETCH cur_sequence
  2690.         INTO rec_cur_sequence;
  2691.       EXIT WHEN cur_sequence%NOTFOUND;
  2692.     
  2693.       IF p_v_gen_drop_sql = 'T' THEN
  2694.         IF p_v_display_prompt_info = 'T' THEN
  2695.           v_sql := v_prompt || ' DROP SEQUENCE ' ||
  2696.                    rec_cur_sequence.sequence_name;
  2697.           insert_rec(n_line_no,
  2698.                      v_object_type,
  2699.                      v_username,
  2700.                      rec_cur_sequence.sequence_name,
  2701.                      v_sql);
  2702.           n_line_no := n_line_no + 1;
  2703.         END IF;
  2704.         v_sql := 'DROP SEQUENCE ' || rec_cur_sequence.sequence_name || ';';
  2705.         insert_rec(n_line_no,
  2706.                    v_object_type,
  2707.                    v_username,
  2708.                    rec_cur_sequence.sequence_name,
  2709.                    v_sql);
  2710.         n_line_no := n_line_no + 1;
  2711.       
  2712.         v_sql := '                  ';
  2713.         insert_rec(n_line_no,
  2714.                    v_object_type,
  2715.                    v_username,
  2716.                    rec_cur_sequence.sequence_name,
  2717.                    v_sql);
  2718.         n_line_no := n_line_no + 1;
  2719.       END IF;
  2720.     
  2721.       IF p_v_gen_create_sql = 'T' THEN
  2722.         IF p_v_display_prompt_info = 'T' THEN
  2723.           v_sql := v_prompt || ' CREATE SEQUENCE ' ||
  2724.                    rec_cur_sequence.sequence_name;
  2725.           insert_rec(n_line_no,
  2726.                      v_object_type,
  2727.                      v_username,
  2728.                      rec_cur_sequence.sequence_name,
  2729.                      v_sql);
  2730.           n_line_no := n_line_no + 1;
  2731.         END IF;
  2732.       
  2733.         v_sql := 'CREATE SEQUENCE ' || rec_cur_sequence.sequence_name;
  2734.         insert_rec(n_line_no,
  2735.                    v_object_type,
  2736.                    v_username,
  2737.                    rec_cur_sequence.sequence_name,
  2738.                    v_sql);
  2739.         n_line_no := n_line_no + 1;
  2740.       
  2741.         v_sql := 'MINVALUE ' || to_char(rec_cur_sequence.min_value);
  2742.         insert_rec(n_line_no,
  2743.                    v_object_type,
  2744.                    v_username,
  2745.                    rec_cur_sequence.sequence_name,
  2746.                    v_sql);
  2747.         n_line_no := n_line_no + 1;
  2748.       
  2749.         v_sql := 'MAXVALUE ' || to_char(rec_cur_sequence.max_value);
  2750.         insert_rec(n_line_no,
  2751.                    v_object_type,
  2752.                    v_username,
  2753.                    rec_cur_sequence.sequence_name,
  2754.                    v_sql);
  2755.         n_line_no := n_line_no + 1;
  2756.       
  2757.         v_sql := 'START WITH 1';
  2758.         insert_rec(n_line_no,
  2759.                    v_object_type,
  2760.                    v_username,
  2761.                    rec_cur_sequence.sequence_name,
  2762.                    v_sql);
  2763.         n_line_no := n_line_no + 1;
  2764.       
  2765.         v_sql := 'INCREMENT BY ' || to_char(rec_cur_sequence.increment_by);
  2766.         insert_rec(n_line_no,
  2767.                    v_object_type,
  2768.                    v_username,
  2769.                    rec_cur_sequence.sequence_name,
  2770.                    v_sql);
  2771.         n_line_no := n_line_no + 1;
  2772.       
  2773.         IF rec_cur_sequence.cycle_flag = 'N' THEN
  2774.           v_sql := 'CACHE ' || to_char(rec_cur_sequence.cache_size) ||
  2775.                    ' NOCYCLE ';
  2776.         ELSE
  2777.           v_sql := 'CACHE ' || to_char(rec_cur_sequence.cache_size) ||
  2778.                    ' CYCLE ';
  2779.         END IF;
  2780.         insert_rec(n_line_no,
  2781.                    v_object_type,
  2782.                    v_username,
  2783.                    rec_cur_sequence.sequence_name,
  2784.                    v_sql);
  2785.         n_line_no := n_line_no + 1;
  2786.       
  2787.         UPDATE temp_for_pkg_gen_sql2000_temp
  2788.            SET sql_text = sql_text || ';'
  2789.          WHERE line_no = n_line_no - 1
  2790.            AND object_type = v_object_type;
  2791.       
  2792.         v_sql := '  ';
  2793.         insert_rec(n_line_no,
  2794.                    v_object_type,
  2795.                    v_username,
  2796.                    rec_cur_sequence.sequence_name,
  2797.                    v_sql);
  2798.         n_line_no := n_line_no + 1;
  2799.       END IF;
  2800.     
  2801.     END LOOP;
  2802.     CLOSE cur_sequence;
  2803.     COMMIT;
  2804.   END;
  2805.   PROCEDURE pro_synonym_sql(p_v_gen_drop_sql        VARCHAR2 default 'T',
  2806.                             p_v_gen_create_sql      VARCHAR2 default 'T',
  2807.                             p_v_display_prompt_info VARCHAR2 default 'T') AS
  2808.     v_sql         VARCHAR2(2000);
  2809.     n_max_id      NUMBER(380);
  2810.     v_max_val     VARCHAR2(1000);
  2811.     v_object_type VARCHAR2(30);
  2812.     v_prompt      VARCHAR2(30);
  2813.     v_username    VARCHAR2(30);
  2814.     CURSOR cur_synonym IS
  2815.       SELECT synonym_name,
  2816.              'CREATE SYNONYM ' || synonym_name || '  for ' ||
  2817.              decode(db_link, null, table_owner || '.''') || table_name ||
  2818.              decode(db_link, null, '''@' || db_link) || ';' sql_text
  2819.         FROM user_synonyms;
  2820.     rec_cur_synonym cur_synonym%rowtype;
  2821.     v_synonym_name  VARCHAR2(50);
  2822.     n_line_no       NUMBER(380);
  2823.     PROCEDURE insert_rec(p_line_no     INTEGER,
  2824.                          p_object_type VARCHAR2,
  2825.                          p_user_name   VARCHAR2,
  2826.                          p_object_name VARCHAR2,
  2827.                          p_string      VARCHAR2) IS
  2828.     BEGIN
  2829.       INSERT INTO temp_for_pkg_gen_sql2000_temp
  2830.         (line_no, object_type, user_name, object_name, sql_text)
  2831.       VALUES
  2832.         (p_line_no, p_object_type, p_user_name, p_object_name, p_string);
  2833.     END;
  2834.   BEGIN
  2835.     n_line_no     := 1;
  2836.     v_object_type := upper('SYNONYM');
  2837.     v_prompt      := '-- prompt ';
  2838.   
  2839.     SELECT username INTO v_username FROM user_users;
  2840.   
  2841.     DELETE temp_for_pkg_gen_sql2000_temp WHERE OBJECT_TYPE = v_object_type;
  2842.     COMMIT;
  2843.   
  2844.     OPEN cur_synonym;
  2845.     LOOP
  2846.       FETCH cur_synonym
  2847.         INTO rec_cur_synonym;
  2848.       EXIT WHEN cur_synonym%NOTFOUND;
  2849.     
  2850.       IF p_v_gen_drop_sql = 'T' THEN
  2851.         IF p_v_display_prompt_info = 'T' THEN
  2852.           v_sql := v_prompt || ' DROP SYNONYM ' ||
  2853.                    rec_cur_synonym.synonym_name;
  2854.           insert_rec(n_line_no,
  2855.                      v_object_type,
  2856.                      v_username,
  2857.                      rec_cur_synonym.synonym_name,
  2858.                      v_sql);
  2859.           n_line_no := n_line_no + 1;
  2860.         END IF;
  2861.         v_sql := 'DROP SYNONYM ' || rec_cur_synonym.synonym_name || ';';
  2862.         insert_rec(n_line_no,
  2863.                    v_object_type,
  2864.                    v_username,
  2865.                    rec_cur_synonym.synonym_name,
  2866.                    v_sql);
  2867.         n_line_no := n_line_no + 1;
  2868.       
  2869.         v_sql := '                  ';
  2870.         insert_rec(n_line_no,
  2871.                    v_object_type,
  2872.                    v_username,
  2873.                    rec_cur_synonym.synonym_name,
  2874.                    v_sql);
  2875.         n_line_no := n_line_no + 1;
  2876.       END IF;
  2877.     
  2878.       IF p_v_gen_create_sql = 'T' THEN
  2879.         IF p_v_display_prompt_info = 'T' THEN
  2880.           v_sql := v_prompt || ' CREATE SYNONYM ' ||
  2881.                    rec_cur_synonym.synonym_name;
  2882.           insert_rec(n_line_no,
  2883.                      v_object_type,
  2884.                      v_username,
  2885.                      rec_cur_synonym.synonym_name,
  2886.                      v_sql);
  2887.           n_line_no := n_line_no + 1;
  2888.         END IF;
  2889.       
  2890.         v_sql := rec_cur_synonym.sql_text;
  2891.         insert_rec(n_line_no,
  2892.                    v_object_type,
  2893.                    v_username,
  2894.                    rec_cur_synonym.synonym_name,
  2895.                    v_sql);
  2896.         n_line_no := n_line_no + 1;
  2897.       
  2898.         v_sql := '  ';
  2899.         insert_rec(n_line_no,
  2900.                    v_object_type,
  2901.                    v_username,
  2902.                    rec_cur_synonym.synonym_name,
  2903.                    v_sql);
  2904.         n_line_no := n_line_no + 1;
  2905.       END IF;
  2906.     
  2907.     END LOOP;
  2908.     CLOSE cur_synonym;
  2909.     COMMIT;
  2910.   END;
  2911.   PROCEDURE pro_job_sql(p_v_gen_drop_sql        VARCHAR2 default 'T',
  2912.                         p_v_gen_create_sql      VARCHAR2 default 'T',
  2913.                         p_v_display_prompt_info VARCHAR2 default 'T') AS
  2914.     v_sql         VARCHAR2(4000);
  2915.     n_max_id      NUMBER(380);
  2916.     v_max_val     VARCHAR2(1000);
  2917.     v_object_type VARCHAR2(30);
  2918.     v_prompt      VARCHAR2(30);
  2919.     v_username    VARCHAR2(30);
  2920.     v_object_name VARCHAR2(200);
  2921.     CURSOR cur_job IS
  2922.       SELECT job job_no,
  2923.              decode(instr(what, chr(10)),
  2924.                     0,
  2925.                     what,
  2926.                     substr(what, 1, instr(what, chr(10)) - 1)) job_name,
  2927.              'dbms_job.submit(:jobno,''' || what || ''', sysdate, ''' ||
  2928.              interval || ''');' sql_text
  2929.         FROM user_jobs;
  2930.     rec_cur_job cur_job%rowtype;
  2931.     v_job_name  VARCHAR2(50);
  2932.     n_line_no   NUMBER(380);
  2933.     PROCEDURE insert_rec(p_line_no     INTEGER,
  2934.                          p_object_type VARCHAR2,
  2935.                          p_user_name   VARCHAR2,
  2936.                          p_object_name VARCHAR2,
  2937.                          p_string      VARCHAR2) IS
  2938.     BEGIN
  2939.       INSERT INTO temp_for_pkg_gen_sql4000_temp
  2940.         (line_no, object_type, user_name, object_name, sql_text)
  2941.       VALUES
  2942.         (p_line_no, p_object_type, p_user_name, p_object_name, p_string);
  2943.     END;
  2944.   BEGIN
  2945.     n_line_no     := 1;
  2946.     v_object_type := upper('job');
  2947.     v_prompt      := '-- prompt ';
  2948.   
  2949.     SELECT username INTO v_username FROM user_users;
  2950.   
  2951.     DELETE temp_for_pkg_gen_sql4000_temp WHERE OBJECT_TYPE = v_object_type;
  2952.     COMMIT;
  2953.   
  2954.     OPEN cur_job;
  2955.     LOOP
  2956.       FETCH cur_job
  2957.         INTO rec_cur_job;
  2958.       EXIT WHEN cur_job%NOTFOUND;
  2959.     
  2960.       IF p_v_gen_drop_sql = 'T' THEN
  2961.         IF p_v_display_prompt_info = 'T' THEN
  2962.           v_sql := v_prompt || ' DROP job ' || rec_cur_job.job_name;
  2963.           insert_rec(n_line_no,
  2964.                      v_object_type,
  2965.                      v_username,
  2966.                      rec_cur_job.job_name,
  2967.                      v_sql);
  2968.           n_line_no := n_line_no + 1;
  2969.         END IF;
  2970.         v_sql := 'exec dbms_job.remove(' || to_char(rec_cur_job.job_no) || ');';
  2971.         insert_rec(n_line_no,
  2972.                    v_object_type,
  2973.                    v_username,
  2974.                    rec_cur_job.job_name,
  2975.                    v_sql);
  2976.         n_line_no := n_line_no + 1;
  2977.       
  2978.         v_sql := '                  ';
  2979.         insert_rec(n_line_no,
  2980.                    v_object_type,
  2981.                    v_username,
  2982.                    rec_cur_job.job_name,
  2983.                    v_sql);
  2984.         n_line_no := n_line_no + 1;
  2985.       END IF;
  2986.     
  2987.       IF p_v_gen_create_sql = 'T' THEN
  2988.         IF p_v_display_prompt_info = 'T' THEN
  2989.           v_sql := v_prompt || ' CREATE job ' || rec_cur_job.job_name;
  2990.           insert_rec(n_line_no,
  2991.                      v_object_type,
  2992.                      v_username,
  2993.                      rec_cur_job.job_name,
  2994.                      v_sql);
  2995.           n_line_no := n_line_no + 1;
  2996.         END IF;
  2997.       
  2998.         v_sql := 'variable jobno number;';
  2999.         insert_rec(n_line_no,
  3000.                    v_object_type,
  3001.                    v_username,
  3002.                    rec_cur_job.job_name,
  3003.                    v_sql);
  3004.         n_line_no := n_line_no + 1;
  3005.       
  3006.         v_sql := 'begin';
  3007.         insert_rec(n_line_no,
  3008.                    v_object_type,
  3009.                    v_username,
  3010.                    rec_cur_job.job_name,
  3011.                    v_sql);
  3012.         n_line_no := n_line_no + 1;
  3013.       
  3014.         v_sql := rec_cur_job.sql_text;
  3015.         insert_rec(n_line_no,
  3016.                    v_object_type,
  3017.                    v_username,
  3018.                    rec_cur_job.job_name,
  3019.                    v_sql);
  3020.         n_line_no := n_line_no + 1;
  3021.       
  3022.         v_sql := 'end;';
  3023.         insert_rec(n_line_no,
  3024.                    v_object_type,
  3025.                    v_username,
  3026.                    rec_cur_job.job_name,
  3027.                    v_sql);
  3028.         n_line_no := n_line_no + 1;
  3029.       
  3030.         v_sql := '/';
  3031.         insert_rec(n_line_no,
  3032.                    v_object_type,
  3033.                    v_username,
  3034.                    rec_cur_job.job_name,
  3035.                    v_sql);
  3036.         n_line_no := n_line_no + 1;
  3037.       
  3038.         v_sql := '  ';
  3039.         insert_rec(n_line_no,
  3040.                    v_object_type,
  3041.                    v_username,
  3042.                    rec_cur_job.job_name,
  3043.                    v_sql);
  3044.         n_line_no := n_line_no + 1;
  3045.       END IF;
  3046.     
  3047.     END LOOP;
  3048.     CLOSE cur_job;
  3049.     COMMIT;
  3050.   END;
  3051.   PROCEDURE pro_dl_sql(p_v_gen_drop_sql        VARCHAR2 default 'T',
  3052.                        p_v_gen_create_sql      VARCHAR2 default 'T',
  3053.                        p_v_display_prompt_info VARCHAR2 default 'T') AS
  3054.     v_sql         VARCHAR2(2000);
  3055.     n_max_id      NUMBER(380);
  3056.     v_max_val     VARCHAR2(1000);
  3057.     v_object_type VARCHAR2(30);
  3058.     v_prompt      VARCHAR2(30);
  3059.     v_username    VARCHAR2(30);
  3060.     CURSOR cur_dl IS
  3061.       SELECT db_link,
  3062.              'CREATE DATABASE LINK ' || db_link || ' CONNECT TO ' ||
  3063.              username || ' IDENTIFIED BY ' || password || ' USING ''' || HOST ||
  3064.              ''';' sql_text
  3065.         FROM user_db_links;
  3066.     rec_cur_dl cur_dl%rowtype;
  3067.     v_db_link  VARCHAR2(50);
  3068.     n_line_no  NUMBER(380);
  3069.     PROCEDURE insert_rec(p_line_no     INTEGER,
  3070.                          p_object_type VARCHAR2,
  3071.                          p_user_name   VARCHAR2,
  3072.                          p_object_name VARCHAR2,
  3073.                          p_string      VARCHAR2) IS
  3074.     BEGIN
  3075.       INSERT INTO temp_for_pkg_gen_sql2000_temp
  3076.         (line_no, object_type, user_name, object_name, sql_text)
  3077.       VALUES
  3078.         (p_line_no, p_object_type, p_user_name, p_object_name, p_string);
  3079.     END;
  3080.   BEGIN
  3081.     n_line_no     := 1;
  3082.     v_object_type := upper('DL');
  3083.     v_prompt      := '-- prompt ';
  3084.   
  3085.     SELECT username INTO v_username FROM user_users;
  3086.   
  3087.     DELETE temp_for_pkg_gen_sql2000_temp WHERE OBJECT_TYPE = v_object_type;
  3088.     COMMIT;
  3089.   
  3090.     OPEN cur_dl;
  3091.     LOOP
  3092.       FETCH cur_dl
  3093.         INTO rec_cur_dl;
  3094.       EXIT WHEN cur_dl%NOTFOUND;
  3095.     
  3096.       IF p_v_gen_drop_sql = 'T' THEN
  3097.         IF p_v_display_prompt_info = 'T' THEN
  3098.           v_sql := v_prompt || ' DROP DATABASE LIKE ' || rec_cur_dl.db_link;
  3099.           insert_rec(n_line_no,
  3100.                      v_object_type,
  3101.                      v_username,
  3102.                      rec_cur_dl.db_link,
  3103.                      v_sql);
  3104.           n_line_no := n_line_no + 1;
  3105.         END IF;
  3106.         v_sql := 'DROP DATABASE LIKE ' || rec_cur_dl.db_link || ';';
  3107.         insert_rec(n_line_no,
  3108.                    v_object_type,
  3109.                    v_username,
  3110.                    rec_cur_dl.db_link,
  3111.                    v_sql);
  3112.         n_line_no := n_line_no + 1;
  3113.       
  3114.         v_sql := '                  ';
  3115.         insert_rec(n_line_no,
  3116.                    v_object_type,
  3117.                    v_username,
  3118.                    rec_cur_dl.db_link,
  3119.                    v_sql);
  3120.         n_line_no := n_line_no + 1;
  3121.       END IF;
  3122.     
  3123.       IF p_v_gen_create_sql = 'T' THEN
  3124.         IF p_v_display_prompt_info = 'T' THEN
  3125.           v_sql := v_prompt || ' CREATE DATABASE LINK ' ||
  3126.                    rec_cur_dl.db_link;
  3127.           insert_rec(n_line_no,
  3128.                      v_object_type,
  3129.                      v_username,
  3130.                      rec_cur_dl.db_link,
  3131.                      v_sql);
  3132.           n_line_no := n_line_no + 1;
  3133.         END IF;
  3134.       
  3135.         v_sql := rec_cur_dl.sql_text;
  3136.         insert_rec(n_line_no,
  3137.                    v_object_type,
  3138.                    v_username,
  3139.                    rec_cur_dl.db_link,
  3140.                    v_sql);
  3141.         n_line_no := n_line_no + 1;
  3142.       
  3143.         v_sql := '  ';
  3144.         insert_rec(n_line_no,
  3145.                    v_object_type,
  3146.                    v_username,
  3147.                    rec_cur_dl.db_link,
  3148.                    v_sql);
  3149.         n_line_no := n_line_no + 1;
  3150.       END IF;
  3151.     
  3152.     END LOOP;
  3153.     CLOSE cur_dl;
  3154.     COMMIT;
  3155.   END;
  3156.   PROCEDURE pro_role_sql(p_v_gen_drop_sql        VARCHAR2 default 'T',
  3157.                          p_v_gen_create_sql      VARCHAR2 default 'T',
  3158.                          p_v_display_prompt_info VARCHAR2 default 'T') AS
  3159.     v_sql         VARCHAR2(2000);
  3160.     v_option      VARCHAR2(200);
  3161.     n_max_id      NUMBER(380);
  3162.     v_max_val     VARCHAR2(1000);
  3163.     v_object_type VARCHAR2(30);
  3164.     v_prompt      VARCHAR2(30);
  3165.     v_username    VARCHAR2(30);
  3166.     CURSOR cur_role IS
  3167.       select granted_role role from user_role_privs;
  3168.     rec_cur_role cur_role%rowtype;
  3169.   
  3170.     CURSOR cur_role_pris(c_role_name VARCHAR2) IS
  3171.       SELECT type,
  3172.              role,
  3173.              owner,
  3174.              table_name,
  3175.              column_name,
  3176.              privilege,
  3177.              grantable
  3178.         FROM (SELECT 'TAB' type,
  3179.                      role,
  3180.                      owner,
  3181.                      table_name,
  3182.                      column_name,
  3183.                      privilege,
  3184.                      grantable
  3185.                 FROM role_tab_privs
  3186.                WHERE role NOT IN ('CONNECT''RESOURCE''DBA')
  3187.               UNION
  3188.               SELECT 'SYS' type,
  3189.                      role,
  3190.                      '' owner,
  3191.                      '' table_name,
  3192.                      '' column_name,
  3193.                      privilege,
  3194.                      admin_option grantable
  3195.                 FROM role_sys_privs
  3196.                WHERE role NOT IN ('CONNECT''RESOURCE''DBA'))
  3197.        where role = upper(c_role_name);
  3198.     rec_cur_role_pris cur_role_pris%rowtype;
  3199.   
  3200.     v_role    VARCHAR2(50);
  3201.     n_line_no NUMBER(380);
  3202.     PROCEDURE insert_rec(p_line_no     INTEGER,
  3203.                          p_object_type VARCHAR2,
  3204.                          p_user_name   VARCHAR2,
  3205.                          p_object_name VARCHAR2,
  3206.                          p_string      VARCHAR2) IS
  3207.     BEGIN
  3208.       INSERT INTO temp_for_pkg_gen_sql2000_temp
  3209.         (line_no, object_type, user_name, object_name, sql_text)
  3210.       VALUES
  3211.         (p_line_no, p_object_type, p_user_name, p_object_name, p_string);
  3212.     END;
  3213.   BEGIN
  3214.     n_line_no     := 1;
  3215.     v_object_type := UPPER('ROLE');
  3216.     v_prompt      := '-- prompt ';
  3217.   
  3218.     SELECT username INTO v_username FROM user_users;
  3219.   
  3220.     DELETE temp_for_pkg_gen_sql2000_temp WHERE OBJECT_TYPE = v_object_type;
  3221.     COMMIT;
  3222.   
  3223.     OPEN cur_role;
  3224.     LOOP
  3225.       FETCH cur_role
  3226.         INTO rec_cur_role;
  3227.       EXIT WHEN cur_role%NOTFOUND;
  3228.     
  3229.       IF p_v_gen_drop_sql = 'T' THEN
  3230.         IF p_v_display_prompt_info = 'T' THEN
  3231.           v_sql := v_prompt || ' DROP ROLE ' || rec_cur_role.role;
  3232.           insert_rec(n_line_no,
  3233.                      v_object_type,
  3234.                      v_username,
  3235.                      rec_cur_role.role,
  3236.                      v_sql);
  3237.           n_line_no := n_line_no + 1;
  3238.         END IF;
  3239.         v_sql := 'DROP ROLE ' || rec_cur_role.role || ';';
  3240.         insert_rec(n_line_no,
  3241.                    v_object_type,
  3242.                    v_username,
  3243.                    rec_cur_role.role,
  3244.                    v_sql);
  3245.         n_line_no := n_line_no + 1;
  3246.       
  3247.         v_sql := '                  ';
  3248.         insert_rec(n_line_no,
  3249.                    v_object_type,
  3250.                    v_username,
  3251.                    rec_cur_role.role,
  3252.                    v_sql);
  3253.         n_line_no := n_line_no + 1;
  3254.       END IF;
  3255.     
  3256.       IF p_v_gen_create_sql = 'T' THEN
  3257.         IF p_v_display_prompt_info = 'T' THEN
  3258.           v_sql := v_prompt || ' CREATE ROLE ' || rec_cur_role.role;
  3259.           insert_rec(n_line_no,
  3260.                      v_object_type,
  3261.                      v_username,
  3262.                      rec_cur_role.role,
  3263.                      v_sql);
  3264.           n_line_no := n_line_no + 1;
  3265.         END IF;
  3266.       
  3267.         v_sql := 'CREATE ROLE ' || rec_cur_role.role || ';';
  3268.         insert_rec(n_line_no,
  3269.                    v_object_type,
  3270.                    v_username,
  3271.                    rec_cur_role.role,
  3272.                    v_sql);
  3273.         n_line_no := n_line_no + 1;
  3274.       
  3275.         v_sql := v_prompt || ' GRANT PRIS TO  ROLE : ' || rec_cur_role.role;
  3276.         insert_rec(n_line_no,
  3277.                    v_object_type,
  3278.                    v_username,
  3279.                    rec_cur_role.role,
  3280.                    v_sql);
  3281.         n_line_no := n_line_no + 1;
  3282.       
  3283.         OPEN cur_role_pris(rec_cur_role.role);
  3284.         LOOP
  3285.           FETCH cur_role_pris
  3286.             INTO rec_cur_role_pris;
  3287.           EXIT WHEN cur_role_pris%NOTFOUND;
  3288.         
  3289.           IF rec_cur_role_pris.type = 'SYS' THEN
  3290.             IF rec_cur_role_pris.grantable = 'NO' THEN
  3291.               v_option := '';
  3292.             ELSE
  3293.               v_option := ' WITH ADMIN OPTION';
  3294.             END IF;
  3295.             v_sql := 'GRANT ' || rec_cur_role_pris.privilege || ' TO  ' ||
  3296.                      rec_cur_role_pris.role || v_option || ';';
  3297.             insert_rec(n_line_no,
  3298.                        v_object_type,
  3299.                        v_username,
  3300.                        rec_cur_role.role,
  3301.                        v_sql);
  3302.             n_line_no := n_line_no + 1;
  3303.           ELSE
  3304.             IF rec_cur_role_pris.grantable = 'NO' THEN
  3305.               v_option := '';
  3306.             ELSE
  3307.               v_option := ' WITH GRANT OPTION';
  3308.             END IF;
  3309.           
  3310.             IF rec_cur_role_pris.column_name IS NOT NULL THEN
  3311.               v_sql := 'GRANT ' || rec_cur_role_pris.privilege || '(' ||
  3312.                        rec_cur_role_pris.column_name || ') ON ' ||
  3313.                        rec_cur_role_pris.owner || '.' ||
  3314.                        rec_cur_role_pris.table_name || ' TO ' ||
  3315.                        rec_cur_role_pris.role || v_option || ';';
  3316.             ELSE
  3317.               v_sql := 'GRANT ' || rec_cur_role_pris.privilege || ' ON ' ||
  3318.                        rec_cur_role_pris.owner || '.' ||
  3319.                        rec_cur_role_pris.table_name || ' TO  ' ||
  3320.                        rec_cur_role_pris.role || v_option || ';';
  3321.             END IF;
  3322.           
  3323.             insert_rec(n_line_no,
  3324.                        v_object_type,
  3325.                        v_username,
  3326.                        rec_cur_role.role,
  3327.                        v_sql);
  3328.             n_line_no := n_line_no + 1;
  3329.           END IF;
  3330.         END LOOP;
  3331.         CLOSE cur_role_pris;
  3332.       
  3333.         v_sql := '  ';
  3334.         insert_rec(n_line_no,
  3335.                    v_object_type,
  3336.                    v_username,
  3337.                    rec_cur_role.role,
  3338.                    v_sql);
  3339.         n_line_no := n_line_no + 1;
  3340.       END IF;
  3341.     
  3342.     END LOOP;
  3343.     CLOSE cur_role;
  3344.     COMMIT;
  3345.   END;
  3346.   PROCEDURE pro_priv_sql(p_v_gen_drop_sql        VARCHAR2 default 'T',
  3347.                          p_v_gen_create_sql      VARCHAR2 default 'T',
  3348.                          p_v_display_prompt_info VARCHAR2 default 'T') AS
  3349.     v_sql         VARCHAR2(2000);
  3350.     v_option      VARCHAR2(200);
  3351.     n_max_id      NUMBER(380);
  3352.     v_max_val     VARCHAR2(1000);
  3353.     v_object_type VARCHAR2(30);
  3354.     v_prompt      VARCHAR2(30);
  3355.     v_username    VARCHAR2(30);
  3356.     n_count       number(100);
  3357.     CURSOR cur_priv IS
  3358.       SELECT privilege,
  3359.              owner,
  3360.              table_name,
  3361.              grantee,
  3362.              'GRANT ' || privilege || ' ON ' || owner || '.' || table_name ||
  3363.              ' TO ' || grantee ||
  3364.              decode(grantable, 'NO'''' WITH GRANT OPTION') || ';' SQL_TEXT
  3365.         FROM user_tab_privs
  3366.        WHERE GRANTOR = (SELECT username FROM user_users)
  3367.        ORDER BY owner, table_name;
  3368.     rec_cur_priv cur_priv%rowtype;
  3369.   
  3370.     CURSOR cur_col_priv IS
  3371.       SELECT privilege,
  3372.              owner,
  3373.              column_name,
  3374.              table_name,
  3375.              grantee,
  3376.              'GRANT ' || privilege || ' ' || column_name || ' ON ' || owner || '.' ||
  3377.              table_name || ' TO ' || grantee ||
  3378.              decode(grantable, 'NO'''' WITH GRANT OPTION') || ';' SQL_TEXT
  3379.         FROM user_col_privs
  3380.        WHERE GRANTOR = (SELECT username FROM user_users)
  3381.        ORDER BY owner, table_name;
  3382.     rec_cur_col_priv cur_col_priv%rowtype;
  3383.   
  3384.     CURSOR cur_sys_priv IS
  3385.       SELECT username,
  3386.              privilege,
  3387.              'GRANT ' || privilege || ' TO ' || username ||
  3388.              decode(admin_option, 'NO'''' WITH ADMIN OPTION') || ';' SQL_TEXT
  3389.         FROM user_sys_privs
  3390.        ORDER BY username;
  3391.     rec_cur_sys_priv cur_sys_priv%rowtype;
  3392.   
  3393.     v_priv    VARCHAR2(50);
  3394.     n_line_no NUMBER(380);
  3395.     PROCEDURE insert_rec(p_line_no     INTEGER,
  3396.                          p_object_type VARCHAR2,
  3397.                          p_user_name   VARCHAR2,
  3398.                          p_object_name VARCHAR2,
  3399.                          p_string      VARCHAR2) IS
  3400.     BEGIN
  3401.       INSERT INTO temp_for_pkg_gen_sql2000_temp
  3402.         (line_no, object_type, user_name, object_name, sql_text)
  3403.       VALUES
  3404.         (p_line_no, p_object_type, p_user_name, p_object_name, p_string);
  3405.     END;
  3406.   BEGIN
  3407.     n_line_no     := 1;
  3408.     v_object_type := UPPER('PRIV');
  3409.     v_prompt      := '-- prompt ';
  3410.     n_count       := 1;
  3411.   
  3412.     SELECT USERNAME INTO v_username FROM USER_USERS;
  3413.   
  3414.     DELETE temp_for_pkg_gen_sql2000_temp WHERE OBJECT_TYPE = v_object_type;
  3415.     COMMIT;
  3416.   
  3417.     OPEN cur_priv;
  3418.     LOOP
  3419.       FETCH cur_priv
  3420.         INTO rec_cur_priv;
  3421.       EXIT WHEN cur_priv%NOTFOUND;
  3422.     
  3423.       IF p_v_gen_create_sql = 'T' THEN
  3424.         IF p_v_display_prompt_info = 'T' THEN
  3425.           v_sql := v_prompt || ' GRANT PRIVILEGE : ' ||
  3426.                    rec_cur_priv.privilege || ' ON ' || rec_cur_priv.owner || '.' ||
  3427.                    rec_cur_priv.table_name || ' TO ' ||
  3428.                    rec_cur_priv.grantee;
  3429.           insert_rec(n_line_no,
  3430.                      v_object_type,
  3431.                      v_username,
  3432.                      'tab priv',
  3433.                      v_sql);
  3434.           n_line_no := n_line_no + 1;
  3435.         END IF;
  3436.       
  3437.         v_sql := rec_cur_priv.sql_text;
  3438.         insert_rec(n_line_no, v_object_type, v_username, 'tab priv', v_sql);
  3439.         n_line_no := n_line_no + 1;
  3440.       
  3441.         v_sql := '  ';
  3442.         insert_rec(n_line_no, v_object_type, v_username, 'tab priv', v_sql);
  3443.         n_line_no := n_line_no + 1;
  3444.       
  3445.       END IF;
  3446.     
  3447.     END LOOP;
  3448.     CLOSE cur_priv;
  3449.   
  3450.     OPEN cur_col_priv;
  3451.     LOOP
  3452.       FETCH cur_col_priv
  3453.         INTO rec_cur_col_priv;
  3454.       EXIT WHEN cur_col_priv%NOTFOUND;
  3455.       IF n_count = 1 THEN
  3456.         v_sql := '-- *********************** ';
  3457.         insert_rec(n_line_no, v_object_type, v_username, 'tab priv', v_sql);
  3458.         n_line_no := n_line_no + 1;
  3459.       
  3460.         n_count := n_count + 1;
  3461.       END IF;
  3462.     
  3463.       v_sql := '  ';
  3464.       insert_rec(n_line_no, v_object_type, v_username, 'tab priv', v_sql);
  3465.       n_line_no := n_line_no + 1;
  3466.     
  3467.       IF p_v_display_prompt_info = 'T' THEN
  3468.         v_sql := v_prompt || ' GRANT COL PRIVILEGE : ' ||
  3469.                  rec_cur_col_priv.privilege || ' ON ' ||
  3470.                  rec_cur_col_priv.owner || '.' ||
  3471.                  rec_cur_col_priv.table_name || ' TO ' ||
  3472.                  rec_cur_col_priv.grantee;
  3473.         insert_rec(n_line_no, v_object_type, v_username, 'col priv', v_sql);
  3474.         n_line_no := n_line_no + 1;
  3475.       END IF;
  3476.     
  3477.       v_sql := rec_cur_col_priv.sql_text;
  3478.       insert_rec(n_line_no, v_object_type, v_username, 'col priv', v_sql);
  3479.       n_line_no := n_line_no + 1;
  3480.     
  3481.       v_sql := '  ';
  3482.       insert_rec(n_line_no, v_object_type, v_username, 'col priv', v_sql);
  3483.       n_line_no := n_line_no + 1;
  3484.     END LOOP;
  3485.     CLOSE cur_col_priv;
  3486.   
  3487.     n_count := 1;
  3488.     OPEN cur_sys_priv;
  3489.     LOOP
  3490.       FETCH cur_sys_priv
  3491.         INTO rec_cur_sys_priv;
  3492.       EXIT WHEN cur_sys_priv%NOTFOUND;
  3493.       IF n_count = 1 THEN
  3494.         v_sql := '  ';
  3495.         insert_rec(n_line_no, v_object_type, v_username, 'sys priv', v_sql);
  3496.         n_line_no := n_line_no + 1;
  3497.       
  3498.         v_sql := 'PROMPT *********** You must the following sql as a user with DBA priv, others you will get errors! 
  3499. ************ ';
  3500.         insert_rec(n_line_no, v_object_type, v_username, 'sys priv', v_sql);
  3501.         n_line_no := n_line_no + 1;
  3502.       
  3503.         v_sql := 'PROMPT *********** We comment the follow sql! ************ ';
  3504.         insert_rec(n_line_no, v_object_type, v_username, 'sys priv', v_sql);
  3505.         n_line_no := n_line_no + 1;
  3506.       
  3507.         v_sql := '  ';
  3508.         insert_rec(n_line_no, v_object_type, v_username, 'sys priv', v_sql);
  3509.         n_line_no := n_line_no + 1;
  3510.       
  3511.         n_count := n_count + 1;
  3512.       
  3513.       END IF;
  3514.     
  3515.       IF p_v_display_prompt_info = 'T' THEN
  3516.         v_sql := v_prompt || ' GRANT SYSTEM PRIVILEGE : ' ||
  3517.                  rec_cur_sys_priv.privilege || ' TO ' ||
  3518.                  rec_cur_sys_priv.username;
  3519.         insert_rec(n_line_no, v_object_type, v_username, 'sys priv', v_sql);
  3520.         n_line_no := n_line_no + 1;
  3521.       END IF;
  3522.     
  3523.       v_sql := '-- ' || rec_cur_sys_priv.sql_text;
  3524.       insert_rec(n_line_no, v_object_type, v_username, 'sys priv', v_sql);
  3525.       n_line_no := n_line_no + 1;
  3526.     
  3527.       v_sql := '  ';
  3528.       insert_rec(n_line_no, v_object_type, v_username, 'sys priv', v_sql);
  3529.       n_line_no := n_line_no + 1;
  3530.     END LOOP;
  3531.     CLOSE cur_sys_priv;
  3532.   
  3533.     COMMIT;
  3534.   END;
  3535.   PROCEDURE pro_pkgprofuntri_sql(p_v_gen_drop_sql        VARCHAR2 default 'T',
  3536.                                  p_v_gen_create_sql      VARCHAR2 default 'T',
  3537.                                  p_v_display_prompt_info VARCHAR2 default 'T',
  3538.                                  p_v_separ_file          VARCHAR2 default 'T',
  3539.                                  p_v_file_path           VARCHAR2 default 'C:/') AS
  3540.     v_sql         VARCHAR2(2000);
  3541.     v_object_type VARCHAR2(30);
  3542.     v_prompt      VARCHAR2(30);
  3543.     v_file_path   VARCHAR2(600);
  3544.     v_notion      char(1);
  3545.     v_username    VARCHAR2(30);
  3546.     CURSOR cur_ProFunPkg_name IS
  3547.       SELECT distinct type, us.name
  3548.         FROM user_source us
  3549.        WHERE type <> 'PACKAGE BODY'
  3550.          AND us.name <> upper('pkg_gen_user_sql')
  3551.        ORDER BY us.type, us.name;
  3552.   
  3553.     CURSOR cur_ProFunPkg_code(c_obj_name VARCHAR2, c_obj_type VARCHAR2) IS
  3554.       SELECT line, type, text
  3555.         FROM user_source us
  3556.        WHERE NAME = c_obj_name
  3557.          AND type = c_obj_type
  3558.        ORDER BY type, line;
  3559.   
  3560.     v_object_name VARCHAR2(50);
  3561.     n_line_no     NUMBER(380);
  3562.     PROCEDURE insert_rec(p_line_no     INTEGER,
  3563.                          p_object_type VARCHAR2,
  3564.                          p_user_name   VARCHAR2,
  3565.                          p_object_name VARCHAR2,
  3566.                          p_string      VARCHAR2) IS
  3567.     BEGIN
  3568.       INSERT INTO temp_for_pkg_gen_sql4000_temp
  3569.         (line_no, object_type, user_name, object_name, sql_text)
  3570.       VALUES
  3571.         (p_line_no, p_object_type, p_user_name, p_object_name, p_string);
  3572.     END;
  3573.   BEGIN
  3574.     n_line_no   := 1;
  3575.     v_file_path := p_v_file_path;
  3576.     v_prompt    := '-- prompt ';
  3577.   
  3578.     SELECT username INTO v_username FROM user_users;
  3579.   
  3580.     -- find the notion between the dictionary
  3581.     IF instr(p_v_file_path, '/') > 0 THEN
  3582.       v_notion := '/';
  3583.     ELSE
  3584.       v_notion := '/';
  3585.     END IF;
  3586.   
  3587.     IF substr(v_file_path, length(v_file_path)) <> v_notion THEN
  3588.       v_file_path := v_file_path || v_notion;
  3589.     END IF;
  3590.   
  3591.     DELETE temp_for_pkg_gen_sql4000_temp
  3592.      WHERE OBJECT_TYPE IN
  3593.            ('PACKAGE BODY''PACKAGE''PROCEDURE''FUNCTION',
  3594.             'SEPAR_PROCS''SEPAR_FUNCS''SEPAR_PKG_HEADS',
  3595.             'SEPAR_PKG_BODYS''SEPAR_PKGS''TRIGGER''SEPAR_TRIS');
  3596.     COMMIT;
  3597.   
  3598.     FOR rec_ProFunPkg_name IN cur_ProFunPkg_name LOOP
  3599.       v_object_type := rec_ProFunPkg_name.type;
  3600.     
  3601.       v_sql := '--  ~~~~~~~~~~~~~~~~~~~~  ' || rec_ProFunPkg_name.type ||
  3602.                ' : ' || rec_ProFunPkg_name.name ||
  3603.                ' START;  ~~~~~~~~~~~~~~~~~~~~';
  3604.       insert_rec(n_line_no,
  3605.                  v_object_type,
  3606.                  v_username,
  3607.                  rec_ProFunPkg_name.name,
  3608.                  v_sql);
  3609.       n_line_no := n_line_no + 1;
  3610.     
  3611.       v_sql := '                  ';
  3612.       insert_rec(n_line_no,
  3613.                  v_object_type,
  3614.                  v_username,
  3615.                  rec_ProFunPkg_name.name,
  3616.                  v_sql);
  3617.       n_line_no := n_line_no + 1;
  3618.     
  3619.       IF p_v_gen_drop_sql = 'T' AND v_object_type <> 'PACKAGE BODY' THEN
  3620.         IF p_v_display_prompt_info = 'T' THEN
  3621.           v_sql := v_prompt || ' DROP ' || rec_ProFunPkg_name.type || ' ' ||
  3622.                    rec_ProFunPkg_name.name;
  3623.           insert_rec(n_line_no,
  3624.                      v_object_type,
  3625.                      v_username,
  3626.                      rec_ProFunPkg_name.name,
  3627.                      v_sql);
  3628.           n_line_no := n_line_no + 1;
  3629.         END IF;
  3630.         v_sql := 'DROP ' || rec_ProFunPkg_name.type || ' ' ||
  3631.                  rec_ProFunPkg_name.type || ' ' || rec_ProFunPkg_name.name || ';';
  3632.         insert_rec(n_line_no,
  3633.                    v_object_type,
  3634.                    v_username,
  3635.                    rec_ProFunPkg_name.name,
  3636.                    v_sql);
  3637.         n_line_no := n_line_no + 1;
  3638.       
  3639.         v_sql := '                  ';
  3640.         insert_rec(n_line_no,
  3641.                    v_object_type,
  3642.                    v_username,
  3643.                    rec_ProFunPkg_name.name,
  3644.                    v_sql);
  3645.         n_line_no := n_line_no + 1;
  3646.       END IF;
  3647.     
  3648.       IF p_v_gen_create_sql = 'T' THEN
  3649.         IF p_v_display_prompt_info = 'T' THEN
  3650.           v_sql := v_prompt || ' CREATE ' || rec_ProFunPkg_name.type || ' ' ||
  3651.                    rec_ProFunPkg_name.name;
  3652.           insert_rec(n_line_no,
  3653.                      v_object_type,
  3654.                      v_username,
  3655.                      rec_ProFunPkg_name.name,
  3656.                      v_sql);
  3657.           n_line_no := n_line_no + 1;
  3658.         END IF;
  3659.       
  3660.         FOR rec_ProFunPkg_code IN cur_ProFunPkg_code(rec_ProFunPkg_name.name,
  3661.                                                      rec_ProFunPkg_name.type) LOOP
  3662.           IF rec_ProFunPkg_code.line = 1 THEN
  3663.             v_sql := 'CREATE OR REPLACE ' || rec_ProFunPkg_code.text;
  3664.           ELSE
  3665.             v_sql := rec_ProFunPkg_code.text;
  3666.           END IF;
  3667.           insert_rec(n_line_no,
  3668.                      v_object_type,
  3669.                      v_username,
  3670.                      rec_ProFunPkg_name.name,
  3671.                      v_sql);
  3672.           n_line_no := n_line_no + 1;
  3673.         END LOOP;
  3674.       
  3675.         v_sql := '/';
  3676.         insert_rec(n_line_no,
  3677.                    v_object_type,
  3678.                    v_username,
  3679.                    rec_ProFunPkg_name.name,
  3680.                    v_sql);
  3681.         n_line_no := n_line_no + 1;
  3682.       
  3683.         v_sql := '@' || lower(rec_ProFunPkg_name.name) || '.sql';
  3684.         IF v_object_type = 'PROCEDURE' THEN
  3685.           insert_rec(n_line_no,
  3686.                      v_object_type,
  3687.                      v_username,
  3688.                      'START_PROCS',
  3689.                      v_sql);
  3690.         ELSIF v_object_type = 'FUNCTION' THEN
  3691.           insert_rec(n_line_no,
  3692.                      v_object_type,
  3693.                      v_username,
  3694.                      'START_FUNCS',
  3695.                      v_sql);
  3696.         ELSIF v_object_type = 'PACKAGE' or v_object_type = 'PACKAGE BODY' THEN
  3697.           insert_rec(n_line_no,
  3698.                      v_object_type,
  3699.                      v_username,
  3700.                      'START_PKGS',
  3701.                      v_sql);
  3702.           n_line_no := n_line_no + 1;
  3703.         
  3704.           v_sql := '@' || lower(rec_ProFunPkg_name.name) || '.haad.sql';
  3705.           insert_rec(n_line_no,
  3706.                      v_object_type,
  3707.                      v_username,
  3708.                      'START_PKG_HS',
  3709.                      v_sql);
  3710.           n_line_no := n_line_no + 1;
  3711.         
  3712.           v_sql := '@' || lower(rec_ProFunPkg_name.name) || '.body.sql';
  3713.           insert_rec(n_line_no,
  3714.                      v_object_type,
  3715.                      v_username,
  3716.                      'START_PKG_BS',
  3717.                      v_sql);
  3718.         ELSIF v_object_type = 'TRIGGER' THEN
  3719.           insert_rec(n_line_no,
  3720.                      v_object_type,
  3721.                      v_username,
  3722.                      'START_TRIS',
  3723.                      v_sql);
  3724.         ELSIF v_object_type = 'TYPE' or v_object_type = 'TYPE BODY' THEN
  3725.           insert_rec(n_line_no,
  3726.                      v_object_type,
  3727.                      v_username,
  3728.                      'START_TYPES',
  3729.                      v_sql);
  3730.           n_line_no := n_line_no + 1;
  3731.         
  3732.           v_sql := '@' || lower(rec_ProFunPkg_name.name) || '.haad.sql';
  3733.           insert_rec(n_line_no,
  3734.                      v_object_type,
  3735.                      v_username,
  3736.                      'START_TYPE_HS',
  3737.                      v_sql);
  3738.           n_line_no := n_line_no + 1;
  3739.         
  3740.           v_sql := '@' || lower(rec_ProFunPkg_name.name) || '.body.sql';
  3741.           insert_rec(n_line_no,
  3742.                      v_object_type,
  3743.                      v_username,
  3744.                      'START_TYPE_BS',
  3745.                      v_sql);
  3746.         END IF;
  3747.         n_line_no := n_line_no + 1;
  3748.       
  3749.         v_sql := '  ';
  3750.         insert_rec(n_line_no,
  3751.                    'START_PROCS',
  3752.                    v_username,
  3753.                    rec_ProFunPkg_name.name,
  3754.                    v_sql);
  3755.         n_line_no := n_line_no + 1;
  3756.       
  3757.         v_sql := '  ';
  3758.         insert_rec(n_line_no,
  3759.                    v_object_type,
  3760.                    v_username,
  3761.                    rec_ProFunPkg_name.name,
  3762.                    v_sql);
  3763.         n_line_no := n_line_no + 1;
  3764.       
  3765.         IF rec_ProFunPkg_name.type = 'PACKAGE' THEN
  3766.           FOR rec_ProFunPkg_code IN cur_ProFunPkg_code(rec_ProFunPkg_name.name,
  3767.                                                        rec_ProFunPkg_name.type ||
  3768.                                                        ' BODY') LOOP
  3769.             IF rec_ProFunPkg_code.line = 1 THEN
  3770.               v_sql := 'CREATE OR REPLACE ' || rec_ProFunPkg_code.text;
  3771.             ELSE
  3772.               v_sql := rec_ProFunPkg_code.text;
  3773.             END IF;
  3774.             insert_rec(n_line_no,
  3775.                        rec_ProFunPkg_name.type || ' BODY',
  3776.                        v_username,
  3777.                        rec_ProFunPkg_name.name,
  3778.                        v_sql);
  3779.             n_line_no := n_line_no + 1;
  3780.           END LOOP;
  3781.         
  3782.           v_sql := '/';
  3783.           insert_rec(n_line_no,
  3784.                      rec_ProFunPkg_name.type || ' BODY',
  3785.                      v_username,
  3786.                      rec_ProFunPkg_name.name,
  3787.                      v_sql);
  3788.           n_line_no := n_line_no + 1;
  3789.         
  3790.           v_sql := '  ';
  3791.           insert_rec(n_line_no,
  3792.                      rec_ProFunPkg_name.type || ' BODY',
  3793.                      v_username,
  3794.                      rec_ProFunPkg_name.name,
  3795.                      v_sql);
  3796.           n_line_no := n_line_no + 1;
  3797.         END IF;
  3798.       
  3799.         v_sql := '--  ~~~~~~~~~~~~~~~~~~~~  ' || rec_ProFunPkg_name.type ||
  3800.                  ' : ' || rec_ProFunPkg_name.name ||
  3801.                  ' END;  ~~~~~~~~~~~~~~~~~~~~';
  3802.         insert_rec(n_line_no,
  3803.                    v_object_type,
  3804.                    v_username,
  3805.                    rec_ProFunPkg_name.name,
  3806.                    v_sql);
  3807.         n_line_no := n_line_no + 1;
  3808.       
  3809.         v_sql := '  ';
  3810.         insert_rec(n_line_no,
  3811.                    v_object_type,
  3812.                    v_username,
  3813.                    rec_ProFunPkg_name.name,
  3814.                    v_sql);
  3815.         n_line_no := n_line_no + 1;
  3816.       
  3817.       END IF;
  3818.     
  3819.       IF v_object_type = 'PROCEDURE' THEN
  3820.         v_sql := 'spool ' || v_file_path || 'procedures' || v_notion ||
  3821.                  'separ_files' || v_notion ||
  3822.                  lower(rec_ProFunPkg_name.name) || '.sql';
  3823.         insert_rec(n_line_no,
  3824.                    'SEPAR_PROCS',
  3825.                    v_username,
  3826.                    rec_ProFunPkg_name.name,
  3827.                    v_sql);
  3828.         n_line_no := n_line_no + 1;
  3829.       
  3830.         v_sql := 'SELECT rtrim(sql_text) FROM temp_for_pkg_gen_sql4000_temp ';
  3831.         insert_rec(n_line_no,
  3832.                    'SEPAR_PROCS',
  3833.                    v_username,
  3834.                    rec_ProFunPkg_name.name,
  3835.                    v_sql);
  3836.         n_line_no := n_line_no + 1;
  3837.       
  3838.         v_sql := 'WHERE OBJECT_TYPE = ''PROCEDURE'' AND OBJECT_NAME = ''' ||
  3839.                  rec_ProFunPkg_name.name || ''' ORDER BY line_no ; ';
  3840.         insert_rec(n_line_no,
  3841.                    'SEPAR_PROCS',
  3842.                    v_username,
  3843.                    rec_ProFunPkg_name.name,
  3844.                    v_sql);
  3845.         n_line_no := n_line_no + 1;
  3846.       
  3847.         v_sql := 'spool off';
  3848.         insert_rec(n_line_no,
  3849.                    'SEPAR_PROCS',
  3850.                    v_username,
  3851.                    rec_ProFunPkg_name.name,
  3852.                    v_sql);
  3853.         n_line_no := n_line_no + 1;
  3854.       
  3855.         v_sql := '  ';
  3856.         insert_rec(n_line_no,
  3857.                    'SEPAR_PROCS',
  3858.                    v_username,
  3859.                    rec_ProFunPkg_name.name,
  3860.                    v_sql);
  3861.         n_line_no := n_line_no + 1;
  3862.       
  3863.       ELSIF v_object_type = 'FUNCTION' THEN
  3864.         v_sql := 'spool ' || v_file_path || 'functions' || v_notion ||
  3865.                  'separ_files' || v_notion ||
  3866.                  lower(rec_ProFunPkg_name.name) || '.sql';
  3867.         insert_rec(n_line_no,
  3868.                    'SEPAR_FUNCS',
  3869.                    v_username,
  3870.                    rec_ProFunPkg_name.name,
  3871.                    v_sql);
  3872.         n_line_no := n_line_no + 1;
  3873.       
  3874.         v_sql := 'SELECT rtrim(sql_text) FROM temp_for_pkg_gen_sql4000_temp ';
  3875.         insert_rec(n_line_no,
  3876.                    'SEPAR_FUNCS',
  3877.                    v_username,
  3878.                    rec_ProFunPkg_name.name,
  3879.                    v_sql);
  3880.         n_line_no := n_line_no + 1;
  3881.       
  3882.         v_sql := 'WHERE OBJECT_TYPE = ''FUNCTION'' AND OBJECT_NAME = ''' ||
  3883.                  rec_ProFunPkg_name.name || ''' ORDER BY line_no ; ';
  3884.         insert_rec(n_line_no,
  3885.                    'SEPAR_FUNCS',
  3886.                    v_username,
  3887.                    rec_ProFunPkg_name.name,
  3888.                    v_sql);
  3889.         n_line_no := n_line_no + 1;
  3890.       
  3891.         v_sql := 'spool off';
  3892.         insert_rec(n_line_no,
  3893.                    'SEPAR_FUNCS',
  3894.                    v_username,
  3895.                    rec_ProFunPkg_name.name,
  3896.                    v_sql);
  3897.         n_line_no := n_line_no + 1;
  3898.       
  3899.         v_sql := '  ';
  3900.         insert_rec(n_line_no,
  3901.                    'SEPAR_FUNCS',
  3902.                    v_username,
  3903.                    rec_ProFunPkg_name.name,
  3904.                    v_sql);
  3905.         n_line_no := n_line_no + 1;
  3906.       ELSIF v_object_type = 'TRIGGER' THEN
  3907.         v_sql := 'spool ' || v_file_path || 'triggers' || v_notion ||
  3908.                  'separ_files' || v_notion ||
  3909.                  lower(rec_ProFunPkg_name.name) || '.sql';
  3910.         insert_rec(n_line_no,
  3911.                    'SEPAR_TRIS',
  3912.                    v_username,
  3913.                    rec_ProFunPkg_name.name,
  3914.                    v_sql);
  3915.         n_line_no := n_line_no + 1;
  3916.       
  3917.         v_sql := 'SELECT rtrim(sql_text) FROM temp_for_pkg_gen_sql4000_temp ';
  3918.         insert_rec(n_line_no,
  3919.                    'SEPAR_TRIS',
  3920.                    v_username,
  3921.                    rec_ProFunPkg_name.name,
  3922.                    v_sql);
  3923.         n_line_no := n_line_no + 1;
  3924.       
  3925.         v_sql := 'WHERE OBJECT_TYPE = ''TRIGGER'' AND OBJECT_NAME = ''' ||
  3926.                  rec_ProFunPkg_name.name || ''' ORDER BY line_no ; ';
  3927.         insert_rec(n_line_no,
  3928.                    'SEPAR_TRIS',
  3929.                    v_username,
  3930.                    rec_ProFunPkg_name.name,
  3931.                    v_sql);
  3932.         n_line_no := n_line_no + 1;
  3933.       
  3934.         v_sql := 'spool off';
  3935.         insert_rec(n_line_no,
  3936.                    'SEPAR_TRIS',
  3937.                    v_username,
  3938.                    rec_ProFunPkg_name.name,
  3939.                    v_sql);
  3940.         n_line_no := n_line_no + 1;
  3941.       
  3942.         v_sql := '  ';
  3943.         insert_rec(n_line_no,
  3944.                    'SEPAR_TRIS',
  3945.                    v_username,
  3946.                    rec_ProFunPkg_name.name,
  3947.                    v_sql);
  3948.         n_line_no := n_line_no + 1;
  3949.       ELSIF v_object_type = 'PACKAGE' THEN
  3950.         --生成可以将包头放在一个文件中的批处理文件
  3951.         v_sql := 'spool ' || v_file_path || 'packages' || v_notion ||
  3952.                  'separ_headbobdy_file' || v_notion ||
  3953.                  lower(rec_ProFunPkg_name.name) || '.head.sql;';
  3954.         insert_rec(n_line_no,
  3955.                    'SEPAR_PKG_HEADS',
  3956.                    v_username,
  3957.                    rec_ProFunPkg_name.name,
  3958.                    v_sql);
  3959.         n_line_no := n_line_no + 1;
  3960.       
  3961.         v_sql := 'SELECT rtrim(sql_text) FROM temp_for_pkg_gen_sql4000_temp ';
  3962.         insert_rec(n_line_no,
  3963.                    'SEPAR_PKG_HEADS',
  3964.                    v_username,
  3965.                    rec_ProFunPkg_name.name,
  3966.                    v_sql);
  3967.         n_line_no := n_line_no + 1;
  3968.       
  3969.         v_sql := 'WHERE OBJECT_TYPE = ''PACKAGE'' AND OBJECT_NAME = ''' ||
  3970.                  rec_ProFunPkg_name.name || ''' ORDER BY line_no ; ';
  3971.         insert_rec(n_line_no,
  3972.                    'SEPAR_PKG_HEADS',
  3973.                    v_username,
  3974.                    rec_ProFunPkg_name.name,
  3975.                    v_sql);
  3976.         n_line_no := n_line_no + 1;
  3977.       
  3978.         v_sql := 'spool off';
  3979.         insert_rec(n_line_no,
  3980.                    'SEPAR_PKG_HEADS',
  3981.                    v_username,
  3982.                    rec_ProFunPkg_name.name,
  3983.                    v_sql);
  3984.         n_line_no := n_line_no + 1;
  3985.       
  3986.         v_sql := '  ';
  3987.         insert_rec(n_line_no,
  3988.                    'SEPAR_PKG_HEADS',
  3989.                    v_username,
  3990.                    rec_ProFunPkg_name.name,
  3991.                    v_sql);
  3992.         n_line_no := n_line_no + 1;
  3993.       
  3994.         --生成可以将包体放在一个文件中的批处理文件
  3995.         v_sql := 'spool ' || v_file_path || 'packages' || v_notion ||
  3996.                  'separ_headbobdy_file' || v_notion ||
  3997.                  lower(rec_ProFunPkg_name.name) || '.body.sql;';
  3998.         insert_rec(n_line_no,
  3999.                    'SEPAR_PKG_BODYS',
  4000.                    v_username,
  4001.                    rec_ProFunPkg_name.name,
  4002.                    v_sql);
  4003.         n_line_no := n_line_no + 1;
  4004.       
  4005.         v_sql := 'SELECT rtrim(sql_text) FROM temp_for_pkg_gen_sql4000_temp ';
  4006.         insert_rec(n_line_no,
  4007.                    'SEPAR_PKG_BODYS',
  4008.                    v_username,
  4009.                    rec_ProFunPkg_name.name,
  4010.                    v_sql);
  4011.         n_line_no := n_line_no + 1;
  4012.       
  4013.         v_sql := 'WHERE OBJECT_TYPE = ''PACKAGE BODY'' AND OBJECT_NAME = ''' ||
  4014.                  rec_ProFunPkg_name.name || ''' ORDER BY line_no ; ';
  4015.         insert_rec(n_line_no,
  4016.                    'SEPAR_PKG_BODYS',
  4017.                    v_username,
  4018.                    rec_ProFunPkg_name.name,
  4019.                    v_sql);
  4020.         n_line_no := n_line_no + 1;
  4021.       
  4022.         v_sql := 'spool off;';
  4023.         insert_rec(n_line_no,
  4024.                    'SEPAR_PKG_BODYS',
  4025.                    v_username,
  4026.                    rec_ProFunPkg_name.name,
  4027.                    v_sql);
  4028.         n_line_no := n_line_no + 1;
  4029.       
  4030.         v_sql := '  ';
  4031.         insert_rec(n_line_no,
  4032.                    'SEPAR_PKG_BODYS',
  4033.                    v_username,
  4034.                    rec_ProFunPkg_name.name,
  4035.                    v_sql);
  4036.         n_line_no := n_line_no + 1;
  4037.       
  4038.         v_sql := '  ';
  4039.         insert_rec(n_line_no,
  4040.                    'SEPAR_PKG_HEADS',
  4041.                    v_username,
  4042.                    rec_ProFunPkg_name.name,
  4043.                    v_sql);
  4044.         n_line_no := n_line_no + 1;
  4045.       
  4046.         -- the package head and package body allow in the same file
  4047.         v_sql := 'spool ' || v_file_path || 'packages' || v_notion ||
  4048.                  'separ_files' || v_notion ||
  4049.                  lower(rec_ProFunPkg_name.name) || '.sql;';
  4050.         insert_rec(n_line_no,
  4051.                    'SEPAR_PKGS',
  4052.                    v_username,
  4053.                    rec_ProFunPkg_name.name,
  4054.                    v_sql);
  4055.         n_line_no := n_line_no + 1;
  4056.       
  4057.         v_sql := 'SELECT rtrim(sql_text) FROM temp_for_pkg_gen_sql4000_temp ';
  4058.         insert_rec(n_line_no,
  4059.                    'SEPAR_PKGS',
  4060.                    v_username,
  4061.                    rec_ProFunPkg_name.name,
  4062.                    v_sql);
  4063.         n_line_no := n_line_no + 1;
  4064.       
  4065.         v_sql := 'WHERE OBJECT_TYPE like ''%PACKAGE%'' AND OBJECT_NAME = ''' ||
  4066.                  rec_ProFunPkg_name.name || ''' ORDER BY line_no ; ';
  4067.         insert_rec(n_line_no,
  4068.                    'SEPAR_PKGS',
  4069.                    v_username,
  4070.                    rec_ProFunPkg_name.name,
  4071.                    v_sql);
  4072.         n_line_no := n_line_no + 1;
  4073.       
  4074.         v_sql := 'spool off;';
  4075.         insert_rec(n_line_no,
  4076.                    'SEPAR_PKGS',
  4077.                    v_username,
  4078.                    rec_ProFunPkg_name.name,
  4079.                    v_sql);
  4080.         n_line_no := n_line_no + 1;
  4081.       
  4082.         v_sql := '  ';
  4083.         insert_rec(n_line_no,
  4084.                    'SEPAR_PKGS',
  4085.                    v_username,
  4086.                    rec_ProFunPkg_name.name,
  4087.                    v_sql);
  4088.         n_line_no := n_line_no + 1;
  4089.       END IF;
  4090.     
  4091.     END LOOP;
  4092.   
  4093.     -- 生成批量运行生成各个文件的批文件
  4094.     v_sql := 'spool ' || v_file_path || 'procedures' || v_notion ||
  4095.              'separ_files' || v_notion || 'start_procs.sql';
  4096.     insert_rec(n_line_no, 'SEPAR_PROCS', v_username, 'SEPAR_PROCS', v_sql);
  4097.     n_line_no := n_line_no + 1;
  4098.   
  4099.     v_sql := 'SELECT rtrim(sql_text) FROM temp_for_pkg_gen_sql4000_temp ';
  4100.     insert_rec(n_line_no, 'SEPAR_PROCS', v_username, 'SEPAR_PROCS', v_sql);
  4101.     n_line_no := n_line_no + 1;
  4102.   
  4103.     v_sql := 'WHERE OBJECT_TYPE = ''PROCEDURE'' AND OBJECT_NAME = ''START_PROCS'' ORDER BY line_no ; ';
  4104.     insert_rec(n_line_no, 'SEPAR_PROCS', v_username, 'SEPAR_PROCS', v_sql);
  4105.     n_line_no := n_line_no + 1;
  4106.   
  4107.     v_sql := 'spool off';
  4108.     insert_rec(n_line_no, 'SEPAR_PROCS', v_username, 'SEPAR_PROCS', v_sql);
  4109.     n_line_no := n_line_no + 1;
  4110.   
  4111.     v_sql := '  ';
  4112.     insert_rec(n_line_no, 'SEPAR_PROCS', v_username, 'SEPAR_PROCS', v_sql);
  4113.     n_line_no := n_line_no + 1;
  4114.   
  4115.     v_sql := 'spool ' || v_file_path || 'functions' || v_notion ||
  4116.              'separ_files' || v_notion || 'start_funcs.sql';
  4117.     insert_rec(n_line_no, 'SEPAR_FUNCS', v_username, 'SEPAR_FUNCS', v_sql);
  4118.     n_line_no := n_line_no + 1;
  4119.   
  4120.     v_sql := 'SELECT rtrim(sql_text) FROM temp_for_pkg_gen_sql4000_temp ';
  4121.     insert_rec(n_line_no, 'SEPAR_FUNCS', v_username, 'SEPAR_FUNCS', v_sql);
  4122.     n_line_no := n_line_no + 1;
  4123.   
  4124.     v_sql := 'WHERE OBJECT_TYPE = ''FUNCTION'' AND OBJECT_NAME = ''START_FUNCS'' ORDER BY line_no ; ';
  4125.     insert_rec(n_line_no, 'SEPAR_FUNCS', v_username, 'SEPAR_FUNCS', v_sql);
  4126.     n_line_no := n_line_no + 1;
  4127.   
  4128.     v_sql := 'spool off';
  4129.     insert_rec(n_line_no, 'SEPAR_FUNCS', v_username, 'SEPAR_FUNCS', v_sql);
  4130.     n_line_no := n_line_no + 1;
  4131.   
  4132.     v_sql := '  ';
  4133.     insert_rec(n_line_no, 'SEPAR_FUNCS', v_username, 'SEPAR_FUNCS', v_sql);
  4134.     n_line_no := n_line_no + 1;
  4135.   
  4136.     v_sql := 'spool ' || v_file_path || 'triggers' || v_notion ||
  4137.              'separ_files' || v_notion || 'start_tris.sql';
  4138.     insert_rec(n_line_no, 'SEPAR_TRIS', v_username, 'SEPAR_TRIS', v_sql);
  4139.     n_line_no := n_line_no + 1;
  4140.   
  4141.     v_sql := 'SELECT rtrim(sql_text) FROM temp_for_pkg_gen_sql4000_temp ';
  4142.     insert_rec(n_line_no, 'SEPAR_TRIS', v_username, 'SEPAR_TRIS', v_sql);
  4143.     n_line_no := n_line_no + 1;
  4144.   
  4145.     v_sql := 'WHERE OBJECT_TYPE = ''TRIGGER'' AND OBJECT_NAME = ''SEPAR_TRIS'' ORDER BY line_no ; ';
  4146.     insert_rec(n_line_no, 'SEPAR_TRIS', v_username, 'SEPAR_TRIS', v_sql);
  4147.     n_line_no := n_line_no + 1;
  4148.   
  4149.     v_sql := 'spool off';
  4150.     insert_rec(n_line_no, 'SEPAR_TRIS', v_username, 'SEPAR_TRIS', v_sql);
  4151.     n_line_no := n_line_no + 1;
  4152.   
  4153.     v_sql := '  ';
  4154.     insert_rec(n_line_no, 'SEPAR_TRIS', v_username, 'SEPAR_TRIS', v_sql);
  4155.     n_line_no := n_line_no + 1;
  4156.   
  4157.     v_sql := 'spool ' || v_file_path || 'packages' || v_notion ||
  4158.              'separ_headbobdy_file' || v_notion || 'start_pkg_heads.sql;';
  4159.     insert_rec(n_line_no,
  4160.                'SEPAR_PKG_HEADS',
  4161.                v_username,
  4162.                'SEPAR_PKG_HEADS',
  4163.                v_sql);
  4164.     n_line_no := n_line_no + 1;
  4165.   
  4166.     v_sql := 'SELECT rtrim(sql_text) FROM temp_for_pkg_gen_sql4000_temp ';
  4167.     insert_rec(n_line_no,
  4168.                'SEPAR_PKG_HEADS',
  4169.                v_username,
  4170.                'SEPAR_PKG_HEADS',
  4171.                v_sql);
  4172.     n_line_no := n_line_no + 1;
  4173.   
  4174.     v_sql := 'WHERE OBJECT_TYPE = ''PACKAGE'' AND OBJECT_NAME = ''START_PKG_HS'' ORDER BY line_no ; ';
  4175.     insert_rec(n_line_no,
  4176.                'SEPAR_PKG_HEADS',
  4177.                v_username,
  4178.                'SEPAR_PKG_HEADS',
  4179.                v_sql);
  4180.     n_line_no := n_line_no + 1;
  4181.   
  4182.     v_sql := 'spool off';
  4183.     insert_rec(n_line_no,
  4184.                'SEPAR_PKG_HEADS',
  4185.                v_username,
  4186.                'SEPAR_PKG_HEADS',
  4187.                v_sql);
  4188.     n_line_no := n_line_no + 1;
  4189.   
  4190.     v_sql := '  ';
  4191.     insert_rec(n_line_no,
  4192.                'SEPAR_PKG_HEADS',
  4193.                v_username,
  4194.                'SEPAR_PKG_HEADS',
  4195.                v_sql);
  4196.     n_line_no := n_line_no + 1;
  4197.   
  4198.     v_sql := 'spool ' || v_file_path || 'packages' || v_notion ||
  4199.              'separ_headbobdy_file' || v_notion || 'start_pkg_bodys.sql;';
  4200.     insert_rec(n_line_no,
  4201.                'SEPAR_PKG_BODYS',
  4202.                v_username,
  4203.                'SEPAR_PKG_BODYS',
  4204.                v_sql);
  4205.     n_line_no := n_line_no + 1;
  4206.   
  4207.     v_sql := 'SELECT rtrim(sql_text) FROM temp_for_pkg_gen_sql4000_temp ';
  4208.     insert_rec(n_line_no,
  4209.                'SEPAR_PKG_BODYS',
  4210.                v_username,
  4211.                'SEPAR_PKG_BODYS',
  4212.                v_sql);
  4213.     n_line_no := n_line_no + 1;
  4214.   
  4215.     v_sql := 'WHERE OBJECT_TYPE = ''PACKAGE'' AND OBJECT_NAME = ''START_PKG_BS'' ORDER BY line_no ; ';
  4216.     insert_rec(n_line_no,
  4217.                'SEPAR_PKG_BODYS',
  4218.                v_username,
  4219.                'SEPAR_PKG_BODYS',
  4220.                v_sql);
  4221.     n_line_no := n_line_no + 1;
  4222.   
  4223.     v_sql := 'spool off';
  4224.     insert_rec(n_line_no,
  4225.                'SEPAR_PKG_BODYS',
  4226.                v_username,
  4227.                'SEPAR_PKG_BODYS',
  4228.                v_sql);
  4229.     n_line_no := n_line_no + 1;
  4230.   
  4231.     v_sql := '  ';
  4232.     insert_rec(n_line_no, 'SEPAR_PKGS', v_username, 'SEPAR_PKGS', v_sql);
  4233.     n_line_no := n_line_no + 1;
  4234.   
  4235.     v_sql := 'spool ' || v_file_path || 'packages' || v_notion ||
  4236.              'separ_files' || v_notion || 'start_pkgs.sql;';
  4237.     insert_rec(n_line_no, 'SEPAR_PKGS', v_username, 'SEPAR_PKGS', v_sql);
  4238.     n_line_no := n_line_no + 1;
  4239.   
  4240.     v_sql := 'SELECT rtrim(sql_text) FROM temp_for_pkg_gen_sql4000_temp ';
  4241.     insert_rec(n_line_no, 'SEPAR_PKGS', v_username, 'SEPAR_PKGS', v_sql);
  4242.     n_line_no := n_line_no + 1;
  4243.   
  4244.     v_sql := 'WHERE OBJECT_TYPE = ''PACKAGE'' AND OBJECT_NAME = ''START_PKGS'' ORDER BY line_no ; ';
  4245.     insert_rec(n_line_no, 'SEPAR_PKGS', v_username, 'SEPAR_PKGS', v_sql);
  4246.     n_line_no := n_line_no + 1;
  4247.   
  4248.     v_sql := 'spool off';
  4249.     insert_rec(n_line_no, 'SEPAR_PKGS', v_username, 'SEPAR_PKGS', v_sql);
  4250.     n_line_no := n_line_no + 1;
  4251.   
  4252.     v_sql := '  ';
  4253.     insert_rec(n_line_no, 'SEPAR_PKGS', v_username, 'SEPAR_PKGS', v_sql);
  4254.     n_line_no := n_line_no + 1;
  4255.     COMMIT;
  4256.   
  4257.   END;
  4258. END pkg_gen_user_sql;
  4259. /
  4260. show err
  4261. set echo off
  4262. set feedback off
  4263. set newpage none
  4264. set pagesize 0
  4265. set verify off
  4266. set pagesize 0
  4267. set term off
  4268. set trims on
  4269. set linesize 5005
  4270. set heading  off 
  4271. set timing off
  4272. set verify off
  4273. set numwidth 38
  4274. -- 生成start
  4275. exec pkg_gen_user_sql.pro_gen_start_sql('&&file_dic')
  4276. spool &&file_dic/start_all.sql  
  4277. SELECT rtrim(sql_text) 
  4278. FROM temp_for_pkg_gen_sql2000_temp
  4279. WHERE OBJECT_TYPE = 'START_SQL'
  4280. ORDER BY line_no ;  
  4281. spool off  
  4282. -- 生成创建表的sql语句
  4283. exec pkg_gen_user_sql.pro_tab_sql_tab8('F','T','F','T');
  4284. spool &&file_dic/cre_tables.sql  
  4285. SELECT rtrim(sql_text) 
  4286. FROM temp_for_pkg_gen_sql2000_temp
  4287. WHERE OBJECT_TYPE = 'TABLE_8'
  4288. ORDER BY line_no ;  
  4289. spool off  
  4290. -- 生成创建索引的sql语句
  4291. exec pkg_gen_user_sql.pro_indx_sql('F','T','F','T')
  4292. spool &&file_dic/cre_indexes.sql
  4293. SELECT   sql_text
  4294. FROM temp_for_pkg_gen_sql2000_temp
  4295. WHERE OBJECT_TYPE = 'INDEX'
  4296. ORDER BY line_no;
  4297. spool off
  4298. -- 生成创建主键约束的sql语句
  4299. exec pkg_gen_user_sql.pro_con_sql('P','F','T','T','T');  
  4300. spool &&file_dic/cre_pri_constraint.sql  
  4301. SELECT rtrim(sql_text) 
  4302. FROM temp_for_pkg_gen_sql2000_temp
  4303. WHERE OBJECT_TYPE = 'CONSTRAINT'
  4304. ORDER BY line_no;  
  4305. spool off
  4306. -- 生成创建出主键约束的其它约束的sql语句
  4307. exec pkg_gen_user_sql.pro_con_sql('NOT_PRI','F','T','F','T');  
  4308. spool &&file_dic/cre_not_pri_constraint.sql  
  4309. SELECT rtrim(sql_text) 
  4310. FROM temp_for_pkg_gen_sql2000_temp
  4311. WHERE OBJECT_TYPE = 'CONSTRAINT'
  4312. ORDER BY line_no;  
  4313. spool off
  4314. -- 生成创建所有约束的sql语句
  4315. exec pkg_gen_user_sql.pro_con_sql('A','F','T','T','T');  
  4316. spool &&file_dic/cre_constraints.sql  
  4317. SELECT rtrim(sql_text) 
  4318. FROM temp_for_pkg_gen_sql2000_temp
  4319. WHERE OBJECT_TYPE = 'CONSTRAINT'
  4320. ORDER BY line_no;  
  4321. spool off
  4322. -- 生成重建索引的sql语句
  4323. exec pkg_gen_user_sql.pro_reb_indx_sql('F','F')
  4324. spool &&file_dic/reb_indexes.sql
  4325. SELECT   sql_text
  4326. FROM temp_for_pkg_gen_sql2000_temp
  4327. WHERE OBJECT_TYPE = 'REBUILD_INDEX'
  4328. ORDER BY line_no;
  4329. spool off
  4330. -- 生成创建视图的sql语句
  4331. exec pkg_gen_user_sql.pro_view_sql('F','T','T');
  4332. spool &&file_dic/cre_views.sql
  4333. SELECT   sql_text
  4334. FROM temp_for_pkg_gen_sql4000_temp
  4335. WHERE OBJECT_TYPE = 'VIEW'
  4336. ORDER BY line_no;
  4337. spool off
  4338. -- 生成创建序列的sql语句
  4339. exec pkg_gen_user_sql.pro_seq_next_val_sql('F');
  4340. spool &&file_dic/cre_sequences.sql
  4341. SELECT   sql_text
  4342. FROM temp_for_pkg_gen_sql2000_temp
  4343. WHERE OBJECT_TYPE = 'SEQUENCE'
  4344. ORDER BY line_no;
  4345. spool off
  4346. -- 生成创建初始序列的sql语句, 每个序列的开始值为1
  4347. exec pkg_gen_user_sql.pro_seq_init_val_sql('F');
  4348. spool &&file_dic/cre_sequences_init.sql
  4349. SELECT   sql_text
  4350. FROM temp_for_pkg_gen_sql2000_temp
  4351. WHERE OBJECT_TYPE = 'SEQUENCE_INIT'
  4352. ORDER BY line_no;
  4353. spool off
  4354. -- 生成创建同义词的sql语句
  4355. exec pkg_gen_user_sql.pro_synonym_sql('F')
  4356. spool &&file_dic/cre_synonyms.sql  
  4357. SELECT rtrim(sql_text) 
  4358. FROM temp_for_pkg_gen_sql2000_temp
  4359. WHERE OBJECT_TYPE = 'SYNONYM'
  4360. ORDER BY line_no ;  
  4361. spool off  
  4362. -- 生成创建job的sql语句
  4363. exec pkg_gen_user_sql.pro_job_sql('F')
  4364. spool &&file_dic/cre_jobs.sql  
  4365. SELECT rtrim(sql_text) 
  4366. FROM temp_for_pkg_gen_sql4000_temp
  4367. WHERE OBJECT_TYPE = 'JOB'
  4368. ORDER BY line_no ;  
  4369. spool off  
  4370. -- 生成创建数据库链的sql语句
  4371. exec pkg_gen_user_sql.pro_dl_sql('F')
  4372. spool &&file_dic/cre_db_links.sql  
  4373. SELECT rtrim(sql_text) 
  4374. FROM temp_for_pkg_gen_sql2000_temp
  4375. WHERE OBJECT_TYPE = 'DL'
  4376. ORDER BY line_no ;  
  4377. spool off  
  4378. -- 生成创建角色的sql语句
  4379. exec pkg_gen_user_sql.pro_role_sql('F')
  4380. spool &&file_dic/cre_roles.sql  
  4381. SELECT rtrim(sql_text) 
  4382. FROM temp_for_pkg_gen_sql2000_temp
  4383. WHERE OBJECT_TYPE = 'ROLE'
  4384. ORDER BY line_no ;  
  4385. spool off 
  4386. -- 生成创建授权的sql语句
  4387. exec pkg_gen_user_sql.pro_priv_sql('F')
  4388. spool &&file_dic/cre_privs.sql  
  4389. SELECT rtrim(sql_text) 
  4390. FROM temp_for_pkg_gen_sql2000_temp
  4391. WHERE OBJECT_TYPE = 'PRIV'
  4392. ORDER BY line_no ;  
  4393. spool off 
  4394. -- 生成创建存储过程的sql语句,所有存储过程放在一个文件中
  4395. exec pkg_gen_user_sql.pro_pkgprofuntri_sql('F','T','T','T','&&file_dic')
  4396. spool &&file_dic/procedures/procedures.sql  
  4397. SELECT rtrim(sql_text) 
  4398. FROM temp_for_pkg_gen_sql4000_temp
  4399. WHERE OBJECT_TYPE = 'PROCEDURE'
  4400.     AND lower(rtrim(sql_text)) not like '@%.sql'
  4401. ORDER BY line_no ;  
  4402. spool off 
  4403. -- 生成创建函数的sql语句,所有函数放在一个文件中
  4404. spool &&file_dic/functions/functions.sql
  4405. SELECT rtrim(sql_text) 
  4406. FROM temp_for_pkg_gen_sql4000_temp
  4407. WHERE OBJECT_TYPE = 'FUNCTION'
  4408.      AND lower(rtrim(sql_text)) not like '@%.sql'
  4409. ORDER BY line_no ;  
  4410. spool off 
  4411. -- 生成创建包的sql语句,所有包放在一个文件中
  4412. spool &&file_dic/packages/packages.sql
  4413. SELECT rtrim(sql_text) 
  4414. FROM temp_for_pkg_gen_sql4000_temp
  4415. WHERE OBJECT_TYPE like '%PACKAGE%'
  4416.      AND lower(rtrim(sql_text)) not like '@%.sql'
  4417. ORDER BY line_no ;
  4418. spool off
  4419. -- 生成创建触发器的sql语句
  4420. spool &&file_dic/triggers/triggers.sql
  4421. SELECT rtrim(sql_text) 
  4422. FROM temp_for_pkg_gen_sql4000_temp
  4423. WHERE OBJECT_TYPE = 'TRIGGER'
  4424. ORDER BY line_no ;  
  4425. spool off 
  4426. -- 生成创建存储过程的sql语句,每个存储过程放在单独的文件中
  4427. spool &&file_dic/temp_sql/separ_pros.sql
  4428. SELECT rtrim(sql_text) 
  4429. FROM temp_for_pkg_gen_sql4000_temp
  4430. WHERE OBJECT_TYPE = 'SEPAR_PROCS'
  4431. ORDER BY line_no ;  
  4432. spool off 
  4433. @ &&file_dic/temp_sql/separ_pros.sql 
  4434. -- 生成创建函数的sql语句,每个函数放在单独的文件中
  4435. spool &&file_dic/temp_sql/separ_funcs.sql
  4436. SELECT rtrim(sql_text) 
  4437. FROM temp_for_pkg_gen_sql4000_temp
  4438. WHERE OBJECT_TYPE = 'SEPAR_FUNCS'
  4439. ORDER BY line_no ;  
  4440. spool off 
  4441. @ &&file_dic/temp_sql/separ_funcs.sql  
  4442. -- 生成创建包的sql语句,每个包放在单独的文件中
  4443. spool &&file_dic/temp_sql/separ_pkgs.sql
  4444. SELECT rtrim(sql_text)
  4445. FROM temp_for_pkg_gen_sql4000_temp
  4446. WHERE OBJECT_TYPE like '%SEPAR_PKGS%'
  4447. ORDER BY line_no ;  
  4448. spool off 
  4449. @ &&file_dic/temp_sql/separ_pkgs.sql
  4450. -- 生成创建存储过程的sql语句,每个包的声明与包体各放在单独的文件中
  4451. spool &&file_dic/temp_sql/separ_hb_pkgs.sql
  4452. SELECT rtrim(sql_text)
  4453. FROM temp_for_pkg_gen_sql4000_temp
  4454. WHERE OBJECT_TYPE in ('SEPAR_PKG_HEADS','SEPAR_PKG_BODYS')
  4455. ORDER BY object_name,OBJECT_TYPE desc, line_no ;  
  4456. spool off 
  4457. @ &&file_dic/temp_sql/separ_hb_pkgs.sql
  4458. -- 生成创建触发器的sql语句,每个触发器放在单独的文件中
  4459. spool &&file_dic/temp_sql/separ_tris.sql
  4460. SELECT rtrim(sql_text) 
  4461. FROM temp_for_pkg_gen_sql4000_temp
  4462. WHERE OBJECT_TYPE = 'SEPAR_TRIS'
  4463. ORDER BY line_no ;  
  4464. spool off 
  4465. @ &&file_dic/temp_sql/separ_tris.sql  
  4466. set echo on
  4467. set feedback on
  4468. set newpage 1
  4469. set pagesize 500
  4470. set linesize 80
  4471. set verify on
  4472. set term on
  4473. set trims on
  4474. set linesize 600
  4475. set heading  on 
  4476. set timing off
  4477. set verify on
  4478. set numwidth 15
  4479. drop table temp_for_pkg_gen_sql2000_temp; 
  4480. drop table temp_for_pkg_gen_sql4000_temp;
  4481. drop package pkg_gen_user_sql;
来自: http://www.oracle.com.cn/viewthread.php?tid=69847&extra=page%3D1%26amp%3Bfilter%3Ddigest
  • 0
    点赞
  • 6
    收藏
    觉得还不错? 一键收藏
  • 3
    评论
适用的数据库:8i, 9i数据库下该脚本通用<br/><br/>功能:导出一个用户数据结构包括视图索引约束、存储过程、触发器、函数、序列等等的定义,并且每个定义为一个文件<br/> 导出的各个对象的定义格式比较规范。<br/> 如的定义为:<br/> prompt Create Table BBNACTIVEHISTORY<br/> CREATE TABLE test(<br/> USERID VARCHAR2(20) NOT NULL,<br/> SPUSERID VARCHAR2(30) NOT NULL,<br/> PRODUCTID VARCHAR2(20) NOT NULL,<br/> GAMETYPE NUMBER NOT NULL,<br/> STARTTIME DATE NOT NULL,<br/> CHARGED CHAR(1) default 'N' NOT NULL<br/> );<br/> <br/> 每个存储过程有多个参数,可以控制输出何种形式的内容,如可以只生成删除sql,可以在生成的创建索引的语句上加上storage子句等等。<br/><br/>运行 user_dll_sql.sql的准备工作:<br/><br/>1. 修改win_mkdir.bat文件,以便生成存放生成脚本的基本目录及其子目录<br/> win_mkdir.bat文件生成上面所需要的所有目录<br/> 打开win_mkdir.bat文件,修改BASE_DIC变量的值,如c:\temp\,该目录是存放生成的脚本文件的基本目录<br/> <br/> <br/>2. 运行 win_mkdir.bat文件创建必要的目录<br/><br/>3. 用sql*plus以想导出数据结构用户登陆到数据库<br/> 运行user_dll_sql.sql 生成文件的路径文件,生成所有的ddl语句<br/> 运行文件时,将存放生成脚本的基本目录作为参数(与步骤1改的基本目录一样)传入, ?要根据需要改为实际的目录<br/> SQL> @?\user_ddl_sql.sql c:\temp\<br/> <br/><br/>说明:<br/> 运行win_mkdir.bat,文件后,会自动在生成脚本的基本目录下产生如下目录:<br/> procedures, functions, triggers, packages, temp_sql.<br/> 每个目录的作用如下:<br/> procedures: 该目录存放存储过程, 有子目录separ_files, 该目录下的每个文件都是一个存储过程的源代码 <br/> functions: 该目录存放函数, 有子目录separ_files, 该目录下的每个文件都是一个函数的源代码<br/> triggers: 该目录存放触发器, 有子目录separ_files, 该目录下的每个文件都是一个触发器的源代码<br/> packages: 该目录存放包, 有子目录separ_files, 该目录下的每个文件都是一个包的源代码<br/> 有子目录separ_headbobdy_file, 该目录下的每个文件都是一个包的包头或包体的源代码<br/> temp_sql:存放生成的临时文件<br/>
评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值