declare
v_cursor number;
stmt varchar2(2000);
s varchar2(40);
cursor cc1 is select voc.SQL_ID from v$open_cursor voc left join v$sql vs on voc.SQL_ID=vs.SQL_ID where voc.SID in(select sid from v$mystat) and to_char(substr(vs.SQL_FULLTEXT,1,2000)=stmt;
begin
delete from table1;
v_cursor:=dbms_sql.open_cursor;
stmt:='inset into table2 (column1,column2) values(''a'',''b'')';
dbms_sql.parse(v_cursor,stmt,dbms_sql.native);
insert into table1 select * from tables(dbms_xplan.display
open cc1;
loop
fetch cc1 into s;
exit;
end loop;
close cc1;
insert into table1 select * from(dbms_xplan.display_cursor(s,0,'ALL'));
I execute this and select from the table1
but the record in table1 is tells me:
it could also be that the plan is no longer in cursor cache(check v$sql_plan).
But if I change the stmt to update statement and execute, the record in table1
is correct.
So i want to know where can I get the analyze about the insert statement.
Best Answer
The
child_number
argument todbms_xplan.display_cursor
needs to be taken fromv$sql
as well, it's not necessarily zero. (I'm not exactly sure what influences that number, but dropping and recreatingtable2
in your example gives me a newchild_number
each time).Here's a modified version of your procedure (fixed a few typoes in what you have above):