|
Re: explain plan using dynaimc sql [message #127899 is a reply to message #127872] |
Thu, 14 July 2005 00:41 |
Frank Naude
Messages: 4587 Registered: April 1998
|
Senior Member |
|
|
SQL> BEGIN
2 EXECUTE IMMEDIATE 'EXPLAIN PLAN SET STATEMENT_ID=''123'' FOR SELECT * FROM DUAL';
3 END;
4 /
PL/SQL procedure successfully completed.
SQL>
SQL> SELECT timestamp, depth, operation, options, object_name
2 FROM plan_table
3 WHERE statement_id = '123';
TIMESTAMP DEPTH OPERATION OPTIONS OBJECT_NAM
--------- ---------- ------------------------------ ---------- ----------
14-JUL-05 0 SELECT STATEMENT
14-JUL-05 1 TABLE ACCESS FULL DUAL
Best regards.
Frank
|
|
|
|
Re: explain plan using dynaimc sql [message #127994 is a reply to message #127872] |
Thu, 14 July 2005 09:00 |
smartin
Messages: 1803 Registered: March 2005 Location: Jacksonville, Florida
|
Senior Member |
|
|
MYDBA@ORCL > declare
2 sql_txt varchar2(200);
3 begin
4 sql_txt := 'select * from dual';
5 execute immediate 'explain plan for ' || sql_txt;
6 end;
7 /
PL/SQL procedure successfully completed.
MYDBA@ORCL > select * from table(dbms_xplan.display);
PLAN_TABLE_OUTPUT
--------------------------------------------------------------------------------
Plan hash value: 272002086
--------------------------------------------------------------------------
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time |
--------------------------------------------------------------------------
| 0 | SELECT STATEMENT | | 1 | 2 | 2 (0)| 00:00:01 |
| 1 | TABLE ACCESS FULL| DUAL | 1 | 2 | 2 (0)| 00:00:01 |
--------------------------------------------------------------------------
8 rows selected.
MYDBA@ORCL >
|
|
|
ORA-06512 at line 4 [message #127997 is a reply to message #127872] |
Thu, 14 July 2005 09:10 |
Hina
Messages: 51 Registered: April 2004
|
Member |
|
|
Whats wrong with following statements ?
declare
mysql varchar2(30) := 'select sysdate from dual';
begin
execute immediate 'explain plan set statement_id = ''323'' for '''||mysql||''' ';
end;
|
|
|
|
Re: explain plan using dynaimc sql [message #128003 is a reply to message #127899] |
Thu, 14 July 2005 09:36 |
Hina
Messages: 51 Registered: April 2004
|
Member |
|
|
Whats wrong with following statements ?
declare
mysql varchar2(30) := 'select sysdate from dual';
begin
execute immediate 'explain plan set statement_id = ''323'' for '''||mysql||''' ';
end;
|
|
|
Re: explain plan using dynaimc sql [message #128015 is a reply to message #127872] |
Thu, 14 July 2005 10:27 |
smartin
Messages: 1803 Registered: March 2005 Location: Jacksonville, Florida
|
Senior Member |
|
|
You have too many quotes around the mysql part at the right. See how I built the string above? You don't need to surround the varchar2 variable in quotes, only constant text.
|
|
|