if you are using order by in sub query with delete statement like the below :
delete from tAccountScoring where riskscoring_id=1 and id in
(select * from tAccountScoring where last_update <= sysdate-3 AND rownum < 3 AND ACC_ID = 251 over (order by last_update desc))
You will have an error :
Error report:
SQL Error: ORA-00907: missing right parenthesis
00907. 00000 – “missing right parenthesis”
*Cause:
*Action:
The workaround to solve this issue is simple like the below :
delete from tAccountScoring
where riskscoring_id=1 and id in
(select ID from (select * from tAccountScoring
where last_update <= sysdate-3 AND rownum < 3 AND ACC_ID = 251 order by last_update))
Thank you
Osama Mustafa
Like this:
Like Loading...
Related
Published by Osama Mustafa
Osama Mustafa has progressive experience in Oracle Products, community. He recently served as Oracle Database Administrator.
Provide Database Implementation Solutions, High Availability Solution, Infrastructure and Storage Planning, Install, Configure, Implement and manage Oracle E-Business Suite environments. Architect, build and support highly-available Oracle EBS, Database and Fusion Middleware environments including appropriate reporting, Installs, configures, upgrades, tunes, and maintains production, development and test databases.
View all posts by Osama Mustafa
What benefit is there for the delete, to have the list in sorted order?Does it run faster?
LikeLike
Don hope you doing fine , actually No point at all , but it was challenge between developers team to tweak this and i provide them with solutions
LikeLike
there is a logical reason for the order by if you use it with “where rownum <= x" as is used here. No reason to use order by in a delete otherwise.
LikeLike
yes. sometimes is very important to delete in order.example: you have some delete from a couple of tables in order(to respect foreignKeys).for some performance issues you may conditions delete by intervals(500 rows at the time).if you don't order your delete you can have errors…..
LikeLike
yeeeeeeeeeeeeeeeeeeeee
LikeLike