Chinaunix首页 | 论坛 | 博客
  • 博客访问: 260713
  • 博文数量: 70
  • 博客积分: 2500
  • 博客等级: 少校
  • 技术积分: 930
  • 用 户 组: 普通用户
  • 注册时间: 2008-04-22 12:32
文章存档

2009年(42)

2008年(28)

我的朋友

分类:

2008-12-20 16:42:45


set serveroutput on

DECLARE
  user_exists EXCEPTION;
  outln_user number;
  outln_tables number;
  extra_outln_tables number;
  DDL_CURSOR integer;
BEGIN
  select count(*) into outln_user from user$ where name='OUTLN';

  select count(*) into outln_tables from obj$ where name in
        ('OL$', 'OL$HINTS') and owner#=
        (select user# from user$ where name='OUTLN');  

  select count(*) into extra_outln_tables from obj$ where name not in
        ('OL$', 'OL$HINTS') and type#=2 and owner#=
        (select user# from user$ where name='OUTLN');  


  DDL_CURSOR := dbms_sql.open_cursor;       
  IF outln_user = 0 THEN
        dbms_sql.parse(DDL_CURSOR, 'create user outln identified by outln',
                 dbms_sql.native);
        dbms_sql.parse(DDL_CURSOR,
                 'grant connect, resource, execute any procedure to outln',
                 dbms_sql.native);
        dbms_sql.parse(DDL_CURSOR, 'create table outln.ol$ ( '||
          'ol_name           varchar2(30), ' ||      
            'sql_text          long,  ' ||               
            'textlen           number,  ' ||            
            'signature         raw(16), ' ||            
            'hash_value        number, ' ||              
            'category          varchar2(30), ' ||        
            'version           varchar2(64), ' ||        
            'creator           varchar2(30), ' ||        
            'timestamp         date,  ' ||               
            'flags             number, ' ||              
            'hintcount         number)', dbms_sql.native);
        dbms_sql.parse(DDL_CURSOR, 'create table outln.ol$hints ( '||
          'ol_name           varchar2(30),  '||
            'hint#             number,  '||      
            'category          varchar2(30),  '||
            'hint_type         number,  '||      
            'hint_text         varchar2(512), '||
            'stage#            number,  '||      
            'node#             number, '||      
            'table_name        varchar2(30),  '||
            'table_tin         number,  '||      
            'table_pos         number)', dbms_sql.native);
        dbms_sql.parse(DDL_CURSOR, 'create unique index outln.ol$name '||
          'on outln.ol$(ol_name)', dbms_sql.native);
        dbms_sql.parse(DDL_CURSOR, 'create unique index outln.ol$signature '||
          ' on outln.ol$(signature,category)', dbms_sql.native);
        dbms_sql.parse(DDL_CURSOR, 'create unique index outln.ol$hnt_num '||
          ' on outln.ol$hints(ol_name, hint#)', dbms_sql.native);
        dbms_output.put_line('OUTLN CREATION SUCCESSFUL');
  ELSE
            IF outln_tables!=2 or extra_outln_tables!=0 THEN
                dbms_output.put_line('ERROR - OUTLN USER ALREADY EXISTS');
                RAISE user_exists;
        ELSE
                dbms_output.put_line('OUTLN CREATION SUCCESSFUL');
        END IF;
  END IF;

  EXCEPTION
         %
阅读(779) | 评论(0) | 转发(0) |
0

上一篇:范仲淹 岳阳楼记

下一篇:破窗理论

给主人留下些什么吧!~~