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 considered as one of the leaders in Cloud technology, DevOps and database in the Middle-East. I have more than ten years of experience within the industry. moreover, certfied 4x AWS , 4x Azure and 6x OCI, have also obtained database certifications for multiple providers.
In addition to having experience with Oracle database and Oracle products, such as middle-ware, OID, OAM and OIM, I have gained substantial knowledge with different databases.
Currently, I am architecting and implementing Cloud and DevOps. On top of that, I'm providing solutions for companies that allow them to implement the solutions and to follow the best practices.
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