sqlplus stuck on delete query

我只是一个虾纸丫 提交于 2019-12-03 20:13:52

This might be a silly thing to find out, however, this happens most of the times.

  • You do a DML transaction in one session.
  • You are yet to COMMIT/ROLLBACK that session.
  • You open another session and do another DML.
  • You find the query keeps waiting.

A small demo of what happened in your case:

SESSION 1

SQL> delete from emp where empno = 7369;

1 row deleted.

SESSION 2

SQL> delete from emp where empno = 7369;

Session 2 keeps waiting.

Let's check why:

SQL> SELECT
  2     s.blocking_session,
  3     s.sid,
  4     s.serial#,
  5     s.seconds_in_wait
  6  FROM
  7     v$session s
  8  WHERE
  9     blocking_session IS NOT NULL;

BLOCKING_SESSION        SID    SERIAL# SECONDS_IN_WAIT
---------------- ---------- ---------- ---------------
             373        130      11069              44

SQL>

SESSION 1

SQL> rollback;

Rollback complete.

SQL>

SESSION 2

SQL> delete from emp where empno = 7369;

1 row deleted.

SQL>

Session 2 succeeded.

SQL> SELECT
  2     s.blocking_session,
  3     s.sid,
  4     s.serial#,
  5     s.seconds_in_wait
  6  FROM
  7     v$session s
  8  WHERE
  9     blocking_session IS NOT NULL;

no rows selected

SQL>

So, no more sessions waiting!

I have found what the problem was.

I was executing the anonymous block form the cmd using sqlpus while my session with the sql-developer tool was still open. I closed the connection with the db and everything worked as expected.

I suppose there were some DML in that session and I didn't commit/rollback.

Thanks to @LalitKumarB and @AlexPoole for the insights.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!