获取执行计划,
第一种方式,set autotrace on
第二种方式,explain plan for
第三种方式,dbms_xplan.DISPLAY_CURSOR
alter session set STATISTICS_LEVEL = ALL;--不设置无法获得A-ROWS等信息
select sysdate from dual;--运行SQL
select * from table(dbms_xplan.DISPLAY_CURSOR(null, null, 'ALLSTATS'));
--如果SQL_ID输入NULL 则默认为之前运行的一条SQL
ALTER SESSION SET STATISTICS_LEVEL=TYPICAL;
如果通过AWR已经获取了SQL_ID,则可以直接得到执行计划
select * from table(dbms_xplan.display_awr('sql_id'));
select * from table(dbms_xplan.display_cursor('sql_id',null,'ADVANCED ALLSTATS LAST PEEKED_BINDS'));
获取SQL的一个绑定变量
SELECT t.VALUE_STRING, t.VALUE_ANYDATA
FROM v$sql_bind_capture t
WHERE sql_id = 'c1j018vt5ajdu';
SELECT snap_id, NAME, position, value_string, last_captured
, WAS_CAPTURED
FROM dba_hist_sqlbind
WHERE sql_id = 'c1j018vt5ajdu';
SELECT
dbms_sqltune.extract_bind(bind_data, 1).value_string AS a,
dbms_sqltune.extract_bind(bind_data, 2).value_string AS b
FROM wrh$_sqlstat
WHERE sql_id = 'c1j018vt5ajdu';