删除DB2视图(如果存在) [英] Drop a DB2 view if it exists

查看:730
本文介绍了删除DB2视图(如果存在)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

为什么在 IBM数据中不起作用Studio(Eclipse)

IF EXISTS (SELECT 1 FROM SYSIBM.SYSVIEWS WHERE NAME = 'MYVIEW' AND CREATOR = 'MYSCHEMA') THEN
    DROP VIEW MYSCHEMA.MYVIEW;
END IF;

我感觉这与语句终止符(;)有关,但我找不到

I have a feeling it has to do with statement terminators (;) but I can't find a syntax that works.

另一个类似的问题,位于在db2 9.1中将其删除之前,如何检查过程/视图/表是否存在?建议他们必须创建一个proc,但这对我们来说不是解决方案。

Another similar question at How to check a procedure/view/table exists or not before dropping it in db2 9.1? suggests that they had to create a proc but this isn't a solution for us.

推荐答案

摘自IBM的书:数据入门Studio for DB2


语句终止符:您可以在单个
中开发
多个SQL语句通过在每个
语句后加上一个语句终止符
字符,在SQL编辑器窗口中。默认终止符为
分号。但是,您可以通过右键单击
编辑器的内容并选择
上下文菜单操作Set
Statement Terminator来将其更改为
一个字符。

Statement terminator: You can develop multiple SQL statements in a single SQL Editor window by ending each statement with a statement terminator character. The default terminator is a semi-colon. But you can change that to another character by right-clicking in the contents of the editor and selecting the context menu action Set Statement Terminator.

编辑:

好的,问题似乎出在语法上。许多人似乎也有同样的问题。示例请参见 DROP TABLE,VIEW,...仅当存在时

OK, the problem seems to be the syntax. Many people seem to have the same problem. Example see DROP TABLE, VIEW, ... only IF EXISTS.

在该示例中,提到了两种解决方案。

In the example there are two solutions mentioned.


  1. 使用开始原子

  2. 使用过程 db2perf_quiet_drop

  1. use Begin atomic
  2. use the procedure db2perf_quiet_drop

有关详细信息,请阅读喜欢的页面。

For details read the liked page.

第二编辑:

我刚刚在IBM页面上找到了关于开始无原子化的一个很好的解释。请参阅IBM的高级SQL脚本PL 。示例2是您要寻找的东西。

I just found a really good explanation for Begin ataomic on the IBM pages. See Advanced SQL Scripting PL from IBM. Example 2 is what you are looking for.

这篇关于删除DB2视图(如果存在)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆