Oracle 10g 多个DELETE语句
我正在构建一个 dml 文件,该文件首先删除表中可能存在的记录,然后插入记录。 示例:
DELETE from foo where field1='bar';
DELETE from foo where fields1='bazz';
INSERT ALL
INTO foo(field1, field2) values ('bar', 'x')
INTO foo(field1, field2) values ('bazz', 'y')
SELECT * from DUAL;
当我单独运行插入语句时,它运行良好。当我运行删除时,仅运行最后一个删除。
另外,似乎有必要用select结束多次插入,是这样吗?如果是这样,为什么有必要? 过去,当使用 MySQL 时,我只需列出多个删除和插入语句,所有语句都单独以分号结尾,并且可以正常运行。
I'm building a dml file that first deletes records that may be in the table, then inserts records.
Example:
DELETE from foo where field1='bar';
DELETE from foo where fields1='bazz';
INSERT ALL
INTO foo(field1, field2) values ('bar', 'x')
INTO foo(field1, field2) values ('bazz', 'y')
SELECT * from DUAL;
When I run the insert statement by itself, it runs fine. When I run the deletes, only the last delete runs.
Also, it seems to be necessary to end the multiple insert with the select, is that so? If so, why is that necessary?
In the past, when using MySQL, I could just list multiple delete and insert statements, all individually ending with a semicolon, and it would run fine.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您显然有一个拼写错误,因为您在 DELETE 中将其称为
field1
或fields1
。不过,你做得很艰难。
不确定 Oracle 是否需要
FROM System.dual
,尽管我似乎记得它需要。 SQL Server 将只允许使用SELECT 'bar', 'x'
。You apparently have a typo, since you're calling it either
field1
orfields1
in the DELETEs.You're doing it the hard way, though.
Not sure if Oracle requires the
FROM System.dual
, although I seem to recall it did. SQL Server will allow just aSELECT 'bar', 'x'
instead.您不想这样做的任何特定原因:
Any particular reason you don't want to: