Oracle WITH DELETE 按行号
我正在编写一个按查看日期删除旧行的过程:
;WITH pv AS (
SELECT
RN = ROW_NUMBER() OVER (ORDER BY viewed DESC)
FROM
previouslyViewed
WHERE
userId = @userId
)
DELETE FROM pv WHERE RN >= 10
这适用于 SQL Server,但不适用于 Oracle。
Oracle 不支持WITH DELETE 组合。它也不支持 DELETE ORDER BY 组合(理论上可以与 rownum 一起使用以获得相同的结果)。我尝试使用 rownum 创建一个临时视图并从中删除,但出现 Oracle 错误 - 似乎在使用 rownum 时无法从视图中删除。
有人有任何指点吗?
I am writing a procedure which removes old rows by their viewed date:
;WITH pv AS (
SELECT
RN = ROW_NUMBER() OVER (ORDER BY viewed DESC)
FROM
previouslyViewed
WHERE
userId = @userId
)
DELETE FROM pv WHERE RN >= 10
This works in SQL Server, but not in Oracle.
Oracle doesn't support the WITH DELETE combination. Nor does it support the DELETE ORDER BY combination (which could theoretically be used with rownum to achieve the same result). I have tried to create a temporary view with the rownum and delete from that, but I get an Oracle error - seemingly you cannot delete from a view when rownum is used.
Does anyone have any pointers?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以这样做:(
将
pkcol
更改为表的主键列)You could do this instead:
(changing
pkcol
to the primary key column(s) of the table)