把下面的mysql语法改为oracle; update temp_asset_table a join ( select x.id,@rownum :=@rownum + 1 AS 'row_num' from ( SELECT id from temp_asset_table where BATCH_ID=batchId and ASSET_TYPE = '100' order by row_num desc ) x,(SELECT @rownum := v_max_id_100) temp ) d on a.id=d.id set a.ASSET_NUMBER= d.row_num where a.ASSET_TYPE = '100' and a.BATCH_ID=batchId;
时间: 2024-04-27 20:19:27 浏览: 141
总结mysql和oracle的语法区别.docx
在 Oracle 中,可以使用以下语法来执行相同的操作:
```
UPDATE (
SELECT a.ASSET_NUMBER, ROW_NUMBER() OVER (ORDER BY x.row_num DESC) AS row_num
FROM temp_asset_table a
JOIN (
SELECT id, ROW_NUMBER() OVER (ORDER BY row_num DESC) AS row_num
FROM (
SELECT id, rownum AS row_num
FROM (
SELECT id, ROWNUM AS rownum
FROM temp_asset_table
WHERE BATCH_ID = batchId AND ASSET_TYPE = '100'
ORDER BY row_num DESC
)
)
) x ON a.id = x.id
WHERE a.ASSET_TYPE = '100' AND a.BATCH_ID = batchId
) SET ASSET_NUMBER = row_num;
```
其中,使用了 `ROW_NUMBER()` 函数来生成每条记录的行号,两个子查询分别用于生成 `id` 和 `row_num`,最终通过 `JOIN` 进行匹配,并在外层使用 `SET` 子句来更新 `ASSET_NUMBER` 字段。需要注意的是,在 Oracle 中,不能在 `JOIN` 子句中使用 `@rownum` 变量。
阅读全文