db2数据库问题
IF EXISTS (SELECT * FROM SYSOBJECTS WHERE NAME='VS_DEPARTMENT') THEN DROP VIEW VS_DEPARTMENT! END IF 上面这个是SQLSERVER写法,但是在DB2下执行不了,请问DB2下应该怎么写 注:VS_DEPARTMENT是我的视图的名字
IF EXISTS (SELECT * FROM SYSOBJECTS WHERE NAME='VS_DEPARTMENT') THEN DROP VIEW VS_DEPARTMENT! END IF 上面这个是SQLSERVER写法,但是在DB2下执行不了,请问DB2下应该怎么写 注:VS_DEPARTMENT是我的视图的名字
答案:drop view VS_DEPARTMENT;
create VS_DEPARTMENT as
SELECT * FROM SYSOBJECTS WHERE NAME='VS_DEPARTMENT' ;
这样可以,我用db2都是这样写的。
其他:你定义个变量
用select count(*) into 变量
然后判断 变量> 0 试试