oracle 更新前十条数据

在项目中,我们可能会遇到只更新数据库的前十条语句,这次我在项目中就遇到按条件更新表中的十条数据

下面是我的SQL:

UPDATE table SET machine='zhangsan' WHERE token IN
(SELECT t.token FROM (SELECT token FROM table where exist=0 and machine is null  order by log_time) t where rownum<=10)

在数据库能正常运行.

注:  oracle取前10行数据时,需要先内层order by 再在外层使用rownum,同一层级使用时,会先取rownum再排序,仅仅只对选中的10行数据排序,其他数据不参与排序

猜你喜欢

转载自blog.csdn.net/qq_38538004/article/details/81460091