views:

37

answers:

1

With SQL Plus for Oracle Database, I can call

SET autotrace on

and then see Execution Plan, statistics, etc.

The problem is that I want access to information about the Execution Plan and statistics in my Java program. I typically have done something like this to execute a sql statement,

Connection connection = //INITIALIZE HERE;

Statement getColumn = connection.createStatement();

ResultSet results = getColumn.executeQuery("INSERT SQL QUERY HERE");

while(results.next()) { //view results }

Is there a way I can get the Execution Plan and Statistics? Thanks.

+3  A: 

You can query the V$SQL_PLAN table to get the explain plain. Alternatively you can query the PLAN_TABLE, you can see more details on this HERE.

Chris Taylor
or SELECT * FROM TABLE(DBMS_XPLAN.DISPLAY_CURSOR(:sql_id)). The trick is trying to work out the id of the statement you executed.
Gary