Skip to Main Content

Breadcrumb

Question and Answer

Tom Kyte

Thanks for the question, David.

Asked: August 25, 2000 - 6:42 am UTC

Last updated: September 10, 2012 - 6:13 pm UTC

Version: 8.0.5.0.0

Viewed 1000+ times

You Asked

Tom,
as part of our database tidy up I was attempting to cut the output from the SQL*Plus session on a unix terminal emulator (AttachMate Extra) to include in an email to report progress to other members of the project team. Imagine my grief, pain, horror and self loathing when – having highlighted the relevant text – I got my operating systems mixed up and attempted to use the Windows CUT command (Ctrl C) to copy the text. YUP, you guessed it :

“User requested cancel of current operation”

This was rather unfortunate as the PL/SQL anonymous block had been running for over 15 hours at this point and had gobbled up 9 hours of CPU time. This is not simply a request for some sympathy but an actual question.

Is there any way that you can configure Oracle so that the keystroke combination to cancel an operation can be changed from Ctrl C? As Attachmate runs in a Windows window you could argue that Ctrl C is a valid keystroke combination but that doesn’t get me my time back and I’d just like to try and guard against the possibility of future occurrences. I’m sure I’m not the only person who has ever fallen foul of this unfortunate juxtaposition of command interpretation.

Regards,

David.


and Tom said...

It'll depend on your terminal but typically STTY can do this (this is a unix thing, not really a SQL thing). What works for me is

stty -isig


Consider:


$ stty -isig

$ ^C
^C: Command not found

^C is now a "command" or just another character -- not a break...


$ sqlplus /

SQL*Plus: Release 8.1.5.0.0 - Production on Fri Aug 25 10...
(c) Copyright 1999 Oracle Corporation. All rights reserved.
Connected to:
Oracle8i Enterprise Edition Release 8.1.5.0.0 - Production
With the Partitioning and Java options
PL/SQL Release 8.1.5.0.0 - Production

ops$tkyte@8i> select count(*) from all_objects;
^C^C^C^C^C^C^C

COUNT(*)
----------
21302


See, I can ^C all day now and not get the ORA-1013.... I can turn it back on:

$ stty isig

$ sqlplus /

SQL*Plus: Release 8.1.5.0.0 - Production on Fri Aug 25 ...
(c) Copyright 1999 Oracle Corporation. All rights reserved.
Connected to:
Oracle8i Enterprise Edition Release 8.1.5.0.0 - Production
With the Partitioning and Java options
PL/SQL Release 8.1.5.0.0 - Production

ops$tkyte@8i> select count(*) from all_objects;
^Cselect count(*) from all_objects
*
ERROR at line 1:
ORA-01013: user requested cancel of current operation

and it works once more...


"man stty", if isig doesn't work on your platform and try some of the others...

Rating

  (7 ratings)

Is this answer out of date? If it is, please let us know via a Comment

Comments

cancel under win NT and within a script

Brigitte, January 09, 2003 - 9:34 am UTC

Hallo Tom,
how can I cancel a select as a Win NT Client?
Can I cancel a script from inside the script?
Thanks


Tom Kyte
January 09, 2003 - 9:38 am UTC

ctl-c always worked for me. assuming sqlplus of course. it is up to the tool in question to do this.

CTRL c doesn't work

Brigitte, January 10, 2003 - 8:54 am UTC

Hallo Tom,
thanks for your quick reply. Please excuse my unclear explanation.

Ctrl c cancels a script.

1. But whenn I have a select statement that's too long for me ctrl c doesn't work. I must kill sqlplus. I tested many key combinations without success. How can I cancel the statement?

2. I have scripts which must run under system. I can test within the script whether the user is system or not (select user from dual). How can I program a cancel in the script if the user is not system.

I hope you can understand me.
thanks

Tom Kyte
January 10, 2003 - 9:20 am UTC

1) contact support -- I don't do windows -- it always worked for me (ctl-c) when I did have windows a while back.

2) like this:

ops$tkyte@ORA920> whenever sqlerror exit
ops$tkyte@ORA920> variable uname varchar2(30)
ops$tkyte@ORA920> begin select user into :uname from dual where user = 'SYSTEM'; end;
  2  /
begin select user into :uname from dual where user = 'SYSTEM'; end;
*
ERROR at line 1:
ORA-01403: no data found
ORA-06512: at line 1


Disconnected from Oracle9i Enterprise Edition Release 9.2.0.2.0 - Production
With the Partitioning, OLAP and Oracle Data Mining options
JServer Release 9.2.0.2.0 - Production
[tkyte@tkyte-pc tkyte]$

unless I'm logged in as SYSTEM, script bombs. 

Brigitte, January 14, 2003 - 7:19 am UTC

Thanks, my script is now "bombproof".

How do I cancel statement programmatically?

Mikito Harakiri, June 14, 2004 - 8:22 pm UTC

I want to cancel statement gratiously, so that (partial) rowsource statistics would be in v$sql_plan_statistics. (If I just kill the session, the cursor stats would be flushed from SGA, right?).

SQL plus client can do it (with ctrl c), and another clients (like TOAD) also seem able to do it, so I wonder how do they do that.

Moreover, is there a way to cancel the statement through JDBC interface?

Tom Kyte
June 15, 2004 - 3:16 pm UTC

"gratiously", interersting :)


the stats stay in the v$ tables, even upon death of the client.


look up Statement.cancel() for jdbc.

cancel

George Joseph, May 17, 2012 - 10:41 pm UTC

Hi Tom

If there is a long running stored procedure that is submitted through sql*plus

begin
long_proc;
end;

and after some time ctl-c is fired, does oracle perform rollback on the transaction. If the proc has got a update to a large table only. does the statement rollback and locks are released?
Tom Kyte
May 18, 2012 - 2:43 am UTC

assuming the ctl-c was "caught" (it can be disabled) - assuming the ctl-c worked - yes, it would roll back the statement.

which could take longer to do then the statement had already been running (that is, if the procedure has been running an hour - it might take 2 or 3 or more hours to rollback.... rolling back is really expensive - we are optimized to commit)

How disabled CRT+C in sql*plus??

Felipe, August 27, 2012 - 1:27 pm UTC

How disable CTRL+C in sql*plus??

Regards
Tom Kyte
August 29, 2012 - 1:25 pm UTC

you'd have to disable it in your terminal program, that sends us a signal, we are not explicitly processing the ctl-c interrupt - your terminal emulator is.

or disable in your shell before running sqlplus

http://www.cyberciti.biz/faq/unix-linux-shell-scripting-disable-controlc/



My terminal is the sqlplus

Felipe, August 30, 2012 - 8:49 am UTC

Hi, the call of sqlplus is made for a batch file. I´m using win7. But in sqlplus don´t explain how command i´d use for disable ctrl+C...

Do you have any idea?? This problem is taking my sleep hours..

Regards
Tom Kyte
September 10, 2012 - 6:13 pm UTC

you would have to ask Microsoft how to disable the ctl-c interrupt in windows - this is an OS question, not a sqlplus question at all... sorry, I don't do windows.

More to Explore

VLDB

If you are new to partitioning, check out Connor McDonald's introduction series here.

VLDB

Documentation set on VLDB and Partitioning.