LoveUnix » DB2 & Informix » DB2的EXISTS怎么用啊??求助
让LU留住您的每

一天 让LU博客留住您的每一天
2004-11-20 11:11 luryfigo
<!--emo&:mad:--><img src='style_emoticons/default/mad.gif' border='0' style='vertical-align:middle' alt='mad.gif' /><!--endemo--> 小弟刚从sybase转向DB2,在sybase中我建表的脚本一般是:<br />if exists (select * from sysobjects where name = &#39;testtab&#39;)<br />     drop table testtab<br />go<br /><br />而在DB2中如下书写:<br />if exists (select * from syscat.tables where tabname = &#39;testtab&#39;)<br />then<br />      &quot;drop table testtab;&quot;<br />end if;<br /><br />死活报错!!!!<br /><br />请各位老大瞧一瞧看这个语句是否有什么毛病??<br /><br />错误信息如下:<br />DB21034E  The command was processed as an SQL statement because it was not a<br />valid Command Line Processor command.  During SQL processing it returned:<br />SQL0104N  An unexpected token &quot;if exists ( select *&quot; was found following<br />&quot;BEGIN-OF-STATEMENT&quot;.  Expected tokens may include:  &quot;&lt;space&gt;&quot;.<br />SQLSTATE=42601

2004-11-20 13:09 larryh
错误信息

2004-11-21 14:01 thrips
db2 的脚本能支持结构化编程吗?<br />把它改成一个shell,然后调用db2 &quot; ...&quot; 应该可以吧。

2004-11-21 14:30 luryfigo
我试过将该SQL写到一个文件,然后在命令行下调用db2 -tvf 1.sql,但错误依旧!我查过DB28.1的帮助,应该可以使用if的。

2004-11-21 16:00 thrips
不过,你得sql出错信息就是说 if 不对啊。

2004-11-26 08:54 燕狂徒
建议你在图形下生成教本,再看看系统自动生成的命令是怎么写的

2005-3-1 20:19 tangxb
可以使用IF,但是<br />A SQL PL block can issue most SQL statements, except for the following:<br /><br />CREATE any object other than indexes, tables, or views<br /><br />DROP any object other than indexes, tables, or views<br /><br />FLUSH EVENT MONITOR<br /><br />REFRESH TABLE<br /><br />RENAME TABLE, RENAME TABLESPACE<br /><br />REVOKE<br /><br />SET INTEGRITY<br /><br />所以在SQL PL BLOCK中是不能创建表的

2005-11-15 16:35 hjli_ada
看看这个吧。

[url]http://www.sql.ru/forum/actualthread.aspx?tid=196157[/url]

页: [1]


Powered by Discuz! Archiver 5.5.0  © 2001-2006 Comsenz Inc.