dbms_xplan的调用的语法类似: select * from table(dbms_xplan.display(format=>'BASIC')) 使用 TABLE() 操作符,或者 CAST 操作。
具体用法可以参考Oracle官方文档。
实际上从Oracle9i开始我们就经常使用如下方式调用dbms_xplan: Connected to: Oracle9i Enterprise Edition Release 9.2.0.4.0 - Production With the Partitioning option JServer Release 9.2.0.4.0 - Production
SQL> explain plan for 2 select count(*) from dual;
-------------------------------------------------------------------- Id Operation Name Rows Bytes Cost -------------------------------------------------------------------- 0 SELECT STATEMENT 1 SORT AGGREGATE 2 TABLE ACCESS FULL DUAL --------------------------------------------------------------------
Note: rule based optimization
10 rows selected.
utlxplp.sql脚本中正是调用了dbms_xplan:
SQL> get ?/rdbms/admin/utlxplp; 1 Rem 2 Rem $Header: utlxplp.sql 23-jan-2002.08:55:23 bdagevil Exp $ 3 Rem 4 Rem utlxplp.sql 5 Rem 6 Rem Copyright (c) 1998, 2002, Oracle Corporation. All rights reserved. 7 Rem 8 Rem NAME 9 Rem utlxplp.sql - UTiLity eXPLain Parallel plans 10 Rem 11 Rem DESCRIPTION 12 Rem script utility to display the explain plan of the last explain plan 13 Rem command. Display also Parallel Query information if the plan happens to 14 Rem run parallel 15 Rem 16 Rem NOTES 17 Rem Assume that the table PLAN_TABLE has been created. The script 18 Rem utlxplan.sql should be used to create that table 19 Rem 20 Rem With SQL*plus, it is recomended to set linesize and pagesize before 21 Rem running this script. For example: 22 Rem set linesize 130 23 Rem set pagesize 0 24 Rem 25 Rem MODIFIED (MM/DD/YY) 26 Rem bdagevil 01/23/02 - rewrite with new dbms_xplan package 27 Rem bdagevil 04/05/01 - include CPU cost 28 Rem bdagevil 02/27/01 - increase Name column 29 Rem jihuang 06/14/00 - change order by to order siblings by. 30 Rem jihuang 05/10/00 - include plan info for recursive SQL in LE row source 31 Rem bdagevil 01/05/00 - make deterministic with order-by 32 Rem bdagevil 05/07/98 - Explain plan script for parallel plans 33 Rem bdagevil 05/07/98 - Created 34 Rem 35 set markup html preformat on 36 Rem 37 Rem Use the display table function from the dbms_xplan package to display the last 38 Rem explain plan. Use default mode which will display only relevant information 39 Rem 40* select * from table(dbms_xplan.display()); 41 SQL>