Thursday, February 21, 2013

Use Order By With Delete Statement

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"
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


  1. What benefit is there for the delete, to have the list in sorted order?

    Does it run faster?

    1. 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

    2. 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.....

  2. 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.

  3. yeeeeeeeeeeeeeeeeeeeee

  4. Unable to Solve Oracle Error ORA-00907? Contact to Remote DBA Services
    The Oracle Error 00907 is regularly happened by the clients when they composing the code physically. The Oracle mistake 00907 is a sentence structure blunder which shows that there is a left bracket yet not relating right enclosure. This blunder additionally happens in a few charges, for example, CREATE TABLE, CREATE CLUSTER and INSERT. Be that as it may, with the correct direction, you can settle this issue. Ensure, we at Cognegic offer help for a wide range of Oracle blunders. Along these lines, for the snappy arrangement, you can specifically connect with Cognegic's Online Oracle DB Support and Database Administration for Oracle.
    For More Info:
    Contact Number: 1-800-450-8670
    Email Address-
    Company’s Address- 507 Copper Square Drive Bethel Connecticut (USA) 06801