Sqlplus - autotrace
Hi,
I need to insert into Oracle table the execution plan as well as statistics of the statements with autotrace for sqlplus session.
for example:
SQL> set autotrace on;
SQL> select count(*)
2 from dual;
count(*)
1
Exrcution Plan
Plan hash value: 1388734953
| Id | Operation | Name | Rows | Cost (%CPU)| Time |
| 0 | SELECT STATEMENT | | 1 | 2 (0)| 00:00:01 |
| 1 | FAST DUAL | | 1 | 2 (0)| 00:00:01 |
Statistics
1 recursive calls
0 db block gets
0 consistent gets
0 physical reads
0 redo size
425 bytes sent via SQL*Net to client
416 bytes received via SQL*Net from client
2 SQL*Net roundtrips to/from client
0 sorts (memory)
0 sorts (disk)
1 rows processed Can I insert this output into Oracle table?
I need to trace many statements for the current session and save them in a table.
Thanks in advance!
Raf Royal wrote:
I need to find the following values for the sqlplus session set autotrace on;
ID
OPERATION
NAME
ROWS
COST (%CPU)
TIME
STATISTICS
I'd like to create a table with these columns and insert these values or I'd like to find some system table that gives me the data.query one or more of the views below
07:43:37 SQL> select view_name from dba_views where view_name like '%PLAN%';
VIEW_NAME
V_$ADVISOR_CURRENT_SQLPLAN
V_$RSRC_PLAN
V_$RSRC_PLAN_CPU_MTH
V_$RSRC_PLAN_HISTORY
DBA_ADVISOR_SQLPLANS
V_$SQLAREA_PLAN_HASH
V_$SQLSTATS_PLAN_HASH
V_$SQL_PLAN
V_$SQL_PLAN_MONITOR
V_$SQL_PLAN_STATISTICS
V_$SQL_PLAN_STATISTICS_ALL
VIEW_NAME
GV_$RSRC_PLAN
GV_$RSRC_PLAN_CPU_MTH
GV_$RSRC_PLAN_HISTORY
GV_$SQLAREA_PLAN_HASH
GV_$SQLSTATS_PLAN_HASH
USER_ADVISOR_SQLPLANS
USER_SQLSET_PLANS
USER_SQLTUNE_PLANS
USER_SQLTUNE_RATIONALE_PLAN
DBA_HIST_PLAN_OPERATION_NAME
DBA_HIST_PLAN_OPTION_NAME
VIEW_NAME
DBA_HIST_RSRC_PLAN
DBA_HIST_SQL_PLAN
DBA_RSRC_PLANS
DBA_RSRC_PLAN_DIRECTIVES
DBA_SQLSET_PLANS
DBA_SQLTUNE_PLANS
DBA_SQLTUNE_RATIONALE_PLAN
DBA_SQL_PLAN_BASELINES
KU$_RMGR_PLAN_DIRECT_VIEW
KU$_RMGR_PLAN_VIEW
ALL_SQLSET_PLANS
VIEW_NAME
GV_$SQL_PLAN
GV_$SQL_PLAN_MONITOR
GV_$SQL_PLAN_STATISTICS
GV_$SQL_PLAN_STATISTICS_ALL
ALL_EXPFIL_PREDTAB_PLAN
USER_EXPFIL_PREDTAB_PLAN
ALL$AW_CUBE_AGG_PLANS
MGMT_JOB$EXECPLAN
GV_$ADVISOR_CURRENT_SQLPLAN
42 rows selected.
07:44:06 SQL>
Similar Messages
-
Why is my sql running parallel ?
Hi,
NOTE: first, I thought sql developer tool is causing this and I opened a thread on that category, thanks to @rp0428's warnings and advises, I realized that something else is happening. so reopened this thread in that category, I also need an admin to delete other one:
https://forums.oracle.com/forums/thread.jspa?threadID=2420515&tstart=0
thanks.
so my problem is:
I have table partitioned by range (no subpartition) on a DATE column per months. It has almost 100 partitions. I run a query on that table based on partition column:
select *
from hareket_table
where islem_tar between to_date('01/05/2012', 'dd/mm/yyyy') and to_date('14/07/2012', 'dd/mm/yyyy') -- ISLEM_TAR is my partition column.so, when I run this query from sql developer, query works parallel. I didnt just get execution plan via sql developer interface, first I used "EXPLAIN PLAN FOR" statement (which I always do, I dont use developer tools interfaces generally) then used developer interface (just to be sure) but I didnt satisfied and then I run the query and and get real execution plan via:
select * from table(dbms_xplan.display_cursor(sql_id => '7cm8cz0k1y0zc', cursor_child_info =>0, format=>'OUTLINE'));and the same execution plan again with PARALLELISM. so INDEXES and TABLE has no parallelism (DEGREE column in DBA_INDEXES and DBA_TABLES is set to 1).
as I know, if I'm wrong please correct me, there is no reason to oracle run this query as parallel (I also did not give any hint). so I worried and run the same steps in "plsql developer" and query runs noparallel (inteface, explain plan for, dbms_xplan.display_cursor). sqlplus autotrace was the same( just autotrace, didnt try others dbms_xplan etc.) Based on that, I decided sql developer is causing to this (*edit: but I was wrong TOAD did same thing*).
so I focused on sql developer and I disabled parallel query using:
alter session disable parallel query;then run the statement again and there were no Parallelism (expectedly).
so looked for execution plans:
I run query twice. one with normal, one with session disabled parallel query. and look for executed execution plan for both. (child 0 and 1)
-- WHEN PARALLEL QUERY IS ENABLE, SESSION DEFAULT
-- JUST CONNECTED TO DATABASE
select * from table(dbms_xplan.display_cursor('7cm8cz0k1y0zc', 0, 'OUTLINE'));
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time | Pstart| Pstop | TQ |IN-OUT| PQ Distrib |
| 0 | SELECT STATEMENT | | | | 2025 (100)| | | | | | |
| 1 | PX COORDINATOR | | | | | | | | | | |
| 2 | PX SEND QC (RANDOM)| :TQ10000 | 7910K| 1267M| 2025 (2)| 00:00:01 | | | Q1,00 | P->S | QC (RAND) |
| 3 | PX BLOCK ITERATOR | | 7910K| 1267M| 2025 (2)| 00:00:01 | 90 | 92 | Q1,00 | PCWC | |
|* 4 | TABLE ACCESS FULL| HAREKET_TABLE | 7910K| 1267M| 2025 (2)| 00:00:01 | 90 | 92 | Q1,00 | PCWP | |
Outline Data
/*+
BEGIN_OUTLINE_DATA
IGNORE_OPTIM_EMBEDDED_HINTS
OPTIMIZER_FEATURES_ENABLE('11.2.0.2')
DB_VERSION('11.2.0.2')
OPT_PARAM('query_rewrite_enabled' 'false')
OPT_PARAM('optimizer_index_cost_adj' 30)
OPT_PARAM('optimizer_index_caching' 50)
OPT_PARAM('optimizer_dynamic_sampling' 6)
ALL_ROWS
OUTLINE_LEAF(@"SEL$1")
FULL(@"SEL$1" "HAREKET_TABLE"@"SEL$1")
END_OUTLINE_DATA
Predicate Information (identified by operation id):
4 - access(:Z>=:Z AND :Z<=:Z)
filter(("ISLEM_TAR">=TO_DATE(' 2012-05-14 00:00:00', 'syyyy-mm-dd hh24:mi:ss') AND "ISLEM_TAR"<=TO_DATE('
2012-07-14 00:00:00', 'syyyy-mm-dd hh24:mi:ss')))
--WHEN DISABLED PARALLEL QUERY
--AFTER CONNECTED, EXECUTED "ALTER SESSION DISABLE PARALLEL QUERY"
select * from table(dbms_xplan.display_cursor('7cm8cz0k1y0zc', 1, 'OUTLINE'));
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time | Pstart| Pstop |
| 0 | SELECT STATEMENT | | | | 36504 (100)| | | |
| 1 | PARTITION RANGE ITERATOR| | 7910K| 1267M| 36504 (2)| 00:00:04 | 90 | 92 |
|* 2 | TABLE ACCESS FULL | HAREKET_TABLE | 7910K| 1267M| 36504 (2)| 00:00:04 | 90 | 92 |
Outline Data
/*+
BEGIN_OUTLINE_DATA
IGNORE_OPTIM_EMBEDDED_HINTS
OPTIMIZER_FEATURES_ENABLE('11.2.0.2')
DB_VERSION('11.2.0.2')
OPT_PARAM('query_rewrite_enabled' 'false')
OPT_PARAM('optimizer_index_cost_adj' 30)
OPT_PARAM('optimizer_index_caching' 50)
ALL_ROWS
OUTLINE_LEAF(@"SEL$1")
FULL(@"SEL$1" "HAREKET_TABLE"@"SEL$1")
END_OUTLINE_DATA
Predicate Information (identified by operation id):
2 - filter(("ISLEM_TAR">=TO_DATE(' 2012-05-14 00:00:00', 'syyyy-mm-dd hh24:mi:ss') AND
"ISLEM_TAR"<=TO_DATE(' 2012-07-14 00:00:00', 'syyyy-mm-dd hh24:mi:ss')))
as you can see, when I've just connected to database (no any statements run) OPT_PARAM('optimizer_dynamic_sampling' 6) is in my stats.
when I disable parallel query on the session, this is not in stats...
value of optimizer_dynamic_sampling is 2 in DB. so why is that query runs parallel ? I don't want that.
thanks for answers>
NOTE: first, I thought sql developer tool is causing this and I opened a thread on that category, thanks to @rp0428's warnings and advises, I realized that something else is happening. so reopened this thread in that category, I also need an admin to delete other one:
https://forums.oracle.com/forums/thread.jspa?threadID=2420515&tstart=0
as you can see, when I've just connected to database (no any statements run) OPT_PARAM('optimizer_dynamic_sampling' 6) is in my stats.
when I disable parallel query on the session, this is not in stats...
value of optimizer_dynamic_sampling is 2 in DB. so why is that query runs parallel ? I don't want that.
>
I answered this question in that other thread, that is now gone. I pointed you to, and quoted from, a blog that tells you EXACTLY why that is happening. And I also gave you a link to an article by Oracle ACE and noted author Jonathan Lewis. You either didn't see the links or didn't read them.
Maria Colgan is an Oracle developer and a member of the optimizer developer team. She has many article on the net that talk about the optimizer, how it works, how to use it.
The one I pointed you to, and quoted from, is titled 'Dynamic sampling and its impact on the Optimizer'
https://blogs.oracle.com/optimizer/entry/dynamic_sampling_and_its_impact_on_the_optimizer
>
For serial SQL statements the dynamic sampling level will depend on the value of the OPTIMIZER_DYNAMIC_SAMPLING parameter and will not be triggered automatically by the optimizer. The reason for this is that serial statements are typically short running and any overhead at compile time could have a huge impact on their performance. Where as we expect parallel statements to be more resource intensive, so the additional overhead at compile time is worth it to ensure we can be best execution plan.
In our original example the SQL statement is serial, which is why we needed to manual set the value for OPTIMIZER_DYNAMIC_SAMPLING parameter. If we were to issue a similar style of query against a larger table that had the parallel attribute set we can see the dynamic sampling kicking in.
You should also note that setting OPTIMIZER_FEATURES_ENABLE to 9.2.0 or earlier will disable dynamic sampling all together.
When should you use dynamic sampling? DS is typically recommended when you know you are getting a bad execution plan due to complex predicates. However, you should try and use an alter session statement to set the value for OPTIMIZER_DYNAMIC_SAMPLING parameter as it can be extremely difficult to come up with a system-wide setting.
When is it not a good idea to use dynamic sampling? If the queries compile times need to be as fast as possible, for example, unrepeated OLTP queries where you can't amortize the additional cost of compilation over many executions.
>
If you read the article and particularly the first two paragraphs above Maria expalins why dynamic sampling was used in your case. And for a table with as many partitions as yours Oracle chose to use sampling level six (256 blocks, see article); a level of two would only sample 64 blocks and you have 90+ partitions. Oracle needs a good sample of partitions.
The Jonathan Lewis article is titled 'Dynamic Sampling'
http://jonathanlewis.wordpress.com/2010/02/23/dynamic-sampling/
This article can also shed light on sampling as he shows how it appears that sampling isn't being used and then shows that it actually is
>
We can see that we have statistics.
We can see that we delete 9002 rows
We can see that we have 998 rows left
We can see that the plan (and especially the cardinality of the full tablescan) doesn’t change even though we included a table-level hint to do dynamic sampling.
Moreoever – we can’t see the usual note that you get when the plan is dependent on a dynamic sample (” – dynamic sampling used for this statement”).
It looks as if dynamic sampling hasn’t happened.
However, I “know” that dynamic sampling is supposed to happen unconditionally when you use a table-level hint – so I’m not going to stop at this point. There are cases where you just have to move on from explain plan (or autotrace) and look at the 10053 trace.
So the optimizer did do dynamic sampling, but then decided that it wasn’t going to use the results for this query. -
Hello,
I am new to sql tuning.
I want help in learning more on this.
How do we display the output of sql_trace.
Initially I did,
alter session set sql_trace = true;
then
select * from tab;
where do i see the output of sql_trace.
Thanks,
Help is appreciated.Hi,
the tracefile is written into the udump directory. If you didn't change it it's located at $ORACLE_BASE/admin/$ORACLE_SID/udump
Use tkprof to format the trace file to a more readable format:
tkprof trace_file.trc output.txtAlso raw Tracefiles have much more information, a tkprof output may be more suitable for a beginner.
You can also use sqlplus autotrace
dimitri@VDB> set autotrace traceonly
dimitri@VDB> select * from dual;
Execution Plan
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 |
Statistics
1 recursive calls
0 db block gets
3 consistent gets
0 physical reads
0 redo size
511 bytes sent via SQL*Net to client
469 bytes received via SQL*Net from client
2 SQL*Net roundtrips to/from client
0 sorts (memory)
0 sorts (disk)
1 rows processedTo use autotrace you have to execute $ORACLE_HOME/sqlplus/admin/plustrce.sql as SYS and grant the new Role PLUSTRACE to your normal User.
A few usfull links for you:
http://www.hotsos.com
http://www.oracle.com/pls/db102/to_toc?pathname=server.102%2Fb14211%2Ftoc.htm&remark=portal+%28Books%29
Dim -
View Objects , whereclauseparam and PERFORMANCE in JSP
We experience that using the method setWhereClauseParam gives VERY BAD performance in our JSP applications.
According to JDev team and others, "best practice" is to use setWhereClauseParam(s), so we wonder why the performance degrade significantly compared to a simpler approach (=define the whereclause when the datasource is created). To avoid the shared pool to grow we were tempted to use the recommended best-practice-parameter-binding approach, but due to performance we had to drop that idea.
Our JSP (pseudo) code look like this:
<jbo:ApplicationModule id="am" .......
<jbo:DataSource id="ds" appid="am" viewobject="ourView" rangesize="0"/>
<%
ViewObject ourVo= ds.getApplicationModule().FindViewObject("ourView");
ourVo.setWhereClauseParam(0, 'xxx');
ourVo.setWhereClauseParam(1, 'yyy');
%>
<jbo:RowsetIterate datasource="ds" >
bla bla bla ..
</jbo:RowsetIterate>
THIS IS SLOW !! ..... compared to:
<jbo:ApplicationModule id="am" .......
<% String clause = "Col1 = 'xxx' and Col2 = 'yyy' %>
<jbo:DataSource id="ds" appid="am" whereclause='<%= clause %>' viewobject="LabelHeadersView" rangesize="0"/>
<jbo:RowsetIterate datasource="ds" >
bla bla bla ..
</jbo:RowsetIterate>
We get the same results but the last method is times 100 faster ??
Any ideas are appreciated .
Thanks, JensOK. I believe I now know what the culprit it. It is your use of the where clause fragment:
(pdk_files_id = ? OR ? IS NULL)
Here's how I arrived at this (while at the same time ruling BC4J out of the picture as a potential cause of the problem).
I following the steps below:
[list]
[*]Connected as SCOTT in SQLPlus, I create the table:
CREATE TABLE files( pdk_files_id NUMBER PRIMARY KEY, name VARCHAR2(20));
[*]I insert one row into the new files table:
INSERT INTO files values (1111, 'SteveTest');
COMMIT;
[*]I connect as SYSTEM, an run the script ORACLE_HOME/sqlplus/admin/plustrce.sql to create the SQL*Plus PLUSTRACE role so that SCOTT will be able to use the SQLPlus AutoTrace feature
[*]As SYSTEM still, I ran the command: GRANT PLUSTRACE TO SCOTT
This gives SCOTT the privilege to use the SQL*Plus autotrace command
[*]I connect as SCOTT, and run the script ORACLE_HOME/rdbms/admin/utlxplan.sql
this created the plan table in my SCOTT schema needed to run the autotrace feature
[*]In SQLPLUS, still connected as SCOTT I issue the command:
SET AUTOTRACE ON EXPLAIN
[*]Then I do the following to create a SQL*Plus bind variable
VAR v VARCHAR2(20)
[*]And then do the following to set its value at the SQL*Plus command prompt:
EXEC :v := '1111';
[list]
Finally, I try some different queries and look at the autotrace output:
SQL> select * from files where pdk_files_id = 1111
2 /
PDK_FILES_ID NAME
1111 SteveTest
Execution Plan
0 SELECT STATEMENT Optimizer=CHOOSE
1 0 TABLE ACCESS (BY INDEX ROWID) OF 'FILES'
2 1 INDEX (UNIQUE SCAN) OF 'SYS_C003006' (UNIQUE).
This shows that using the literal value 1111 uses the index.
SQL> select * from files where (pdk_files_id = 1111 or 1111 is null)
2 /
PDK_FILES_ID NAME
1111 SteveTest
Execution Plan
0 SELECT STATEMENT Optimizer=CHOOSE
1 0 TABLE ACCESS (BY INDEX ROWID) OF 'FILES'
2 1 INDEX (UNIQUE SCAN) OF 'SYS_C003006' (UNIQUE).
This shows that using the literal values together with the OR clause, still uses the index.
SQL> select * from files where (pdk_files_id = :v)
2 /
PDK_FILES_ID NAME
1111 SteveTest
Execution Plan
0 SELECT STATEMENT Optimizer=CHOOSE
1 0 TABLE ACCESS (BY INDEX ROWID) OF 'FILES'
2 1 INDEX (UNIQUE SCAN) OF 'SYS_C003006' (UNIQUE).
Using my ":v" bind variable I defined, it uses the index, too, even though the type of the bind variable is VARCHAR2 and the type of the PDK_FILES_ID column is NUMBER. This is because this is a simple enough case for the database to do automatic type coersion to convert my string value '1111' for the bind variable into the number value 1111 and then use that for the index lookup.
HOWEVER, when I try the case that simulates what you are doing in BC4J, which is using a bind variable together with the OR clause for the NULL test, we see...
SQL> select * from files where (pdk_files_id = :v OR :v IS NULL)
2 /
PDK_FILES_ID NAME
1111 SteveTest
Execution Plan
0 SELECT STATEMENT Optimizer=CHOOSE
1 0 TABLE ACCESS (FULL) OF 'FILES'.
So in this case, the database DOES NOT use the index, and hence explains why your query is slow.
I believe the database works this way because when it hard-parses the SQL statement, it is at this time that it determines the query plan for the SQL statement. The plan needs to remain stable since the same plan will be cached and reused for all uses of the same parsed SQL statement, so the plan cannot be conditional based on the values of the bind variables. Since it cannot decide without knowing the value of the bind variable, it apparently disqualifies your index from being used.
Even introducing an optimizer hint only improves the problem a little. I tried this example:
SQL> select /*+INDEX (files sys_c003006)*/ *
2 from files where (pdk_files_id = :v or :v IS NULL)
3 /
PDK_FILES_ID NAME
1111 SteveTest
Execution Plan
0 SELECT STATEMENT Optimizer=CHOOSE (Cost=826 Card=5 Bytes=125)
1 0 TABLE ACCESS (BY INDEX ROWID) OF 'FILES' (Cost=826 Card=5 Bytes=125)
2 1 INDEX (FULL SCAN) OF 'SYS_C003006' (UNIQUE) (Cost=26 Card=82).
In this case it still has to fully scan the index where above it was able to do a unique scan.
MORAL OF THE STORY:The tiny cost of having two different View Objects in your application, one to use when you want to find by PDK_FILES_ID, and one to use when you want to find by your other key criteria, is well worth the performance improvement that can be had by using bind variables and using them in a way that the database will use the index.
As Tom Kyte says in his excellent book Expert One on One: Oracle in a passage that made me laugh:
"If I were going to write a book about building Oracle applications that do not scale, "Don't Use Bind Variables" would be the first and last chapter." :-)
So, by using a few design-time-created view objects that uses bind variables and avoid the use of the (COL = ? OR ? IS NULL) construct, you get the following benefits:
[list]
[*]The database doesn't have to hard-parse your SQL statement each time you execute it (which it does if you keep sending queries that have literal values in the SQL statement, making each query different as far as the SGA is concerned)
[*]The indexes will get used correctly as we saw above
[*]Your code actually might be clearer, since you can name one of your view objects "FindFileById" and the other one "FindFileByName", or what have you
[list]
Hope this helps. -
Sqlplus – spool data to a flat file
Hi,
Does any oracle expert here know why the sqlplus command could not spool all the data into a flat file at one time.
I have tried below command. It seems like every time I will get different file size :(
a) sqlplus -s $dbUser/$dbPass@$dbName <<EOF|gzip -c > ${TEMP_FILE_PATH}/${extract_file_prefix}.dat.Z
b) sqlplus -s $dbUser/$dbPass@$dbName <<EOF>> spool.log
set feedback off
set trims on
set trim on
set feedback off
set linesize 4000
set pagesize 0
whenever sqlerror exit 173;
spool ${extract_file_prefix}.datFor me, this is working. What exactly are you getting and what exactly are you expecting?
(t352104@svlipari[GEN]:/lem) $ cat test.ksh
#!/bin/ksh
TEMP_FILE_PATH=`pwd`
extract_file_prefix=emp
dbUser=t352104
dbPass=t352104
dbName=gen_dev
dataFile=${TEMP_FILE_PATH}/${extract_file_prefix}.dat
sqlplus -s $dbUser/$dbPass@$dbName <<EOF > $dataFile
set trims on
set trim on
set tab off
set linesize 7000
SET HEAD off AUTOTRACE OFF FEEDBACK off VERIFY off ECHO off SERVEROUTPUT off term off;
whenever sqlerror exit 173;
SELECT *
FROM emp ;
exit
EOF
(t352104@svlipari[GEN]:/lem) $ ./test.ksh
(t352104@svlipari[GEN]:/lem) $ echo $?
0
(t352104@svlipari[GEN]:/lem) $ cat emp.dat
7369 SMITH CLERK 7902 17-DEC-80 800 20
7499 ALLEN SALESMAN 7698 20-FEB-81 1600 300 30
7521 WARD SALESMAN 7698 22-FEB-81 1250 500 30
7566 JONES MANAGER 7839 02-APR-81 2975 20
7654 MARTIN SALESMAN 7698 28-SEP-81 1250 1400 30
7698 BLAKE MANAGER 7839 01-MAY-81 2850 30
7782 CLARK MANAGER 7839 09-JUN-81 2450 10
7788 SCOTT ANALYST 7566 09-DEC-82 3000 20
7839 KING PRESIDENT 17-NOV-81 5000 10
7844 TURNER SALESMAN 7698 08-SEP-81 1500 0 30
7876 ADAMS CLERK 7788 12-JAN-83 1100 20
7900 JAMES CLERK 7698 03-DEC-81 950 30
7902 FORD ANALYST 7566 03-DEC-81 3000 20
7934 MILLER CLERK 7782 23-JAN-82 1300 10
(t352104@svlipari[GEN]:/lem) $ -
Getting Autotrace of a sql on forms6i screen
Hi,
The sql scripts from forms 6i against 10G database are running fine when we click on a forms button..
But why this Ora-00904 error comes along with the scripts results on forms 6i screen. You can see it below
Below you find the complete code which I am using on WBPT.
If you have suggestion about improving this code please let me know. I am a single
person whoc is doing this.
Your suggestion will be appreciated.
Thanks
Insbor
Following result was generate on forms screen with ORA-00904: "POSITION" error
Forms Screen
ERROR:
ORA-00904: "POSITION": invalid identifier
Error enabling EXPLAIN report
Statistics
0 recursive calls
0 db block gets
8646 consistent gets
45 physical reads
0 redo size
775383 bytes sent via SQL*Net to client
356955 bytes received via SQL*Net from client
3214 SQL*Net roundtrips to/from client
0 sorts (memory)
0 sorts (disk)
48188 rows processed
My code on forms button wbpt:
Declare
in_file Text_IO.File_Type;
linebuf VARCHAR2(1800);
output varchar2(1000);
/* New Parameter define for form_ddl */
v_create_table_sql varchar2(2000);
v_test number;
un VARCHAR2(80);
pw VARCHAR2(80);
cn VARCHAR2(80);
BEGIN
Get_Connect_Info(un,pw,cn);
v_create_table_sql := 'Create table plan_table (STATEMENT_ID varchar2(30),'||
'PLAN_ID NUMBER ,'|| 'TIMESTAMP DATE ,'|| 'remarks varchar2(80),'||
'operation varchar2(30),'||'options varchar2(30),'||'object_owner varchar2(30),'
||'object_name varchar2(30),'||'optimizer varchar2(255),'||'search_columns number,'
||'id number(38),' ||'parent_id number(38),'
||'cost number(38),'||'cardinality number(38))';
select count(*) into v_test
from all_objects
where object_name = 'PLAN_TABLE'
and owner in (user,'PUBLIC');
if v_test = 0 then
forms_ddl(v_create_table_sql);
Forms_DDL('grant select on plan_table to public');
Forms_DDL('create public synonym plan_table for plan_table');
Forms_DDL('create role plustrace');
Forms_DDL('grant select on v_$sesstat to plustrace');
Forms_DDL('grant select on v_$statname to plustrace') ;
Forms_DDL('grant select on v_$session to plustrace') ;
Forms_DDL('grant plustrace to dba with admin option') ;
Forms_DDL('grant plustrace to public') ;
end if;
if v_test <> 0 then
forms_ddl('delete from plan_table ');
Forms_DDL ('commit');
end if;
IF NOT Form_Success THEN
Message ('Table Creation Failed');
ELSE
null;
-- Message ('Table Created');
END IF;
--Old Work
in_file := Text_IO.Fopen('c:\explain_plus\misc\create_ascript3.bat', 'w');
Text_IO.Put_Line(in_file, linebuf);
Text_IO.put_line(in_file,' ');
Text_IO.put_line(in_file,' @echo off');
Text_IO.put_line(in_file,' ');
Text_IO.put_line(in_file,' set connect_db=%1 ' );
Text_IO.put_line(in_file,' ');
Text_IO.put_line(in_file,' if exist connect_DB == goto usage ');
Text_IO.put_line(in_file,' ');
Text_IO.put_line(in_file,' echo " sqlplus %connect_db% @c:\explain_plus\misc\auto_trace.txt" > c:\explain_plus\misc\runauto.txt ');
Text_IO.put_line(in_file,' ');
Text_IO.put_line(in_file,' :end ');
Text_IO.put_line(in_file,' ');
Text_IO.put_line(in_file,' set connect_db= ');
Text_IO.put_line(in_file,' ');
Text_IO.FCLOSE(in_file);
in_file := Text_IO.Fopen('c:\explain_plus\misc\create_ascript4.bat', 'w');
Text_IO.Put_Line(in_file, linebuf);
Text_IO.put_line(in_file,' ');
Text_IO.put_line(in_file,' @echo off');
Text_IO.put_line(in_file,' ');
Text_IO.put_line(in_file,' set connect_db=%1 ' );
Text_IO.put_line(in_file,' ');
Text_IO.put_line(in_file,' if exist connect_DB == goto usage ');
Text_IO.put_line(in_file,' ');
Text_IO.put_line(in_file,' echo " sqlplus %connect_db% @c:\explain_plus\misc\raw_Explain.txt" > c:\explain_plus\misc\run_explain.txt ');
Text_IO.put_line(in_file,' ');
Text_IO.put_line(in_file,' :end ');
Text_IO.put_line(in_file,' ');
Text_IO.put_line(in_file,' set connect_db= ');
Text_IO.put_line(in_file,' ');
Text_IO.FCLOSE(in_file);
in_file := Text_IO.Fopen('c:\explain_plus\misc\del_all.bat', 'w');
Text_IO.Put_Line(in_file, linebuf);
Text_IO.put_line(in_file,' ');
Text_IO.put_line(in_file,' @echo off');
Text_IO.put_line(in_file,' ');
Text_IO.put_line(in_file,' del /s /q c:\explain_plus\misc\* ');
Text_IO.put_line(in_file,' ');
Text_IO.FCLOSE(in_file);
in_file := Text_IO.Fopen('c:\explain_plus\misc\raw_explain.txt', 'w');
Text_IO.Put_Line(in_file, linebuf);
Text_IO.put_line(in_file,' set trimspool on ');
Text_IO.put_line(in_file,' set heading off ');
Text_IO.put_line(in_file,' set feedback off ');
Text_IO.put_line(in_file,' set echo off');
Text_IO.put_line(in_file,' EXPLAIN PLAN FOR ');
Text_IO.put(in_file, :sql.sql);
Text_IO.put_line(in_file,' ; ' );
Text_IO.put_line(in_file,' ');
Text_IO.put_line(in_file,' exit');
Text_IO.FCLOSE(in_file);
in_file := Text_IO.Fopen('c:\explain_plus\misc\auto_trace.txt', 'w');
Text_IO.Put_Line(in_file, linebuf);
Text_IO.put_line(in_file,' set trimspool on ');
Text_IO.put_line(in_file,' set heading off ');
Text_IO.put_line(in_file,' set feedback off ');
Text_IO.put_line(in_file,' set echo off');
Text_IO.put_line(in_file,' spool c:\explain_plus\misc\traceonly.txt');
Text_IO.put_line(in_file,' set autotrace traceonly ');
Text_IO.put_line(in_file,' ');
Text_IO.put(in_file, :sql.sql);
Text_IO.put_line(in_file,' ; ' );
Text_IO.put_line(in_file,' ');
Text_IO.put_line(in_file,' spool off');
Text_IO.put_line(in_file,' set autotrace off ');
Text_IO.put_line(in_file,' exit');
Text_IO.FCLOSE(in_file);
output:='c:\explain_plus\misc\create_ascript3.bat '||un||'/'||pw||'@'||cn ;
Host(output,no_screen);
output:='sqlplus -s system/manager @c:\explain_plus\misc\runauto.txt' ;
Host(output,no_screen);
output:='c:\explain_plus\misc\create_ascript4.bat '||un||'/'||pw||'@'||cn ;
Host(output,no_screen);
output:='sqlplus -s system/manager @c:\explain_plus\misc\run_explain.txt' ;
Host(output,no_screen);
set_'Explain Plan','You are going to generate explain plan for that SQL. ');
exception
WHEN OTHERS
THEN
message('Error occured');
If Text_IO.is_open(in_file) then
Text_IO.Fclose(in_file);
output:='c:\explain_plus\misc\del_all.bat';
host(output,no_screen);
End if;
end;Hi,
Now my application of getting explain plan of a sql is running fine.
But during running, one script which is written inside the wbp trigger, I manually close the forms plus80.sql screen, which is cumbersome. Could someone suggest me what changes I will do in the code in order to terminate this plus80.sql forms screen automatically.
Thanks
Insbor.
My code as I posted earlier
Declare
in_file Text_IO.File_Type;
linebuf VARCHAR2(1800);
output varchar2(1000);
/* New Parameter define for form_ddl */
v_create_table_sql varchar2(2000);
v_test number;
un VARCHAR2(80);
pw VARCHAR2(80);
cn VARCHAR2(80);
BEGIN
Get_Connect_Info(un,pw,cn);
select count(*) into v_test
from all_objects
where object_name = 'PLAN_TABLE'
and owner in (user,'PUBLIC');
if v_test = 0 then
forms_ddl(v_create_table_sql);
end if;
if v_test <> 0 then
forms_ddl('delete from plan_table ');
Forms_DDL ('commit');
end if;
IF NOT Form_Success THEN
Message ('Table Creation Failed');
ELSE
null;
-- Message ('Table Created');
END IF;
--Old Work
in_file := Text_IO.Fopen('c:\explain_plus\misc\create_ascript3.bat', 'w');
Text_IO.Put_Line(in_file, linebuf);
Text_IO.put_line(in_file,' ');
Text_IO.put_line(in_file,' @echo off');
Text_IO.put_line(in_file,' ');
Text_IO.put_line(in_file,' set connect_db=%1 ' );
Text_IO.put_line(in_file,' ');
Text_IO.put_line(in_file,' if exist connect_DB == goto usage ');
Text_IO.put_line(in_file,' ');
Text_IO.put_line(in_file,' echo host " sqlplus -s %connect_db% @c:\explain_plus\misc\auto_trace.txt" > c:\explain_plus\misc\runauto.txt ');
Text_IO.put_line(in_file,' ');
Text_IO.put_line(in_file,' :end ');
Text_IO.put_line(in_file,' ');
Text_IO.put_line(in_file,' set connect_db= ');
Text_IO.put_line(in_file,' ');
Text_IO.FCLOSE(in_file);
in_file := Text_IO.Fopen('c:\explain_plus\misc\create_ascript4.bat', 'w');
Text_IO.Put_Line(in_file, linebuf);
Text_IO.put_line(in_file,' ');
Text_IO.put_line(in_file,' @echo off');
Text_IO.put_line(in_file,' ');
Text_IO.put_line(in_file,' set connect_db=%1 ' );
Text_IO.put_line(in_file,' ');
Text_IO.put_line(in_file,' if exist connect_DB == goto usage ');
Text_IO.put_line(in_file,' ');
Text_IO.put_line(in_file,' echo host " sqlplus -s %connect_db% @c:\explain_plus\misc\raw_Explain.txt" > c:\explain_plus\misc\run_explain.txt ');
Text_IO.put_line(in_file,' ');
Text_IO.put_line(in_file,' :end ');
Text_IO.put_line(in_file,' ');
Text_IO.put_line(in_file,' set connect_db= ');
Text_IO.put_line(in_file,' ');
Text_IO.FCLOSE(in_file);
in_file := Text_IO.Fopen('c:\explain_plus\misc\raw_explain.txt', 'w');
Text_IO.Put_Line(in_file, linebuf);
Text_IO.put_line(in_file,' set trimspool on ');
Text_IO.put_line(in_file,' set heading off ');
Text_IO.put_line(in_file,' set feedback off ');
Text_IO.put_line(in_file,' set echo off');
Text_IO.put_line(in_file,' EXPLAIN PLAN FOR ');
Text_IO.put(in_file, :sql.sql);
Text_IO.put_line(in_file,' ; ' );
Text_IO.put_line(in_file,' ');
Text_IO.put_line(in_file,' exit');
Text_IO.FCLOSE(in_file);
in_file := Text_IO.Fopen('c:\explain_plus\misc\auto_trace.txt', 'w');
Text_IO.Put_Line(in_file, linebuf);
Text_IO.put_line(in_file,' set trimspool on ');
Text_IO.put_line(in_file,' set heading off ');
Text_IO.put_line(in_file,' set feedback off ');
Text_IO.put_line(in_file,' set echo off');
Text_IO.put_line(in_file,' spool c:\explain_plus\misc\traceonly.txt');
Text_IO.put_line(in_file,' set autotrace traceonly ');
Text_IO.put_line(in_file,' ');
Text_IO.put(in_file, :sql.sql);
Text_IO.put_line(in_file,' ; ' );
Text_IO.put_line(in_file,' ');
Text_IO.put_line(in_file,' spool off');
Text_IO.put_line(in_file,' set autotrace off ');
Text_IO.put_line(in_file,' exit');
Text_IO.FCLOSE(in_file);
output:='c:\explain_plus\misc\create_ascript3.bat '||un||'/'||pw||'@'||cn ;
Host(output,no_screen);
output:='sqlplus -s system/manager @c:\explain_plus\misc\runauto.txt' ;
Host(output,no_screen);
output:='c:\explain_plus\misc\create_ascript4.bat '||un||'/'||pw||'@'||cn ;
Host(output,no_screen);
output:='sqlplus -s system/manager @c:\explain_plus\misc\run_explain.txt' ;
Host(output,no_screen);
exception
WHEN OTHERS
THEN
message('Error occured');
If Text_IO.is_open(in_file) then
Text_IO.Fclose(in_file);
output:='c:\explain_plus\misc\del_all.bat';
host(output,no_screen);
End if;
end; -
NEW FEATURE:AUTOTRACE IN SQL*PLUS 3.3(EXECUTION PLAN)
제품 : SQL*PLUS
작성날짜 : 2003-10-07
NEW FEATURE:AUTOTRACE IN SQL*PLUS 3.3
======================================
Autotrace는 SQL*Plus 3.3부터 지원하는 New feature로서 기존에는 init.ora에
SQL_TRACE=TRUE를 setting 후 얻어진 trace file을 TKPROF란 utility를
이용하여 SQL 문의 수행 경로, 각종 통계 정보를 얻었다.
그러나, SQL*Plus 3.3부터는 이것을 간단히 처리할 수 있는 방법을 제공한다.
1. SQL*Plus를 실행하여 scott user로 접속한 후, plan table을 생성한다.
#sqlplus scott/tiger
SQL>@$ORACLE_HOME/rdbms/admin/utlxplan
2. 다음에 sys user에서 PLUSTRACE란 ROLE을 만든다.
SVRMGR>connect internal;
SVRMGR>create role plustrace;
SVRMGR>grant select on v_$sesstat to plustrace;
SVRMGR>grant select on v_$statname to plustrace;
SVRMGR>grant select on v_$session to plustrace;
SVRMGR>grant plustrace to dba with admin option;
SVRMGR>grant plustrace to scott;
비고) 위의 grant 문은 client에 SQL*Plus 3.3이 install되어 있는 경우
C:ORAWIN95\PLUS33\PLUSTRCE.SQL이라는 script에 기록되어 있다.
다음과 같이 실행해 주면 된다.
1> connect sys/manager
2> @$ORACLE_HOME/sqlplus/admin/plustrce.sql
3> grant plustrace to scott;
3. 다음에는 scott user로 connect하여 작업한다.
#sqlplus scott/tiger
SQL>set autotrace on
SQL>select * from emp;
Execution Plan
0 SELECT STATEMENT Optimizer=CHOOSE
1 0 TABLE ACCESS (FULL) OF 'EMP'
Statistics
389 recursive calls
5 db block gets
53 consistent gets
12 physical reads
0 redo size
1049 bytes sent via SQL*Net to client
239 bytes received via SQL*Net from client
4 SQL*Net round-trips to/from client
0 sorts (memory)
0 sorts (disk)
13 rows processed
4. 참고로 set autotrace에는 여러가지 option을 부여해 작업할 수도 있다.
예)set autotrace on => Explain plan and statistics.
set autotrace on explain => Explain plan only.
set autotrace traceonly => select된 결과는 빼고 trace만 display
시킴.
set autotrace on statistics=> sql statement execution statistics.
5. 서버 버젼과 상관없다.
Server가 7.2 version 이하일지라도 clinet에 SQL*Plus 3.3이 install되어
있으면 client에서 sqlplus 3.3을 구동시켜 server에 접속하여 위와 같이
작업하면 무리없이 작업이 가능하다.
Reference Documents
<Note:43214.1>Hi Roman,
I don't have an Oracle 9.2 database readily available, but it works fine on 10g XE. Please note 3.1 is not certified with 9i:
http://www.oracle.com/technetwork/developer-tools/sql-developer/certification-096745.html
Regards,
Gary
SQL Developer Team -
Why insert a row will cause a sort (it can be saw from autotrace)?
When I simply insert a row into a table, I could also see there is a sort in memory. But why insert need a sort?
C:\Documents and Settings\qiwu>sqlplus qihua/qihua
SQL*Plus: Release 10.2.0.1.0 - Production on Sun Jul 27 19:51:51 2008
Copyright (c) 1982, 2005, Oracle. All rights reserved.
Connected to:
Oracle Database 10g Enterprise Edition Release 10.2.0.1.0 - Production
With the Partitioning, OLAP and Data Mining options
SQL> drop table t2;
Table dropped.
SQL> create table t2 (a int, b int);
Table created.
SQL> set autotrace on;
SQL> insert into t2 values(1,1);
1 row created.
Execution Plan
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time |
| 0 | INSERT STATEMENT | | 1 | 100 | 1 (0)| 00:00:01 |
Statistics
3 recursive calls
8 db block gets
2 consistent gets
0 physical reads
0 redo size
670 bytes sent via SQL*Net to client
558 bytes received via SQL*Net from client
4 SQL*Net roundtrips to/from client
2 sorts (memory) first time run, 2 sort, and after run it several times, one sort
0 sorts (disk)
1 rows processed
SQL> insert into t2 values(1,1);
1 row created.
Execution Plan
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time |
| 0 | INSERT STATEMENT | | 1 | 100 | 1 (0)| 00:00:01 |
Statistics
0 recursive calls
1 db block gets
1 consistent gets
0 physical reads
288 redo size
671 bytes sent via SQL*Net to client
558 bytes received via SQL*Net from client
4 SQL*Net roundtrips to/from client
1 sorts (memory)
0 sorts (disk)
1 rows processed
SQL> insert into t2 values(1,1);
1 row created.
Execution Plan
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time |
| 0 | INSERT STATEMENT | | 1 | 100 | 1 (0)| 00:00:01 |
Statistics
0 recursive calls
1 db block gets
1 consistent gets
0 physical reads
288 redo size
672 bytes sent via SQL*Net to client
558 bytes received via SQL*Net from client
4 SQL*Net roundtrips to/from client
1 sorts (memory)
0 sorts (disk)
1 rows processedAt a guess...
First execution makes a number of recursive calls - that'll be SQL run against the dictionary, and might well include one of your sorts.
After that, probably 1 sort for the explain part of the autotrace output.
Regards
Tony Berrington -
Better client than sqlplus for bulk fetch testing .
Hi,
I'm doing some test with rows speed retriving via Net8 and need some better client than sqlplus itself .
There is araysize limit of 5000 in sqlplus and its not oriented for massive row fetching , although Im using set termout off .
Test are in 10.2.0.3 environment and 100Mbit ethernet netowrk .
So is there any better client I can use ? Or I need to write it by myself :) ?
I've tried with pmdtm (informatica fetch utility) but it has got some problems with thread synchronization , basicaly strace profiling returns
% time seconds usecs/call calls errors syscall
57.35 1.738975 161 10819 2145 futex
41.35 1.253799 32149 39 poll
1.21 0.036717 3 11869 read
0.08 0.002491 1 2163 write
0.00 0.000000 0 50 fcntl
0.00 0.000000 0 19 clock_gettime
100.00 3.031982 24959 2145 totalso instead of reading it's latching :).
Regards
GregGGregG wrote:
its not oriented for massive row fetching , although Im using set termout off .You can use SQL*Plus AUTOTRACE command to disable query result printing:
SQL> set autotrace traceonly;
SQL> select * from dba_objects;
18816 rows selected.
Execution Plan
Plan hash value: 1919983379
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time |
| 0 | SELECT STATEMENT | | 16154 | 3265K| 75 (3)| 00:00:01 |
| 1 | VIEW | DBA_OBJECTS | 16154 | 3265K| 75 (3)| 00:00:01 |
| 2 | UNION-ALL | | | | | |
|* 3 | TABLE ACCESS BY INDEX ROWID | SUM$ | 1 | 26 | 0 (0)| 00:00:01 |
|* 4 | INDEX UNIQUE SCAN | I_SUM$_1 | 1 | | 0 (0)| 00:00:01 |
| 5 | TABLE ACCESS BY INDEX ROWID | OBJ$ | 1 | 25 | 3 (0)| 00:00:01 |
|* 6 | INDEX RANGE SCAN | I_OBJ1 | 1 | | 2 (0)| 00:00:01 |
|* 7 | FILTER | | | | | |
|* 8 | HASH JOIN | | 19706 | 2290K| 72 (3)| 00:00:01 |
| 9 | TABLE ACCESS FULL | USER$ | 66 | 1122 | 3 (0)| 00:00:01 |
|* 10 | HASH JOIN | | 19706 | 1962K| 69 (3)| 00:00:01 |
| 11 | INDEX FULL SCAN | I_USER2 | 66 | 1452 | 1 (0)| 00:00:01 |
|* 12 | TABLE ACCESS FULL | OBJ$ | 19706 | 1539K| 67 (2)| 00:00:01 |
|* 13 | TABLE ACCESS BY INDEX ROWID| IND$ | 1 | 8 | 2 (0)| 00:00:01 |
|* 14 | INDEX UNIQUE SCAN | I_IND1 | 1 | | 1 (0)| 00:00:01 |
| 15 | NESTED LOOPS | | 1 | 30 | 2 (0)| 00:00:01 |
|* 16 | INDEX SKIP SCAN | I_USER2 | 1 | 20 | 1 (0)| 00:00:01 |
|* 17 | INDEX RANGE SCAN | I_OBJ4 | 1 | 10 | 1 (0)| 00:00:01 |
| 18 | NESTED LOOPS | | 1 | 43 | 3 (0)| 00:00:01 |
| 19 | TABLE ACCESS FULL | LINK$ | 1 | 26 | 2 (0)| 00:00:01 |
| 20 | TABLE ACCESS CLUSTER | USER$ | 1 | 17 | 1 (0)| 00:00:01 |
|* 21 | INDEX UNIQUE SCAN | I_USER# | 1 | | 0 (0)| 00:00:01 |
Predicate Information (identified by operation id):
3 - filter(BITAND("S"."XPFLAGS",8388608)=8388608)
4 - access("S"."OBJ#"=:B1)
6 - access("EO"."OBJ#"=:B1)
7 - filter(("O"."TYPE#"<>1 AND "O"."TYPE#"<>10 OR "O"."TYPE#"=1 AND (SELECT 1
FROM "SYS"."IND$" "I" WHERE "I"."OBJ#"=:B1 AND ("I"."TYPE#"=1 OR "I"."TYPE#"=2 OR
"I"."TYPE#"=3 OR "I"."TYPE#"=4 OR "I"."TYPE#"=6 OR "I"."TYPE#"=7 OR
"I"."TYPE#"=9))=1) AND ("O"."TYPE#"<>4 AND "O"."TYPE#"<>5 AND "O"."TYPE#"<>7 AND
"O"."TYPE#"<>8 AND "O"."TYPE#"<>9 AND "O"."TYPE#"<>10 AND "O"."TYPE#"<>11 AND
"O"."TYPE#"<>12 AND "O"."TYPE#"<>13 AND "O"."TYPE#"<>14 AND "O"."TYPE#"<>22 AND
"O"."TYPE#"<>87 AND "O"."TYPE#"<>88 OR BITAND("U"."SPARE1",16)=0 OR ("O"."TYPE#"=4 OR
"O"."TYPE#"=5 OR "O"."TYPE#"=7 OR "O"."TYPE#"=8 OR "O"."TYPE#"=9 OR "O"."TYPE#"=10 OR
"O"."TYPE#"=11 OR "O"."TYPE#"=12 OR "O"."TYPE#"=13 OR "O"."TYPE#"=14 OR
"O"."TYPE#"=22 OR "O"."TYPE#"=87) AND ("U"."TYPE#"<>2 AND
SYS_CONTEXT('userenv','current_edition_name')='ORA$BASE' OR "U"."TYPE#"=2 AND
"U"."SPARE2"=TO_NUMBER(SYS_CONTEXT('userenv','current_edition_id')) OR EXISTS
(SELECT 0 FROM SYS."USER$" "U2",SYS."OBJ$" "O2" WHERE "O2"."OWNER#"="U2"."USER#" AND
"O2"."TYPE#"=88 AND "O2"."DATAOBJ#"=:B2 AND "U2"."TYPE#"=2 AND
"U2"."SPARE2"=TO_NUMBER(SYS_CONTEXT('userenv','current_edition_id'))))))
8 - access("O"."SPARE3"="U"."USER#")
10 - access("O"."OWNER#"="U"."USER#")
12 - filter("O"."NAME"<>'_NEXT_OBJECT' AND "O"."NAME"<>'_default_auditing_options_'
AND BITAND("O"."FLAGS",128)=0 AND "O"."LINKNAME" IS NULL)
13 - filter("I"."TYPE#"=1 OR "I"."TYPE#"=2 OR "I"."TYPE#"=3 OR "I"."TYPE#"=4 OR
"I"."TYPE#"=6 OR "I"."TYPE#"=7 OR "I"."TYPE#"=9)
14 - access("I"."OBJ#"=:B1)
16 - access("U2"."TYPE#"=2 AND "U2"."SPARE2"=TO_NUMBER(SYS_CONTEXT('userenv','curren
t_edition_id')))
filter("U2"."TYPE#"=2 AND "U2"."SPARE2"=TO_NUMBER(SYS_CONTEXT('userenv','curren
t_edition_id')))
17 - access("O2"."DATAOBJ#"=:B1 AND "O2"."TYPE#"=88 AND "O2"."OWNER#"="U2"."USER#")
21 - access("L"."OWNER#"="U"."USER#")
Statistics
0 recursive calls
0 db block gets
3397 consistent gets
78 physical reads
0 redo size
908471 bytes sent via SQL*Net to client
14213 bytes received via SQL*Net from client
1256 SQL*Net roundtrips to/from client
0 sorts (memory)
0 sorts (disk)
18816 rows processed
SQL> -
Query is immediate in sqlplus but doesn't finish in Apex
OK, so i wrote this fairly simple 4 table query for a report. This query when run from SQL Developer or directly in SQL Plus runs and completes in less than a second.
I create an APEX application that would run this same query and the report never completes. The APEX page never actually displays.
I know that's not a lot of information...i can provide it if necessary. Here is the explain plan of the query from autotrace:
15:50:46 >;
1 select c.customer||' '||c.name, so.opportunity_name, ui.name, so.estimated_project_value, so.resolution_date, smn.note
2 from s.sales_opportunity so, s.sales_mgmt_notes smn, s.user_initials ui, s.customer c
3 where smn.sales_mgmt_note_key = so.resolution_sales_mgmt_note_key
4 and so.resolution_date > sysdate - 365
5 and ui.key = so.owner_user_initials_key
6 and so.resolution = 'L'
7* and so.customer_key = c.key
15:50:48 >set autotrace traceonly explain statistics
15:50:59 >/
369 rows selected.
Execution Plan
Plan hash value: 3997948256
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time |
| 0 | SELECT STATEMENT | | 91 | 32032 | 815 (2)| 00:00:10 |
| 1 | NESTED LOOPS | | | | | |
| 2 | NESTED LOOPS | | 91 | 32032 | 815 (2)| 00:00:10 |
| 3 | NESTED LOOPS | | 90 | 9360 | 541 (2)| 00:00:07 |
| 4 | NESTED LOOPS | | 90 | 6390 | 450 (2)| 00:00:06 |
|* 5 | TABLE ACCESS BY INDEX ROWID| SALES_OPPORTUNITY | 90 | 4770 | 359 (2)| 00:00:05 |
|* 6 | INDEX RANGE SCAN | IOPPORTUNITY_RESOLVEDATE | 393 | | 3 (0)| 00:00:01 |
| 7 | TABLE ACCESS BY INDEX ROWID| USER_INITIALS | 1 | 18 | 1 (0)| 00:00:01 |
|* 8 | INDEX UNIQUE SCAN | UI_PK | 1 | | 0 (0)| 00:00:01 |
| 9 | TABLE ACCESS BY INDEX ROWID | CUSTOMER | 1 | 33 | 1 (0)| 00:00:01 |
|* 10 | INDEX UNIQUE SCAN | CUST_PK | 1 | | 0 (0)| 00:00:01 |
|* 11 | INDEX RANGE SCAN | ISMN_NOTE_KEY | 1 | | 2 (0)| 00:00:01 |
| 12 | TABLE ACCESS BY INDEX ROWID | SALES_MGMT_NOTES | 1 | 248 | 3 (0)| 00:00:01 |
Predicate Information (identified by operation id):
5 - filter("SO"."RESOLUTION_SALES_MGMT_NOTE_KEY" IS NOT NULL AND "SO"."RESOLUTION"='L' AND
"SO"."OWNER_USER_INITIALS_KEY" IS NOT NULL)
6 - access("SO"."RESOLUTION_DATE">SYSDATE@!-365)
8 - access("UI"."KEY"="SO"."OWNER_USER_INITIALS_KEY")
10 - access("SO"."CUSTOMER_KEY"="C"."KEY")
11 - access("SMN"."SALES_MGMT_NOTE_KEY"="SO"."RESOLUTION_SALES_MGMT_NOTE_KEY")
Statistics
1 recursive calls
0 db block gets
2810 consistent gets
0 physical reads
0 redo size
73724 bytes sent via SQL*Net to client
784 bytes received via SQL*Net from client
26 SQL*Net roundtrips to/from client
0 sorts (memory)
0 sorts (disk)
369 rows processedEdited by: ChrisLHT on Mar 30, 2012 12:46 PM
Edited by: ChrisLHT on Mar 30, 2012 12:56 PMSo you have no item references in the Apex query predicate - right? I had a similar issue that I never really traced the cause of, but adding ALL_ROWS hint resolved my particular query. See if using SELECT /*+ ALL_ROWS */ and SELECT /*+ FIRST_ROWS */ from SQLplus can reproduce the issue.
-
How to make linesize for autotrace be larger than 80?
Is it possible to make that the linesize of the output in sqlplus to be larger than 80?
I have my linesize = 150 but the output of the autotrace is wrapped and it is quite difficult to see.did you try?:
SET LINESIZE 150Yes, I did. And it did not work.
SQL> show user
USER is "SCOTT"
SQL> set linesize 150
SQL> set autotrace traceonly
SQL> select 1 from emp, dept, bonus, emp, dept, emp, dept, emp, dept, bonus, emp, dept, emp, dept, b
onus, emp, dept, bonus;
no rows selected
Execution Plan
0 SELECT STATEMENT Optimizer=CHOOSE
1 0 NESTED LOOPS
2 1 NESTED LOOPS
3 2 NESTED LOOPS
4 3 NESTED LOOPS
5 4 NESTED LOOPS
6 5 NESTED LOOPS
7 6 NESTED LOOPS
8 7 NESTED LOOPS
9 8 NESTED LOOPS
10 9 NESTED LOOPS
11 10 NESTED LOOPS
12 11 NESTED LOOPS
13 12 NESTED LOOPS
14 13 NESTED LOOPS
15 14 NESTED LOOPS
16 15 NESTED LOOPS
17 16 NESTED LOOPS
18 17 TABLE ACCESS (FULL) OF '
BONUS'
19 17 TABLE ACCESS (FULL) OF '
DEPT'
20 16 TABLE ACCESS (FULL) OF 'EM
P'
21 15 TABLE ACCESS (FULL) OF 'BONU
S'
22 14 TABLE ACCESS (FULL) OF 'DEPT'
23 13 TABLE ACCESS (FULL) OF 'EMP'
24 12 TABLE ACCESS (FULL) OF 'DEPT'
25 11 TABLE ACCESS (FULL) OF 'EMP'
26 10 TABLE ACCESS (FULL) OF 'BONUS'
27 9 TABLE ACCESS (FULL) OF 'DEPT'
28 8 TABLE ACCESS (FULL) OF 'EMP'
29 7 TABLE ACCESS (FULL) OF 'DEPT'
30 6 TABLE ACCESS (FULL) OF 'EMP'
31 5 TABLE ACCESS (FULL) OF 'DEPT'
32 4 TABLE ACCESS (FULL) OF 'EMP'
33 3 TABLE ACCESS (FULL) OF 'BONUS'
34 2 TABLE ACCESS (FULL) OF 'DEPT'
35 1 TABLE ACCESS (FULL) OF 'EMP'
Statistics
0 recursive calls
0 db block gets
3 consistent gets
0 physical reads
0 redo size
244 bytes sent via SQL*Net to client
372 bytes received via SQL*Net from client
1 SQL*Net roundtrips to/from client
0 sorts (memory)
0 sorts (disk)
0 rows processed
SQL> -
Sqlplus and explainplan output
when I set autotrace on and run a sql statement , the output gets wrapped on to the next line once it hits a certain length. The output then becomes muddled.
I have tried playing around with the linesize , wrap and truncate parameters in sqlplus but the output is still a mess.
how can I fix this.
any ideas guys?COLUMN plan_plus_exp FORMAT A80
-
Question about AUTOTRACE, SP2-0618 and SP2-0611
Good morning,
I wanted to look at the execution plan(s) for some sample queries. I did a little research using Google, found out about autotrace, plan_table, plustrace role and utlxplan. I followed the instructions I found but the result isn't quite as expected.
Here is an output of a freshly started session:
0 01:50 [SS1TB Attic-Z] [5G] [750M] Z:\Documentation\Oracle\
Oracle Concepts\Scripts>sqlplus hr/abc123
SQL*Plus: Release 11.2.0.1.0 Production on Sun Aug 8 01:50:16 2010
Copyright (c) 1982, 2010, Oracle. All rights reserved.
Connected to:
Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 - Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options
SQL> select count(*) from plan_table;
COUNT(*)
2
SQL> set autotrace on
SP2-0618: Cannot find the Session Identifier. Check PLUSTRACE role is enabled
SP2-0611: Error enabling STATISTICS report
SQL> select count(*) from plan_table;
COUNT(*)
2
Execution Plan
Plan hash value: 3662021055
| Id | Operation | Name | Rows | Cost (%CPU)| Time |
| 0 | SELECT STATEMENT | | 1 | 3 (0)| 00:00:01 |
| 1 | SORT AGGREGATE | | 1 | | |
| 2 | TABLE ACCESS FULL| PLAN_TABLE | 2 | 3 (0)| 00:00:01 |
Note
- dynamic sampling used for this statement (level=2)
SQL>1. the first select is there to ensure I have a plan_table, that checks.
2. When I set autotrace on, I get SP2-0618 and SP2-0611 for reasons that I cannot figure out.
3. the second select is there to find out if the autotrace in step 2 had any effect. It did since now the explain plan is displayed.
The question is: if it is working (as step 3 demonstrates) then why I am getting those errors in step 2 ? and what do I have to do to not get those errors anymore ?
Thank you (again!) for your help,
John.
Note: I created the plustrace role, granted it select on v_$sesstat, v_$statname, v_$session, then I granted plustrace to hr. Was there something else needed ?Hi John,
It looks like that, for PLUSTRACE it is important for the user to be logged out when the role is granted otherwise, it looks like there is a part of the process that doesn't "stick".That's not just with the PLustrace role. Any role would be working when the next time the user is going to log in. Please see below where using two sessions, I shall grant a user some privs and would see whether its working for the user or not.
*Session1BANNER
Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 - Production
PL/SQL Release 11.2.0.1.0 - Production
CORE 11.2.0.1.0 Production
TNS for 32-bit Windows: Version 11.2.0.1.0 - Production
NLSRTL Version 11.2.0.1.0 - Production
SQL> create user john identified by john;
User created.
SQL> grant connect to john;
Grant succeeded.
SQL> create role dangerous ;
Role created.
SQL> grant drop any table,create any index to dangerous;
Grant succeeded.
SQL> conn john/john
Connected.
SQL> select * from session_privs;
PRIVILEGE
CREATE SESSIONSo far, what I did that I created a user John, granted him a direct priviledge. There is a role also that's prepared and would be granted to the user while still he being connected. See below, this is the second session,
SQL*Plus: Release 11.2.0.1.0 Production on Sun Aug 8 15:33:09 2010
Copyright (c) 1982, 2010, Oracle. All rights reserved.
Connected to:
Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 - Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options
SQL> grant dangerous to john;
Grant succeeded.I would check the available permissions for the user in the session. This command was entered in the first session where the user john was already connected.
SQL> /
PRIVILEGE
CREATE SESSIONYou can see that there is no change in the session privs. Now, let's disconnect and connect again,
SQL> disconn
Disconnected from Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 - Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options
SQL> conn john/john
Connected.
SQL> select * from session_privs;
PRIVILEGE
CREATE SESSION
DROP ANY TABLE
CREATE ANY INDEXAll he privs are active now for the user.
Now, the privs in the role, if would be updated, would be reflecting right away in the user's currently connected session. I added one more priv to the role in the 2nd session and it was coming in the 1st session, see below please,
session-2
SQL> grant alter any table to dangerous;
Grant succeeded.
SQL>
session-1
SQL> /
PRIVILEGE
CREATE SESSION
ALTER ANY TABLE
DROP ANY TABLE
CREATE ANY INDEX
SQL>I copied extra lines I guess, deleted them now.
Aman....
Edited by: Aman.... on Aug 8, 2010 3:56 PM -
Hi, I try to use "set autotrace on" in sqlplus 8i (NT). I run the scripts "utlxplan.sql" using "sys", and can use the autotrace. But when I change to user "scott", and also run the script "utlxplan.sql" in scott, but it give errors when I issue "set autotrace on" :
"Cannot find the Session Identifier. Check PLUSTRACE role is enabled
Error enabling STATISTICS report"
Who knows what is the problem? From view dba_roles, I did not see any role named "plustrace".
Thanks in advance!1) Bitmaps are not a suitable file type for the web. You will need to open image in your favorite graphics editor, resize image to required height & width for web page, then Save for Web as an optimized GIF, JPG or PNG. The smaller the filesize, the faster your page will load.
2) In DW, Insert > Image. On the Properties Panel you should see the HOTSPOT tools: Selection arrow, rectangle, elipse, polygon.
3) Click the desired tool and drag your mouse around the area you wish to make an active link. I recommend zooming in on the page to make this easier to see.
When you have linked all your hotspot regions on the image map, switch to Code View and add Title attributes (shown in red) to each area shape.
<area shape="rect" coords="337,78,489,193" href="some-link.html" alt="#" title="Tooltip Text goes here"/>
For more info on Image Maps and Hotspots, hit F1 (DW Help).
Nancy O.
Alt-Web Design & Publishing
Web | Graphics | Print | Media Specialists
http://alt-web.com/
http://twitter.com/altweb
http://alt-web.blogspot.com -
How to create .log for sqlplus script
Hi All,
I created a sqlplus script and run it through a window form. My user want to me create a .log file for this script so they can know the job is completed or not. Does any one know how to do it?
Thanks
OFI created a "Login.sql" script that I use for all my sql*plus sessions.
It creates a spool file in my common directory and everything i do is logged unless i set spool off.
Take a look and it gives you an example of using spool files and how to set a directory and unique filename for each spoolfile.
The contents of this file:
-- any uppercase commands are my specific changes.
-- this file must go in the oracle bin path or where sqlplus exe is located
SET HEADING OFF
PROMPT Who What Why Where When, This is SQL*Plus!
Select 'You are connected to ' || GLOBAL_NAME || ' as ' || USER FROM GLOBAL_NAME;
set appinfo ON
set appinfo "SQL*Plus"
set arraysize 15
set autocommit OFF
set autoprint OFF
set autorecovery OFF
set autotrace off
set blockterminator "."
set cmdsep OFF
set colsep " "
set compatibility NATIVE
set concat "."
set copycommit 0
set copytypecheck ON
set define "&"
set describe DEPTH 1 LINENUM OFF INDENT ON
set markup HTML OFF SPOOL OFF ENTMAP ON PRE OFF
set echo OFF
set editfile "afiedt.buf"
set embedded OFF
set endbuftoken ""
set escape OFF
set feedback 6
set flagger OFF
set flush ON
SET HEADING ON
set headsep "|"
SET LINESIZE 250
set logsource ""
set long 80
set longchunksize 80
set newpage 1
set null ""
set numformat ""
set numwidth 10
SET PAGESIZE 24
set pause OFF
set recsep WRAP
set recsepchar " "
SET SERVEROUTPUT ON size 1000000 format WORD_WRAPPED
set shiftinout invisible
set showmode OFF
set sqlblanklines OFF
set sqlcase MIXED
set sqlcontinue "> "
set sqlnumber ON
set sqlprefix "#"
set sqlprompt "SQL> "
set sqlterminator ";"
set suffix "sql"
set tab ON
set termout ON
SET TIME ON
SET TIMING ON
SET TRIMOUT ON
set trimspool OFF
set underline "-"
set verify ON
set wrap ON
COL SPOOLFILE NEW_VALUE SPOOL;
COL SYSTIMESTAMP FORMAT a38
SELECT 'C:\oracle\spoolfiles\'||NAME||'_'||TO_CHAR(SYSDATE,'DD_MON_YYYY_HH24MISS')||'.lst' spoolfile FROM V$DATABASE;
spool &spool
PROMPT -----------------------------------------------
SELECT SYSTIMESTAMP FROM DUAL;
PROMPT -----------------------------------------------
Maybe you are looking for
-
Customer/Vendor A/C with line item details and with opening and closing Bal
Dear Sir / Madam, Is it possible to have a customer and / or vendor Sub-Ledger account- with line item details and with opening and closing balance detail for a particular period.? Regards Chirag Shah I thank for the given below thread which has solv
-
Design mode not working in Jdev 10g
Hi All I am facing some problem in Jdeveloper 10g. I created a project few days back. Today when I am opening jsp pages of that project, It is not coming in the Design mode. It writes only "Page Directives" instead of showing Forms and Tables. But wh
-
Media Encoder CS4 output file size varies--why??
I was batch encoding several files yesterday, and one of the files failed. Adobe Media Encoder provided no details, other than when I hover over the yellow exclamation point error icon, it says: "Error compiling movie. Unknown error." Very insightful
-
Address not showing correctly in quotation Smartform
Hi Guru's, We created smartforms for Quotaions. Based on Plant we selecting address. For some quotaions address template table displaying fine. For few quotations its not working fine in printprivew mode. Template table is same length for all. Also i
-
After I updated my N8 to Anna I had a new program called 'Nokia Signal Booster' but when I clicked it, the icon disappeared. What was this and how do I get it back? Solved! Go to Solution.