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 = 'testtab')<br /> drop table testtab<br />go<br /><br />而在DB2中如下书写:<br />if exists (select * from syscat.tables where tabname = 'testtab')<br />then<br /> "drop table testtab;"<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 "if exists ( select *" was found following<br />"BEGIN-OF-STATEMENT". Expected tokens may include: "<space>".<br />SQLSTATE=42601
2004-11-20 13:09
larryh
错误信息
2004-11-21 14:01
thrips
db2 的脚本能支持结构化编程吗?<br />把它改成一个shell,然后调用db2 " ..." 应该可以吧。
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.