Search notes:

Oracle: Stopping the execution of (a long running) SQL statement

The following session executes an insert statement whose execution should be stopped (yet without killing the session):
SQL> create table tq84_long_running(id integer, txt varchar2(4000));
SQL> insert into tq84_long_running select level, dbms_random.string('a', 4000) from dual connect by level <= 1000000;
The execution of this statement can be stoppped like so (in another session):
select
  'alter system cancel sql ''' || ses.sid || ',' || ses.serial# || ',' || ses.sql_id || ''';' stmt,
   ses.sid,
   ses.serial#,
   ses.sql_id,
   txt.*
from
   v$session  ses                                          join
   v$sqlarea  txt on ses.sql_id = txt.sql_id
where
   txt.sql_text = q'[insert into tq84_long_running select level, dbms_random.string('a', 4000) from dual connect by level <= 1000000]';
--
-- alter system cancel sql '130,49016,31a172bxt53dr';
--
alter system cancel sql '130,49016,31a172bxt53dr';
--
-- System CANCEL altered.
The modifications of the statement are rolled back, the user gets the error message ORA-01013: user requested cancel of current operation.

Index

Fatal error: Uncaught PDOException: SQLSTATE[HY000]: General error: 8 attempt to write a readonly database in /home/httpd/vhosts/renenyffenegger.ch/php/web-request-database.php:78 Stack trace: #0 /home/httpd/vhosts/renenyffenegger.ch/php/web-request-database.php(78): PDOStatement->execute(Array) #1 /home/httpd/vhosts/renenyffenegger.ch/php/web-request-database.php(30): insert_webrequest_('/notes/developm...', 1758205952, '216.73.216.150', 'Mozilla/5.0 App...', NULL) #2 /home/httpd/vhosts/renenyffenegger.ch/httpsdocs/notes/development/databases/Oracle/SQL/statement/execution/stop(56): insert_webrequest() #3 {main} thrown in /home/httpd/vhosts/renenyffenegger.ch/php/web-request-database.php on line 78