Sometimes I run a DELETE statement that takes a long time to complete. I have often wondered how many rows have already been deleted so that I can decide whether or not to abort the statement. Is there a way to display how many rows have been deleted while the DELETE is occurring?
Thank you.
Elie Grunhaus
egrunhaus@concentrix.com
Sure, I cannot tell you the rows but for any long running query we can get lots of good info.
I loaded a table with 1.5 million rows and then issued "delete from t". Gave it a bit of time to run and then queried (the SID of the delete was 17, found that in v$session) :
ops$tkyte@ORA817.US.ORACLE.COM> exec print_table( 'select * from v$session_longops where sid = 17 and time_remaining > 0' )
SID : 17
SERIAL# : 84
OPNAME : Table Scan
TARGET : OPS$TKYTE.T
TARGET_DESC :
SOFAR : 6415
TOTALWORK : 23601
UNITS : Blocks
START_TIME : 06-jul-2001 11:13:33
LAST_UPDATE_TIME : 06-jul-2001 11:17:56
TIME_REMAINING : 705
ELAPSED_SECONDS : 263
CONTEXT : 0
MESSAGE : Table Scan: OPS$TKYTE.T: 6415 out of 23601 Blocks done
USERNAME : OPS$TKYTE
SQL_ADDRESS : 83255028
SQL_HASH_VALUE : 4031062735
QCSID : 0
And then later:
ops$tkyte@ORA817.US.ORACLE.COM> exec print_table( 'select * from v$session_longops where sid = 17 and time_remaining > 0' )
SID : 17
SERIAL# : 84
OPNAME : Table Scan
TARGET : OPS$TKYTE.T
TARGET_DESC :
SOFAR : 9450
TOTALWORK : 23601
UNITS : Blocks
START_TIME : 06-jul-2001 11:13:33
LAST_UPDATE_TIME : 06-jul-2001 11:20:11
TIME_REMAINING : 596
ELAPSED_SECONDS : 398
CONTEXT : 0
MESSAGE : Table Scan: OPS$TKYTE.T: 9450 out of 23601 Blocks done
USERNAME : OPS$TKYTE
SQL_ADDRESS : 83255028
SQL_HASH_VALUE : 4031062735
QCSID : 0
-----------------
It shows how long the statement is running and even tries to guess as to how long it'll take. You can see in this case the number of blocks processed so far...
see
</code>
http://asktom.oracle.com/pls/asktom/f?p=100:11:::::P11_QUESTION_ID:1035431863958 <code>
for print_table if you like that output...