Oracle 使用序列号删除行
我的数据库知识非常有限,我尝试使用以下查询删除一行:
DELETE FROM table WHERE 列(选择序列.CURRVAL FROM DUAL);
这在 .sql 中用于在 Maven 中运行集成测试后清理数据库。我已经用谷歌搜索过,但仍然没有找到删除语句起作用的答案。任何帮助表示赞赏!
My DB knowledge is quite limited and I am trying to delete a row with the following query:
DELETE FROM table
WHERE column in (select sequence.CURRVAL FROM DUAL);
This is used in a .sql to clean up the database after integration tests are run in Maven. I have Googled it but still haven't found an answer for the delete statement to work. Any help is appreciated!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您不能在 DELETE 语句中使用 CURRVAL,您可以在此处阅读:http://www .orafaq.com/wiki/ORA-02287
但是由于您使用的是 SQL 脚本,因此您可以在 SQL*Plus 中这样做:
问候,
抢。
You can't use a CURRVAL in a DELETE statement, as you can read here: http://www.orafaq.com/wiki/ORA-02287
But since you are using SQL scripts, you can do it like this in SQL*Plus:
Regards,
Rob.
1) DUAL中的sequence.CURRVAL是单个离散值;使用 IN 是不合适的
2) 因为您引用的是序列。CURRVAL 您不需要使用子查询,您可以直接访问该值。
尝试:
假设序列被用作主键(某处),这将导致删除最近插入的键记录,或者如果该列是外键,则只有那些被删除的记录与最近的记录相关。
哎呀...
我已经做了足够多的删除查询,所以我没有检查我的工作。虽然我从未想过在删除中使用序列值,但我从未想过您不能这样做。
但这会起作用:
1) sequence.CURRVAL from DUAL is a single discrete value; the use of IN is inappropriate
2) because you are referencing sequence.CURRVAL you need not use a subquery, you may access this value directly.
try:
assuming the sequence is being used as a primary key (somewhere) this will result in the deletion of the most recently insert key record or if the column is a foreign key, then only those records that are related to the most recent record.
oops...
I've done enough delete queries that I didn't check my work. While I have never thought to use sequence values in a delete it never occurred to me that you couldn't do it.
this, however will work: