SQL tuning which uses View
I have used the below sql on a View .I will enter SEI_ACCT_NUMBER to get the respective ACCT_TRAN_ID.
It is taking longer time to run the query .ACCOUNT_TYPE_CD does not contain indexes.I do not have access rights to create indexes .
select
A.ACCT_TRAN_ID,
B.account_num as SEI_ACCT_NUMBER
from PACSAPP.TRAN_DETAIL_REPORT_VIEW A
INNER JOIN PACSAPP.TRAN_DETAIL_REPORT_VIEW B
on A.REQUEST_ID = B.REQUEST_ID
and A.ACCOUNT_TYPE_CD IN ('CHECKING','GL','SAVINGS')
and B.ACCOUNT_TYPE_CD = 'TRUST'
The counts are below
select count(*) from PACSAPP.TRAN_DETAIL_REPORT_VIEW
2909725
select count(*) from PACSAPP.TRAN_DETAIL_REPORT_VIEW B
WHERE B.ACCOUNT_TYPE_CD = 'TRUST'
835354
select count(*) from PACSAPP.TRAN_DETAIL_REPORT_VIEW B
WHERE B.ACCOUNT_TYPE_CD = 'CHECKING'
320640
select count(*) from PACSAPP.TRAN_DETAIL_REPORT_VIEW B
WHERE B.ACCOUNT_TYPE_CD = 'GL'
16723
select count(*) from PACSAPP.TRAN_DETAIL_REPORT_VIEW B
WHERE B.ACCOUNT_TYPE_CD = 'SAVINGS'
530
Could you please help in improving the performance of this
I got the plan .DBA saying that it has a cartesian.How can we improve this?Could you Please suggest
Plan
SELECT STATEMENT ALL_ROWS Cost: 29,967 Bytes: 86,655,388 Cardinality: 646,682
27 HASH JOIN RIGHT OUTER Cost: 29,967 Bytes: 86,655,388 Cardinality: 646,682
1 INDEX FULL SCAN INDEX (UNIQUE) PACSAPP.ACCT_TRAN_TYPE_PK Cost: 1 Bytes: 8 Cardinality: 2
26 HASH JOIN RIGHT OUTER Cost: 29,937 Bytes: 84,068,660 Cardinality: 646,682
2 INDEX FULL SCAN INDEX (UNIQUE) PACSAPP.ACCT_TRAN_STATUS_PK Cost: 1 Bytes: 44 Cardinality: 11
25 HASH JOIN RIGHT OUTER Cost: 29,907 Bytes: 81,481,932 Cardinality: 646,682
3 INDEX FULL SCAN INDEX (UNIQUE) PACSAPP.PAYMENT_TYPE_PK Cost: 1 Bytes: 15 Cardinality: 5
24 HASH JOIN RIGHT OUTER Cost: 29,877 Bytes: 79,541,886 Cardinality: 646,682
4 INDEX FAST FULL SCAN INDEX (UNIQUE) PACSAPP.PK_ACH_TRAN Cost: 312 Bytes: 3,515,106 Cardinality: 585,851
23 NESTED LOOPS OUTER Cost: 25,007 Bytes: 75,661,794 Cardinality: 646,682
21 HASH JOIN RIGHT OUTER Cost: 24,466 Bytes: 71,781,702 Cardinality: 646,682
5 INDEX FAST FULL SCAN INDEX (UNIQUE) PACSAPP.PK_TRUST_TRAN Cost: 183 Bytes: 2,074,164 Cardinality: 345,694
20 HASH JOIN Cost: 20,315 Bytes: 67,901,610 Cardinality: 646,682
18 HASH JOIN RIGHT OUTER Cost: 10,368 Bytes: 17,412,120 Cardinality: 241,835
6 INDEX FULL SCAN INDEX (UNIQUE) PACSAPP.ACCT_TRAN_TYPE_PK Cost: 1 Bytes: 8 Cardinality: 2
17 HASH JOIN RIGHT OUTER Cost: 10,356 Bytes: 16,444,780 Cardinality: 241,835
7 INDEX FULL SCAN INDEX (UNIQUE) PACSAPP.ACCT_TRAN_STATUS_PK Cost: 1 Bytes: 44 Cardinality: 11
16 HASH JOIN RIGHT OUTER Cost: 10,344 Bytes: 15,477,440 Cardinality: 241,835
8 INDEX FULL SCAN INDEX (UNIQUE) PACSAPP.PAYMENT_TYPE_PK Cost: 1 Bytes: 15 Cardinality: 5
15 HASH JOIN RIGHT OUTER Cost: 10,332 Bytes: 14,751,935 Cardinality: 241,835
9 INDEX FAST FULL SCAN INDEX (UNIQUE) PACSAPP.PK_ACH_TRAN Cost: 312 Bytes: 3,515,106 Cardinality: 585,851
14 NESTED LOOPS OUTER Cost: 8,688 Bytes: 13,300,925 Cardinality: 241,835
12 HASH JOIN RIGHT OUTER Cost: 8,490 Bytes: 11,587,128 Cardinality: 236,472
10 INDEX FAST FULL SCAN INDEX (UNIQUE) PACSAPP.PK_TRUST_TRAN Cost: 183 Bytes: 2,074,164 Cardinality: 345,694
11 TABLE ACCESS FULL TABLE PACSAPP.TRAN Cost: 7,349 Bytes: 10,168,296 Cardinality: 236,472
13 INDEX UNIQUE SCAN INDEX (UNIQUE) PACSAPP.PK_WIRE_TRAN Cost: 0 Bytes: 6 Cardinality: 1
19 TABLE ACCESS FULL TABLE PACSAPP.TRAN Cost: 7,387 Bytes: 23,410,761 Cardinality: 709,417
22 INDEX UNIQUE SCAN INDEX (UNIQUE) PACSAPP.PK_WIRE_TRAN Cost: 0 Bytes: 6 Cardinality: 1
Edited by: user2556087 on Feb 2, 2012 8:59 AM
Edited by: user2556087 on Feb 2, 2012 9:00 AM
Similar Messages
-
How to get the exact sql developer which used for data migration?
Hi all,
Hope doing well,
Sir i seen a link for data migration that is : http://www.oracle.com/technetwork/developer-tools/sql-developer/sql-server-connection-viewlet-swf-089886.html
in this link when they are connecting to sql database so after clicking on new connection four tab is showing that is oracle, access, my sql, sql server.
i downloaded latest version of sql developer which version is: 3.02.09.30 when i opened this i am not getting those option.
and one more thing i am not getting miragation menu name in menu items.
please help me.
thanks and regardsHi,
To connect to non-Oracle databases from SQL*Developer youneed to download the relevant JDBC driver.
This is detailed in the documentation in the User Guide -
http://docs.oracle.com/cd/E35137_01/appdev.32/e35117.pdf
in the section -
Database: Third Party JDBC Drivers
The Third Party JDBC Drivers pane specifies drivers to be used for connections to third-party (non-Oracle) databases, such as IBM DB2, MySQL, Microsoft SQL Server, or Sybase Adaptive Server. (You do not need to add a driver for connections to Microsoft Access databases.) To add a driver, click Add Entry and select the path for the driver:
■For IBM DB2: the db2jcc.jar and db2jcc_license_cu.jar files, which are available from IBM
■For MySQL: a file with a name similar to mysql-connector-java-5.0.4-bin.jar, in a directory under the one into which you unzipped the download for the MySQL driver
■For Microsoft SQL Server or Sybase Adaptive Server: jtds-1.2.jar, which is included in the jtds-1.2-dist.zip download
■For Teradata: tdgssconfig.jar and terajdbc4.jar, which are included (along with a readme.txt file) in the TeraJDBC__indep_indep.12.00.00.110.zip or TeraJDBC__indep_indep.12.00.00.110.tar download
To find a specific third-party JDBC driver, see the appropriate website (for example, http://www.mysql.com for the MySQL Connector/J JDBC driver for MySQL, http://jtds.sourceforge.net/ for the jTDS driver for Microsoft SQL Server and Sybase Adaptive Server, or search at http://www.teradata.com/ for the JDBC driver for Teradata). For MySQL, use the MySQL 5.0 driver, not 5.1 or later, with SQL Developer release 1.5.
You must specify a third-party JDBC driver or install a driver using the Check for Updates feature before you can create a database connection to a third-party database of that associated type. (See the tabs for creating connections to third-party databases in the Create/Edit/Select Database Connection dialog box.)
Regards,
Mike -
Inconsistent SQL results when using View with UNION-ALL and table function
Can any of you please execute the below scripts and check the output. In the table type variable, I am adding 4 distinct object ids, where as in the result, I get only the row pertaining to last id in the table type variable. Same row is returned 4 times (4= number of values in the table type).
This scenario is occurring in our product with a SQL with exactly same pattern. I could simulate the same issue with the sample script I have provided.
Database version: 11.2.0.3 Enterprise Edition, Single node
Thank you.
CREATE TABLE TEMP_T1 AS SELECT * FROM ALL_OBJECTS;
CREATE TABLE TEMP_T2 AS SELECT * FROM ALL_OBJECTS;
UPDATE TEMP_T2 SET OBJECT_ID = OBJECT_ID * 37;
CREATE UNIQUE INDEX TEMP_T1_U1 ON TEMP_T1(OBJECT_ID);
CREATE UNIQUE INDEX TEMP_T2_U1 ON TEMP_T2(OBJECT_ID);
CREATE OR REPLACE VIEW TEMP_T1T2_V AS
SELECT * FROM TEMP_T1 UNION ALL SELECT * FROM TEMP_T2;
CREATE OR REPLACE TYPE TEMP_OBJ_TYPE AS OBJECT (OBJ_ID NUMBER);
CREATE OR REPLACE TYPE TEMP_OBJ_TAB_TYPE IS TABLE OF TEMP_OBJ_TYPE;
SET SERVEROUTPUT ON;
DECLARE
TYPE TEMP_T1T2_V_ROW_TAB_TYPE IS TABLE OF TEMP_T1T2_V%ROWTYPE;
TEMP_T1T2_V_ROW_TAB TEMP_T1T2_V_ROW_TAB_TYPE;
TEMP_OBJ_TAB TEMP_OBJ_TAB_TYPE := TEMP_OBJ_TAB_TYPE();
PROCEDURE ADD_TO_TEMP_OBJ_TAB(OBJ_ID IN NUMBER) IS
BEGIN
TEMP_OBJ_TAB.EXTEND;
TEMP_OBJ_TAB(TEMP_OBJ_TAB.LAST) := TEMP_OBJ_TYPE(OBJ_ID);
END;
BEGIN
ADD_TO_TEMP_OBJ_TAB(100);
ADD_TO_TEMP_OBJ_TAB(116);
ADD_TO_TEMP_OBJ_TAB(279);
ADD_TO_TEMP_OBJ_TAB(364);
DBMS_OUTPUT.PUT_LINE('=====================');
FOR I IN TEMP_OBJ_TAB.FIRST..TEMP_OBJ_TAB.LAST
LOOP
DBMS_OUTPUT.PUT_LINE('OBJ_ID = '||TEMP_OBJ_TAB(I).OBJ_ID);
END LOOP;
DBMS_OUTPUT.PUT_LINE('---------------------');
SELECT * BULK COLLECT INTO TEMP_T1T2_V_ROW_TAB
FROM TEMP_T1T2_V VW
WHERE ((VW.OBJECT_ID) IN (SELECT OBJ_ID
FROM TABLE(CAST(TEMP_OBJ_TAB AS TEMP_OBJ_TAB_TYPE))));
FOR I IN TEMP_OBJ_TAB.FIRST..TEMP_OBJ_TAB.LAST
LOOP
DBMS_OUTPUT.PUT_LINE('OBJ_ID = '||TEMP_OBJ_TAB(I).OBJ_ID);
END LOOP;
DBMS_OUTPUT.PUT_LINE('---------------------');
IF TEMP_T1T2_V_ROW_TAB.COUNT > 0 THEN
FOR I IN TEMP_T1T2_V_ROW_TAB.FIRST..TEMP_T1T2_V_ROW_TAB.LAST
LOOP
DBMS_OUTPUT.PUT_LINE(TEMP_T1T2_V_ROW_TAB(I).OBJECT_ID||' : '||TEMP_T1T2_V_ROW_TAB(I).OBJECT_NAME);
END LOOP;
ELSE
DBMS_OUTPUT.PUT_LINE('NO ROWS RETURNED!');
END IF;
DBMS_OUTPUT.PUT_LINE('---------------------');
END;
/I can reproduce it:
SQL*Plus: Release 11.2.0.3.0 Production on Tue Oct 30 14:05:39 2012
Copyright (c) 1982, 2011, Oracle. All rights reserved.
Enter user-name: scott
Enter password:
Connected to:
Oracle Database 11g Enterprise Edition Release 11.2.0.3.0 - 64bit Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options
SQL> select *
2 from v$version
3 /
BANNER
Oracle Database 11g Enterprise Edition Release 11.2.0.3.0 - 64bit Production
PL/SQL Release 11.2.0.3.0 - Production
CORE 11.2.0.3.0 Production
TNS for 64-bit Windows: Version 11.2.0.3.0 - Production
NLSRTL Version 11.2.0.3.0 - Production
SQL> CREATE TABLE TEMP_T1 AS SELECT * FROM ALL_OBJECTS;
Table created.
SQL>
SQL> CREATE TABLE TEMP_T2 AS SELECT * FROM ALL_OBJECTS;
Table created.
SQL>
SQL> UPDATE TEMP_T2 SET OBJECT_ID = OBJECT_ID * 37;
72883 rows updated.
SQL>
SQL> CREATE UNIQUE INDEX TEMP_T1_U1 ON TEMP_T1(OBJECT_ID);
Index created.
SQL>
SQL> CREATE UNIQUE INDEX TEMP_T2_U1 ON TEMP_T2(OBJECT_ID);
Index created.
SQL>
SQL> CREATE OR REPLACE VIEW TEMP_T1T2_V AS
2 SELECT * FROM TEMP_T1 UNION ALL SELECT * FROM TEMP_T2;
View created.
SQL>
SQL> CREATE OR REPLACE TYPE TEMP_OBJ_TYPE AS OBJECT (OBJ_ID NUMBER)
2 /
Type created.
SQL> CREATE OR REPLACE TYPE TEMP_OBJ_TAB_TYPE IS TABLE OF TEMP_OBJ_TYPE
2 /
Type created.
SQL> SET SERVEROUTPUT ON;
SQL>
SQL> DECLARE
2 TYPE TEMP_T1T2_V_ROW_TAB_TYPE IS TABLE OF TEMP_T1T2_V%ROWTYPE;
3 TEMP_T1T2_V_ROW_TAB TEMP_T1T2_V_ROW_TAB_TYPE;
4 TEMP_OBJ_TAB TEMP_OBJ_TAB_TYPE := TEMP_OBJ_TAB_TYPE();
5 PROCEDURE ADD_TO_TEMP_OBJ_TAB(OBJ_ID IN NUMBER) IS
6 BEGIN
7 TEMP_OBJ_TAB.EXTEND;
8 TEMP_OBJ_TAB(TEMP_OBJ_TAB.LAST) := TEMP_OBJ_TYPE(OBJ_ID);
9 END;
10 BEGIN
11 ADD_TO_TEMP_OBJ_TAB(100);
12 ADD_TO_TEMP_OBJ_TAB(116);
13 ADD_TO_TEMP_OBJ_TAB(279);
14 ADD_TO_TEMP_OBJ_TAB(364);
15 DBMS_OUTPUT.PUT_LINE('=====================');
16 FOR I IN TEMP_OBJ_TAB.FIRST..TEMP_OBJ_TAB.LAST
17 LOOP
18 DBMS_OUTPUT.PUT_LINE('OBJ_ID = '||TEMP_OBJ_TAB(I).OBJ_ID);
19 END LOOP;
20 DBMS_OUTPUT.PUT_LINE('---------------------');
21 SELECT * BULK COLLECT INTO TEMP_T1T2_V_ROW_TAB
22 FROM TEMP_T1T2_V VW
23 WHERE ((VW.OBJECT_ID) IN (SELECT OBJ_ID
24 FROM TABLE(CAST(TEMP_OBJ_TAB AS TEMP_OBJ_TAB_TYPE))));
25 FOR I IN TEMP_OBJ_TAB.FIRST..TEMP_OBJ_TAB.LAST
26 LOOP
27 DBMS_OUTPUT.PUT_LINE('OBJ_ID = '||TEMP_OBJ_TAB(I).OBJ_ID);
28 END LOOP;
29 DBMS_OUTPUT.PUT_LINE('---------------------');
30 IF TEMP_T1T2_V_ROW_TAB.COUNT > 0 THEN
31 FOR I IN TEMP_T1T2_V_ROW_TAB.FIRST..TEMP_T1T2_V_ROW_TAB.LAST
32 LOOP
33 DBMS_OUTPUT.PUT_LINE(TEMP_T1T2_V_ROW_TAB(I).OBJECT_ID||' : '||TEMP_T1T2_V_ROW_TAB(I).OBJECT_NAME);
34 END LOOP;
35 ELSE
36 DBMS_OUTPUT.PUT_LINE('NO ROWS RETURNED!');
37 END IF;
38 DBMS_OUTPUT.PUT_LINE('---------------------');
39 END;
40 /
=====================
OBJ_ID = 100
OBJ_ID = 116
OBJ_ID = 279
OBJ_ID = 364
OBJ_ID = 100
OBJ_ID = 116
OBJ_ID = 279
OBJ_ID = 364
364 : I_AUDIT
364 : I_AUDIT
364 : I_AUDIT
364 : I_AUDIT
PL/SQL procedure successfully completed.
SQL> column object_name format a30
SQL> select object_id,
2 object_name
3 from dba_objects
4 where object_id in (100,116,279,364)
5 /
OBJECT_ID OBJECT_NAME
100 ORA$BASE
116 DUAL
279 MAP_OBJECT
364 I_AUDIT
SQL> Works fine in:
=====================
OBJ_ID = 100
OBJ_ID = 116
OBJ_ID = 279
OBJ_ID = 364
OBJ_ID = 100
OBJ_ID = 116
OBJ_ID = 279
OBJ_ID = 364
100 : ORA$BASE
116 : DUAL
364 : SYSTEM_PRIVILEGE_MAP
279 : MAP_OBJECT
PL/SQL procedure successfully completed.
SQL> select object_id,
2 object_name
3 from dba_objects
4 where object_id in (100,116,279,364)
5 /
OBJECT_ID OBJECT_NAME
100 ORA$BASE
116 DUAL
364 SYSTEM_PRIVILEGE_MAP
279 MAP_OBJECT
SQL> select *
2 from v$version
3 /
BANNER
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>SY.
Edited by: Solomon Yakobson on Oct 30, 2012 2:14 PM -
MS SQL query slow using view column as criteria
HI,
I am experiencing a very frustrate problem. I have 2 tables, and create a view
to union these 2 tables, when do a select on this view using the column of the
view as criteria is took more 1 minutes, but the query runs fine in Qurey Analyzer.
Anybody has the same experience? is this the problem with jdbc?I searched http://e-docs.bea.com/wls/docs70/index.html, also searched the documentation
for wls6.1, wls5.1. As you pointed I searched support site, they are all the customer
case, it's not formal documentation.
Joe Weinstein <[email protected]> wrote:
>
>
jen wrote:
Thanks. but I search on the table is fine (the same column). is thereany db setting
could be tuned? so the view is the problem? No, it's a client decision/issue. If you defined your tables to have
nvarchar columns
the jdbc driver's parameter values would be fine as-is.
I searched "useVarChars" on whole
site and can't find anything.Which site? This is a property of the weblogic.jdbc.mssqlserver4.Driver.
I just went to www.bea.com/support and entered useVarChars in the Ask
BEA
question panel and got hits...
Joe
Joe Weinstein <[email protected]> wrote:
Jen wrote:
Sorry it's my bad. I am testing on wls81, but the problems is on wls70,so they
are using different drivers.
You are the magic man. It worked on wls81 now. I am sure it will curethe problem
on wls70. Is there any documentation on this? Why it is not a problemon some
databse server? ThanksSure. The issue has to do with the MS client-DBMS protocol having evolved
from
an 8-bit (7-bit really) character representation. Now it has a newer
16-bit
way, to transfer NVARCHAR data. Java characters are all 16-bit, so
by default
a JDBC driver will send Java parameters over as NVARCHAR data. This
is
crucial
for Japanese data etc. However, once simple ASCII data is transformed
to an
NVARCHAR format, the DBMS can't directly compare it to varchar data,
or use it
in index searches. The DBMS has to convert the VARCHAR data to NVARCHAR,
but it
can't guarantee that the converted data will retain the same ordering
as the index,
so the DBMS has to do a table scan!
The properties I suggested are each driver's way of allowing you
to say "I'm
a simple American ;) I am using simple varchar data so please sendmy
java
strings that way.". This allows the DBMS to use your varchar indexes
in queries.
Joe Weinstein at BEA
Joe Weinstein <[email protected]> wrote:
Jen wrote:
It doesn't cure the problem. Here is my pool
<JDBCConnectionPool DriverName="weblogic.jdbc.sqlserver.SQLServerDriver"Name="test_pool"
Password="{3DES}fKSovViFe5kHzl/vTs0LVQ==" Properties="user=user;PortNumber=1543;useVarChars=true;ServerName=194.20.2.10;DatabaseName=devDB"
Targets="admin" TestTableName="SQL SELECT COUNT(*) FROM sysobjects"URL="jdbc:bea:sqlserver://194.20.2.10:1543"/>
Strange is some database is fine.Oh, sorry. I thought it was the older weblogic driver. Change the
useVarChars=true to sendStringParametersAsUnicode=false
Let me know... Also, I suggest changing the TestTableName to "SQL
select
1".
For MS, that will be much more efficient than involving a full count
of sysobjects!
Joe
Joe Weinstein <[email protected]> wrote:
Jen wrote:
You are right. Tadaa! Am I Kreskin, or what? ;) Here's what I recommend:
In your pool definition, for this driver add a driver property:
useVarChars=true
and let me know if it's all better.
Joe
I am using weblogic jdbc driver weblogic.jdbc.mssqlserver4.Driver.
here is the code:
getData(Connection connection, String stmt, ArrayList arguments)
PreparedStatement pStatement=null;>>>>>>>> ResultSet resultSet=null;>>>>>>>> try {>>>>>>>> pStatement = connection.prepareStatement(stmt);>>>>>>>> for (int i = 1; i <= arguments.size(); i++) {>>>>>>>> pStatement.setString(i, (String) arguments.get(i-1));>>>>>>>> resultSet = pStatement.executeQuery(); //this statement takesmore than 1
min.
Joe Weinstein <[email protected]> wrote:
Jen wrote:
HI,
I am experiencing a very frustrate problem. I have 2 tables,
and
create
a view
to union these 2 tables, when do a select on this view using
the
column
of the
view as criteria is took more 1 minutes, but the query runs
fine
in
Qurey Analyzer.
Anybody has the same experience? is this the problem with jdbc?
I have suspicions... Show me the jdbc code. I'm guessing it's
a
PreparedStatement,
and you send the search criterion column value as a parameter
you
set
with a
setString().... Let me know... (also let me know which jdbc driveryou're
using).
Joe -
SQL Tuning using Enterprise manager in oracle 10g
Hi,
In oracle 10g you have the enterprise manager which can be used to tune sql statements using the SQL Tuning ADvisor and SQL access advisor.
I believe in oracle 10g the process of SQL Tuning is slightly easier using the Enterprise Manager ...so if some one could explain me that process...
Again thanking you in advance
regds
Manoj GokhaleHi Manoj,
Didn't you already start two other threads about this same question the SQL forum?
How do i do the SQL Statement tuning
Enterprise Manager - sql tuning advisor , Access advisor for SQL Tuning -
Need SQL query using View - Please help
Hi,
I have similar requirement like below.
I have two tables DEPT and EMP and some departments may not have employees. I have created below view, which displays all DEPT records, even though there are no emplyees.
CREATE OR REPLACE VIEW dept_emp_vw AS
SELECT deptno, empid, 0 AS selected
FROM dept d, emp e
WHERE d.deptno = e.deptnno (+);
Ex.
DEPTNO EMPID SELECTED
10 101 0
10 102 0
20 103 0
30 103 0
40 104 0
50 <null> 0
Application will pass "empid" to the view (for ex. empid = 103) and I want result like below.
Ex.
DEPTNO EMPID SELECTED
10 101 0
10 102 0
20 103 1
30 103 1
40 104 0
50 <null> 0
Can you please let me know the query using "dept_emp_vw" view. We have Oracle 11g Release 2.
Thanks a lot for the help.Not possible using normal SQL - as SQL is not a procedure language and does not support variable declaration and use (e.g. passing empid as a variable and using it both as a predicate and as a condition in the SQL projection).
That said - SQL can be "+parameterised+". An approach that is ugly and contrary to the basic design and use of SQL. But it can support the (very weird) view definition of yours.
E.g.
SQL> create or replace procedure SetVariable( name varchar2, value varchar2 ) is
2 begin
3 DBMS_SESSION.set_context( 'MyVariables', name, value );
4 end;
5 /
Procedure created.
SQL>
SQL>
SQL> create or replace context MyVariables using SetVariable;
Context created.
SQL>
SQL> create or replace view my_funky_weird_view as
2 select
3 e.empno,
4 e.ename,
5 e.job,
6 case e.empno
7 when to_number(sys_context( 'MyVariables', 'empid' )) then
8 0
9 else
10 1
11 end as "SELECTED"
12 from emp e
13 /
View created.
SQL>
SQL> exec SetVariable( 'empid', 7499 )
PL/SQL procedure successfully completed.
SQL>
SQL> select * from session_context where namespace = 'MYVARIABLES';
NAMESPACE ATTRIBUTE VALUE
MYVARIABLES EMPID 7499
SQL>
SQL> select * from my_funky_weird_view order by selected;
EMPNO ENAME JOB SELECTED
7499 ALLEN SALESMAN 0
7521 WARD SALESMAN 1
7566 JONES MANAGER 1
7654 MARTIN SALESMAN 1
7698 BLAKE MANAGER 1
7934 MILLER CLERK 1
7788 SCOTT ANALYST 1
7839 KING PRESIDENT 1
7844 TURNER SALESMAN 1
7876 ADAMS CLERK 1
7900 JAMES CLERK 1
7902 FORD ANALYST 1
7369 SMITH CLERK 1
7782 CLARK MANAGER 1
14 rows selected.
SQL>But I will N\OT recommend doing it this way. It is not natural SQL as PL/SQL is needed to "+inject+" name-value pairs into the context for the SQL view to use. It is ugly. It is not standard. It cannot scale. It is complex to use. Etc.
Yes, there are instances when this approach is exactly what one needs - when for example dealing with a trusted context and using the contents for implementing a security layer. But in the above case - I would rather want to see the actual business requirement first, as I think you're barking up the wrong tree with the view solution you have imagined. -
How to use views in sql script report?
All all
Can any one tell how to use views in sql script report?Most of the views are based on tables (or other views which are based on tables).
The view typically shows one org at a time based on the context that is set.
If you need records for all orgs, you need to use the underlying tables. Oracle typically names the tables with a _all suffix.
e.g. PO_HEADERS will show records for one org at a time. PO_HEADERS_ALL will show records for all orgs.
Hope this answers your question,
Sandeep Gandhi -
We have activated the Oracle 'SQL Tuning pack' however only one function "SQL Tuning Advisor" is activated/visible in ST04
and other functionality is not visible. We have already taken license of 'SQL Tuning pack' .
Other then this we want to use following oracle supported features.
1) Automatic SQL Tuning Advisor
2) Real-time SQL Monitoring
3) Object Reorganization Wizard
As I know we can use "oracle enterprise manager" to use such oracle features, If SAP allow use of OEM in SAP environment.
can someone help here please..?
Thanks,
Kapil PandeyHello Kapil,
which other options did you expect to find in ST04? SAP note 1028068 speaks only of the "SQL Tuning Advisor" which will be activated:
As of Enhancement Package 1 for Basis Release 7.00 (that is, Basis Release 7.01), the function "SQL Tuning Advisor" is contained in the DBA Cockpit. This optional function requires the Oracle Tuning Pack to be licensed.
The other features should be used via the OEM, because they are not integrated in the DBACOCKPIT transaction:
- Automatic SQL Tuning Advisor
- Real-time SQL Monitoring (with OEM you even get a really useful visualization)
- Object Reorganization Wizard -> better use brspace because it is supported by SAP
Regards,
Mark -
Sql Tuning using OEM and Logon triggers
OEM = 10.2.0.4/Agent 10.2.0.4
Target = 10.2.0.3 Db
We have several db users that have session level adjustments made by use of logon triggers. When OEM is used to review one of those session's performance and sql tuning opportunities - are the logon triggers and the session level settings taken into consideration? Another way to ask is if the suggested changes from the sql profiler are making decisions based on the user's session level settings?
Thank you in advance.
-abeYour logon triggers affect the new sessions. When you monitor with OEM, it is no affect on OEM's activity. Hoping that, your logon trigger did not affect the user which OEM uses to connect to repository DB.
-
SQL Tuning Advisor evaluates statement using wrong plan_hash_value
The execution plan for one of my SQL statements changed this morning. The statement is in a third-party package. The new plan runs worse than the old plan. I had the SQL tuning advisor evaluate the statement. I ran it three times. Each time it evaluated the original plan, not the new one. I can tell that because the plan_hash_value shown in the advisor's recommendations is the old plan's plan_hash_value. The old plan no longer appears in DBA_HIST_SQL_PLAN. I do not understand why the advisor is using the original plan, nor where it is getting it. It does not show up in Oracle Enterprise Manager either.
Has anyone see this before?
Do you have any suggestions how I can force the advisor to evaluate the new execution plan?
I am running Oracle Database Server 10gR2 Enterprise Edition.
Thanks,
BillFollowing advice given earlier, I ran the SQL Tuning Advisor by executing DBMS_SQLTUNE from within a SQL*Plus session instead of via Oracle Enterprise Manager. The problem I originally encountered in OEM also happened using DBMS_SQLTUNE. Using DBMS_SQLTUNE I specified plan_hash_value => '3657286666' but the results of running create_tuning_task shows that the utility used a different plan_hash_value. See below:
Based on this, I think the problem I originally blamed on OEM's creation of a SQL Tuning Advisor job was misdirected. I now believe that OEM supplied the proper information to the advisor, but the advisor did not correctly use what is was given.
Below is what I submitted when I ran create_tuning_task and execute_tuning_task. Note that the value assigned to plan_hash_value is 3657286666. Following the messages from execute_tuning_task, see the output produced by the execution of report_tuning_task. In EXPLAIN PLANS SECTION heading 1 - ORIGINAL, note that Plan Hash Value = 3541843898.
I submitted instructions to use plan_hash_value 3657286666 but instead it used 3541843898. Why did it do this??????
I have not found a published bug that describes this condition.
Thanks,
Bill
SQL> DECLARE
2 stmt_task VARCHAR2(64);
3 BEGIN
4 stmt_task:=dbms_sqltune.create_tuning_task(sql_id => 'ab30ujpshkur3', plan_hash_
value => '3657286666', time_limit => 3600, task_name => 'Tune_ab30ujpshkur3_3657286666'
, description => 'Task to tune sql_id ab30ujpshkur3 plan_hash_value 3657286666');
5 END;
6 /
PL/SQL procedure successfully completed.
SQL> EXECUTE dbms_sqltune.execute_tuning_task('Tune_ab30ujpshkur3_3657286666');
PL/SQL procedure successfully completed.
Here is the output produced by report_tuning_task:
SQL> SET linesize 200
SQL> SET LONG 999999999
SQL> SET pages 1000
SQL> SET longchunksize 20000
SQL> SELECT dbms_sqltune.report_tuning_task('Tune_ab30ujpshkur3_3657286666', 'TEXT', 'ALL') FROM dual;
SELECT dbms_sqltune.script_tuning_task('Tune_ab30ujpshkur3_3657286666', 'ALL')
FROM dual;
DBMS_SQLTUNE.REPORT_TUNING_TASK('TUNE_AB30UJPSHKUR3_3657286666','TEXT','ALL')
GENERAL INFORMATION SECTION
Tuning Task Name : Tune_ab30ujpshkur3_3657286666
Tuning Task Owner : EXPTEST
Tuning Task ID : 110190
Scope : COMPREHENSIVE
Time Limit(seconds) : 3600
Completion Status : COMPLETED
Started at : 08/03/2012 14:47:45
Completed at : 08/03/2012 14:48:54
Number of Index Findings : 1
Schema Name: EXPTEST
SQL ID : ab30ujpshkur3
SQL Text : SELECT ATTACHED_ACC_ID FROM SERVICE_EVENTS WHERE TSERV_ID = :B4
AND EQ_NBR = :B3 AND ASSOC_EQ_NBR = :B2 AND (PERFORMED <= :B1 +
1/1440 AND PERFORMED >= :B1 - 1/1440)
FINDINGS SECTION (1 finding)
1- Index Finding (see explain plans section below)
The execution plan of this statement can be improved by creating one or more
indices.
Recommendation (estimated benefit: 100%)
- Consider running the Access Advisor to improve the physical schema design
or creating the recommended index.
create index EXPTEST.IDX$$_1AE6E0001 on
EXPTEST.SERVICE_EVENTS('EQ_NBR','ASSOC_EQ_NBR');
Rationale
Creating the recommended indices significantly improves the execution plan
of this statement. However, it might be preferable to run "Access Advisor"
using a representative SQL workload as opposed to a single statement. This
will allow to get comprehensive index recommendations which takes into
account index maintenance overhead and additional space consumption.
EXPLAIN PLANS SECTION
1- Original
Plan hash value: 3541843898
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)|
Time |
| 0 | SELECT STATEMENT | | 1 | 32 | 4 (0)|
00:00:01 |
|* 1 | FILTER | | | | |
|
|* 2 | TABLE ACCESS BY INDEX ROWID| SERVICE_EVENTS | 1 | 32 | 4 (0)|
00:00:01 |
|* 3 | INDEX RANGE SCAN | SEVENTS_PERFORMED | 18 | | 2 (0)|
00:00:01 |
Query Block Name / Object Alias (identified by operation id):
1 - SEL$1
2 - SEL$1 / SERVICE_EVENTS@SEL$1
3 - SEL$1 / SERVICE_EVENTS@SEL$1
Predicate Information (identified by operation id):
1 - filter(:B1+.000694444444444444444444444444444444444444>=:B1-.0006944444444444444
444
44444444444444444444)
2 - filter("EQ_NBR"=:B3 AND "ASSOC_EQ_NBR"=:B2 AND "TSERV_ID"=:B4)
3 - access("PERFORMED">=:B1-.000694444444444444444444444444444444444444 AND
"PERFORMED"<=:B1+.000694444444444444444444444444444444444444)
Column Projection Information (identified by operation id):
1 - "ATTACHED_ACC_ID"[VARCHAR2,12]
2 - "ATTACHED_ACC_ID"[VARCHAR2,12]
3 - "SERVICE_EVENTS".ROWID[ROWID,10]
2- Using New Indices
Plan hash value: 2568062050
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)| T
ime |
| 0 | SELECT STATEMENT | | 1 | 32 | 2 (0)| 0
0:00:01 |
|* 1 | FILTER | | | | |
|
|* 2 | TABLE ACCESS BY INDEX ROWID| SERVICE_EVENTS | 1 | 32 | 2 (0)| 0
0:00:01 |
|* 3 | INDEX RANGE SCAN | IDX$$_1AE6E0001 | 1 | | 2 (0)| 0
0:00:01 |
Query Block Name / Object Alias (identified by operation id):
1 - SEL$1
2 - SEL$1 / SERVICE_EVENTS@SEL$1
3 - SEL$1 / SERVICE_EVENTS@SEL$1
Predicate Information (identified by operation id):
1 - filter(:B1+.000694444444444444444444444444444444444444>=:B1-.0006944444444444444
4
4444444444444444444444)
2 - filter("TSERV_ID"=:B4 AND "PERFORMED">=:B1-.000694444444444444444444444444444444
4
44444 AND "PERFORMED"<=:B1+.000694444444444444444444444444444444444444)
3 - access("EQ_NBR"=:B3 AND "ASSOC_EQ_NBR"=:B2)
Column Projection Information (identified by operation id):
1 - "ATTACHED_ACC_ID"[VARCHAR2,12]
2 - "ATTACHED_ACC_ID"[VARCHAR2,12]
3 - "SERVICE_EVENTS".ROWID[ROWID,10]
SQL> 2
DBMS_SQLTUNE.SCRIPT_TUNING_TASK('TUNE_AB30UJPSHKUR3_3657286666','ALL')
-- Script generated by DBMS_SQLTUNE package, advisor framework --
-- Use this script to implement some of the recommendations --
-- made by the SQL tuning advisor. --
-- NOTE: this script may need to be edited for your system --
-- (index names, privileges, etc) before it is executed. --
create index EXPTEST.IDX$$_1AE6E0001 on EXPTEST.SERVICE_EVENTS('EQ_NBR','ASSOC_EQ_NBR')
; -
How could I find which i-views/pages are being used
Hello
I am pritty new in portal area. I have to administrate an ESS/MSS portal during hollydays. I am trying to find everywhere the way.
How could I find which i-views/pages are being used. Let say I can see which group I belong and which roles are behind.
How could I know in which PCD folder they are taken into account (to e.g give permission to someone not in the group)HI,
the user administration (UME) gives you the information about the user <-> group <-> role assignment.
When you know the role, search in the PCS for it, open the role and you will see all the pages / iviews assigned to the role.
SAP Help: Role Assignment: http://help.sap.com/saphelp_nw04s/helpdata/en/59/bf2287b3cb5e48af94f99929ad15b9/content.htm
SAP Help: Content Administration: http://help.sap.com/saphelp_nw04s/helpdata/en/5a/0339000c0b11d7b84800047582c9f7/content.htm
br,
Tobias -
I have been using FIREFOX since a long time back and am quite happy with FIREFOX 4.
But a little uncanny situation since release of FIREFOX RC is that 'Reload which used to come under view option is no longer visible,but appears as an icon(button) in toolbar...which sometimes doesn't work(becomes blur and sometimes firefox hangs)'.
Please try to fix it if its only my problem or include it in next release.Thanks!I have been using FIREFOX since a long time back and am quite happy with FIREFOX 4.
But a little uncanny situation since release of FIREFOX RC is that 'Reload which used to come under view option is no longer visible,but appears as an icon(button) in toolbar...which sometimes doesn't work(becomes blur and sometimes firefox hangs)'.
Please try to fix it if its only my problem or include it in next release.Thanks! -
BEA MS Sql server which driver to use?
We have BEA weblogic 8.1 and want to work with sql server Which driver
shoudl we use ?
i believe driver is deprecated
Bea talks about the new driver
"WebLogic Server 8.1 SP1 includes a new JDBC driver from BEA for connecting
to a Microsoft SQL Server database. The BEA WebLogic Type 4 JDBC MS SQL
Server driver replaces the WebLogic jDriver for Microsoft SQL Server, which
is deprecated. The new driver offers JDBC
3.0 compliance, support for some JDBC 2.0 extensions, and better
performance. BEA recommends that you use the new BEA WebLogic Type 4 JDBC MS
SQL Server driver in place of the WebLogic jDriver for Microsoft SQL
Server."
Do we have to install sp1 or sp2 to work with this driver. How can we get
sp1 ,
Thanks,Where did the Driver file place?
You can copy the driver file to the JAVA_HOME/lib
folderDo not put that JDBC JAR in JAVA_HOME/lib.
You should put it someplace close to your app and add it to the CLASSPATH when you compile and run?
Geez, doesn't anybody think about a standard directory structure to use for their apps? Put it in a /lib directory with the rest of your app stuff. - MOD -
Using Linked SQL server in a View
Hello All:
I have a new view that reads data from the base source server/table. Also, it links in another server (using the sp_addlinkedserver command).
When I run the script not in a view, it works. When I create a view with this script, it does not find the linked server. Is there some issue with linked servers from within a view or perhaps I am creating the view
incorrectly in combination with the linking of the server? I have begining of the view creation below. Ideas? Thanks
If OBJECT_ID('dbo.V_CombinedLaborHours') IS NOT NULL
DROP VIEW dbo.V_CombinedLaborHours;
GO
use SQL_Server_1
EXEC sp_addlinkedserver 'SQL_Server_2', N'SQL Server'
GO
Create View dbo.V_CombinedLaborHours
AS
selectSorry, that difference in the name was a typo. I manually changed the name for display purposes only. My company forbids actual server and database names to be exposed to the outside.
When I run the script from outside of the view, it works (linking the second server etc) and I can see the data coming from the view. It is just when I create the view (as shown in the first entry in this thread) then it is as if the view is
not running the sp_addlinkedserver command.
Perhaps I cannot run the link to the second server out side of the "AS" command? I tried having it inside of the "AS" but then it throws error. When I look at the definition of the View it is not showing the link to
the second server as if it got ignored during the create of the view. -
BOXI3.0 Universe Design using view or query in SQL
Hi. Alias here.
I would like to know what are the effect to the BOXI3.0 or SQL performance if:
1. We are using view or query in creating the universe?
2. Is it the correct way of creating the universe only from tables?
3. If need to do combination between tables and views?
Hope you all can reply to this matter.
Regards,
AliasHi Alias,
Designer has the capability to import tables and views you cna use in the design of the universe. Furthermore, you can also create a derived table in the universe - in simple terms it is much like a view, but the code is in the universe availble to the universe designer.
With all this available to you, it is pretty much up to you how you want to tackle the design. I would say first prise is using the physical tables in the databse, then move to using a view and if there are certain restrictions on the designer, use the derived tables.
Remeber this, at the end of the day, any SQL code generated or used is passed down to the database to be processed, may it be the query from the universe directly on the tables or by means of the views or derived tables - the database server will need to crunch through it all - and this is what will determine your performance.
Regards
Jacques
Maybe you are looking for
-
Insert, update and delete on updatable join views
Hi I need to insert, update and delete data in a views. I tried the foloing example http://download-uk.oracle.com/docs/cd/B14117_01/server.101/b10739/views.htm#i1006232 We have two tables: CREATE TABLE dept ( deptno NUMBER(4) PRIMARY KEY, dname VARCH
-
Output Macbook Pro to HDTV?
Is there a single chord that could be purchased either online, or preferably somewhere like BestBuy, that could let my Macbook Pro display onto an HDTV, so I could watch movies on it that I have downloaded, without buying an Apple TV? Thanks
-
Third-Party apps can't connect to public wifi networks.
When I connect my iPhone to my university's Wi-Fi connection, Apple Apps (Safari, Mail, iTunes, App Store...) all function normally. But when it comes to third-party apps I can't get them to connect to the internet. So is there a workaround to this?
-
Can't Connect - New Connection
I want to like Contribute CS3, I really do. I spent the money on the full version. I trusted in Adobe to put out a product that was as robust as Photoshop and all the rest. So far, it's been disappointing. The latest drama is that all of a sudden, Co
-
hi to all abap gurus my querry is as follows what is buffer ? and when do we buffer the table ? how do we decide wether the table has tio be buffered or not ? we know that all bufeering types 1 full buffering , 2. single record buffering .3.generi