Oracle 10g 多个DELETE语句

发布于 2024-10-17 00:31:37 字数 422 浏览 2 评论 0原文

我正在构建一个 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

挥剑断情 2024-10-24 00:31:37

您显然有一个拼写错误,因为您在 DELETE 中将其称为 field1fields1

不过,你做得很艰难。

DELETE FROM Foo WHERE Field1 in ('bar', 'bazz');

INSERT INTO Foo (Field1, Field2) 
  SELECT 'bar', 'x' FROM System.dual UNION 
  SELECT 'bazz', 'y' FROM System.dual;

不确定 Oracle 是否需要 FROM System.dual,尽管我似乎记得它需要。 SQL Server 将只允许使用 SELECT 'bar', 'x'

You apparently have a typo, since you're calling it either field1 or fields1 in the DELETEs.

You're doing it the hard way, though.

DELETE FROM Foo WHERE Field1 in ('bar', 'bazz');

INSERT INTO Foo (Field1, Field2) 
  SELECT 'bar', 'x' FROM System.dual UNION 
  SELECT 'bazz', 'y' FROM System.dual;

Not sure if Oracle requires the FROM System.dual, although I seem to recall it did. SQL Server will allow just a SELECT 'bar', 'x' instead.

允世 2024-10-24 00:31:37

您不想这样做的任何特定原因:

insert into foo(field1, field2) values('bar', 'x');
insert into foo(field1, field2) values('bazz', 'y');

Any particular reason you don't want to:

insert into foo(field1, field2) values('bar', 'x');
insert into foo(field1, field2) values('bazz', 'y');
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文