简体   繁体   中英

How to stop a running command in oracle 11g DBMS

I used to write PL/SQL procedures in oracle dbms. Few times I would end up in situations like Infinite loop and the query continuously running I want to stop it. If I press ctrl + C whole command line gets closed.

In 11g, you need to kill the session on which that procedure is running.

You can select the sessions with below query then find out the one you want to kill/stop.

select sid, serial#, status from v$session where USERNAME='NAME';

Then kill it with below command

ALTER SYSTEM KILL SESSION 'SID,SERIAL#';

In 18c+, you can cancel the currently running statement associated with a session:

ALTER SYSTEM CANCEL SQL 'SID, SERIAL#';

Create a Windows shortcut with the target as

powershell.exe -NoExit sqlplus

or if you don't have Powershell,

cmd /k sqlplus.exe

(I'd also recommend setting "Start in" to a new folder that you just use for SQL scripts.)

Then when the sqlplus executable is interrupted and exits, you are back on the command line where you can see the error details instead of the window vanishing.

I don't know of a way to stop a Control-C terminating sqlplus.exe, but I find this does the job in most situations.

Depending on what development tool you use ( PL/SQL Developer , SQL Developer, Toad) you can probably set up a menu item to launch SQL*Plus using the current database connection instead of relying on desktop/taskbar shortcuts.

More notes on setting up SQL*Plus .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM