六狼论坛

 找回密码
 立即注册

QQ登录

只需一步,快速开始

新浪微博账号登陆

只需一步,快速开始

搜索
查看: 81|回复: 0

db2存储过程

[复制链接]

升级  7.33%

15

主题

15

主题

15

主题

秀才

Rank: 2

积分
61
 楼主| 发表于 2013-1-13 18:38:07 | 显示全部楼层 |阅读模式
删表时判断是否存在的存储过程

CREATE procedure EXISTSTVF(FLAG VARCHAR(1),TNAME VARCHAR(50))
    LANGUAGE SQL
    MODIFIES SQL DATA
    NOT DETERMINISTIC
    EXTERNAL ACTION
    begin atomic
--该函数用于查询表、视图、函数是否存在
    --FLAG='T'表示查询表是否存在,FLAG='V'表示查询视图是否存在,FLAG='F'表示查询函数是否存在
         declare  Fint int default 0;
         declare x varchar(100);
         if(Flag='T') then
             set Fint = (select count(*) from sysibm.systables where name = upper(TName));
         elseif(Flag='V') then
             set Fint = (select count(*) from sysibm.sysviews where  name = upper(TName));
         else
            set Fint = (select count(*) from sysibm.sysfunctions where name = upper(TName));
         end if;
         
         if(Flag='T'  and Fint = 1) then
           set x = 'drop table '||TNAME;
           execute immediate x;
         elseif(Flag='V' and Fint = 1) then
           set x = 'drop view '||TNAME;
           execute immediate x;
         elseif(Flag='F' and Fint = 1) then
           set x = 'drop function '||TNAME;
           execute immediate x;
         end if;
     end


附件中还有几个例子
您需要登录后才可以回帖 登录 | 立即注册 新浪微博账号登陆

本版积分规则

快速回复 返回顶部 返回列表