IN clause Vs Exist clause
Which is better to use in select query IN or EXIST clause ??
Which better in terms of what performance,readability ? Performance is the same but EXISTS is more readable and easy understand in my opinion.
Best Regards,Uri Dimant SQL Server MVP,
http://sqlblog.com/blogs/uri_dimant/
MS SQL optimization: MS SQL Development and Optimization
MS SQL Consulting:
Large scale of database and data cleansing
Remote DBA Services:
Improves MS SQL Database Performance
SQL Server Integration Services:
Business Intelligence
Similar Messages
-
Need to seek advice on the use of EXISTS clause.
What is this statement trying to do? What is the '1' in the inner SELECT statement means?
DELETE FROM a
WHERE NOT EXISTS (SELECT 1
FROM b
WHERE a.a_id = b.a_id);
What about these 2 statements doing??
SELECT * FROM a WHERE EXISTS (SELECT 1 FROM b WHERE a.a_id = b.a_id);
DELETE FROM a
WHERE EXISTS (SELECT 1 FROM b WHERE a.a_id = b.a_id);have a look at http://asktom.oracle.com/pls/ask/f?p=4950:8:::::F4950_P8_DISPLAYID:953229842074 for a complete explanation of how an "exists" and an "in" is executed. For "not in" and "not exists", look here: http://asktom.oracle.com/pls/ask/f?p=4950:8:::::F4950_P8_DISPLAYID:442029737684
greetings
Freek D
Freek and Mona are correct in that the 1 is just a place holder, because you need to SELECT something. However, the EXISTS clause actually returns TRUE or FALSE depending on whether the SELECT statement finds a row.
EXISTS is similar to IN using a SELECT statement. The advantage of EXISTS, particularly when you can use a correlated sub-query, is that it stops looking as soon as it finds a single row that matches the criteria in the SELECT statement, where an IN clause will return all the rows that match, including duplicates -
Use of EXISTS clause in Interface
I want to build an interface from one table but using an exist clause to check the data change in the same table.
In SQL statement it can be expressed as follows
SELECT PB.PROJECT_KEY, COUNT (DISTINCT DW_PROJECT_BUILDING_KEY)
FROM DW_PROJECT_BUILDING PB
WHERE EXISTS
(SELECT 1
FROM DW_PROJECT_BUILDING PB1
WHERE PB1.PROJECT_KEY = PB.PROJECT_KEY
AND PB1.RECORD_STATUS_ID = 1)
AND PB.RECORD_STATUS_ID = 1
AND TRUNC (PB.LOAD_DT) >= '03-OCT-2013'
GROUP BY PB.PROJECT_KEY;
How can I build this SQL with exists clause in the interface ?
ThanksCreate the interface with DW_PROJECT_BUILDING table and give this table a name PB.
Now put one filter on the table with the conditions that you have just mentioned in the query above, with the exist statement.
I assume data from this table is targeted into one more aggregated table: here is the definition for the table:
CREATE TABLE PROJECT_BUILDING_AGGR
(PROJ_BUILD_KEY VARCHAR2(20),
PROJECT_KEY varchar2(20));
perform mapping like :
PROJECT_KEY=PB.PROJECT_KEY
PROJ_BUILD_KEY=count(distinct PB.DW_PROJECT_BUILDING_KEY)
Select IKM as IKM SQL control append.
FLOW control as false.
run the interface, it is giving something like this for me, I hope this is according to your requirement:
insert into
ORACLE_SOURCE.PROJECT_BUILDING_AGGR
PROJ_BUILD_KEY,
PROJECT_KEY
select
PROJ_BUILD_KEY,
PROJECT_KEY
FROM (
select
count(distinct PB.DW_PROJECT_BUILDING_KEY) PROJ_BUILD_KEY,
PB.PROJECT_KEY PROJECT_KEY
from
ORACLE_SOURCE.DW_PROJECT_BUILDING PB
where
(1=1)
And (EXISTS
(SELECT 1
FROM DW_PROJECT_BUILDING PB1
WHERE PB1.PROJECT_KEY = PB.PROJECT_KEY
AND PB1.RECORD_STATUS_ID = 1)
AND PB.RECORD_STATUS_ID = 1
AND TRUNC (PB.LOAD_DT) >= '03-OCT-2013')
Group By PB.PROJECT_KEY
) ODI_GET_FROM -
Exists clause in query causes too much time to get back results
We Are having the long query as follows which is taking so much time to respond.Is there any way to optimize the query.We see that there is exists clause in query which is taking long time .if it is so please suggest appropriate solution to remove exists clause.
SELECT
DISTINCT t0.JDOID,
t0.JDOCLASS,
t0.JDOVERSION,
t0.ACTIVITY,
t0.ADMINSTATE,
t0.CREATEDDATE,
t0.CREATEDUSER,
t0.DESCRIPTION,
t0.ENDDATE,
t0.ID,
t0.LASTMODIFIEDDATE,
t0.LASTMODIFIEDUSER,
t0.NAME,
t0.NOSPEC,
t0.OBJECTSTATE,
t0.OWNER,
t0.PARTITION,
t0.PERMISSIONS,
t0.SPECIFICATION,
t0.STARTDATE
FROM
SERVINV.RESOURCESPECIFICATION t2,
SERVINV.SPECIFICATION t3,
SERVINV.TELEPHONENUMBER t0,
SERVINV.TELEPHONENUMBERSPECIFICATION t1,
SERVINV.TN_CHAR t4
WHERE
t3.NAME = 'usTelephoneNumber'
AND
t0.ID LIKE '0010210%'
OR t0.ID LIKE '0010370%'
OR t0.ID LIKE '0010690%'
OR t0.ID LIKE '0010090%'
OR t0.ID LIKE '0010610%'
OR t0.ID LIKE '0010570%'
OR t0.ID LIKE '0010330%'
OR t0.ID LIKE '0010130%'
OR t0.ID LIKE '0010410%'
OR t0.ID LIKE '0010650%'
OR t0.ID LIKE '0010730%'
OR t0.ID LIKE '0010050%'
OR t0.ID LIKE '0010450%'
OR t0.ID LIKE '0010490%'
OR t0.ID LIKE '0010530%'
OR t0.ID LIKE '0010170%'
OR t0.ID LIKE '0010290%'
OR t0.ID LIKE '0010030%'
OR t0.ID LIKE '0010250%'
OR t0.ID LIKE '0010770%'
AND t4.NAME = 'tnType'
AND t4.VALUE = 'OWNED'
AND NOT EXISTS (
SELECT
t5.JDOID
FROM
SERVINV.TNCONSUMER t5
WHERE
t5.TELEPHONENUMBER = t0.JDOID
AND
t5.ADMINSTATE IS
NULL
OR t5.ADMINSTATE <> 'UNASSIGNED'
AND
t0.OBJECTSTATE = 'ACTIVE'
OR t0.OBJECTSTATE = 'INACTIVE'
OR t0.OBJECTSTATE IS
NULL
AND t0.JDOCLASS = 'com.metasolv.impl.entity.TelephoneNumberDAO'
AND t0.SPECIFICATION = t1.JDOID
AND t0.JDOID = t4.TELEPHONENUMBER
AND t1.JDOID = t2.JDOID
AND t2.JDOID = t3.JDOID
ORDER BY
t0.ID ASC;
Unable to post xplain plan as it is huge and exceeding 30000 characters.
PanduHi Pandu,
try something like this and check if it works:
replace the OR conditions with substr function:
AND substr(t0.ID,1,7) in
('0010210',
'0010370',
'0010690',
'0010090',
'0010610',
'0010570',
'0010330',
'0010130',
'0010410',
'0010650',
'0010730',
'0010050',
'0010450',
'0010490',
'0010530',
'0010170',
'0010290',
'0010030',
'0010250',
'0010770')confirm if this reduces the time...will check further after your confirmation...
Regards
Imran -
Not able to migrate a query with not exist clause
Hi all,
I'm using Toplink 10.1.3 and I am trying to rewrite the following query with Expression Framework:
select distinct r.e_ogg_oper_k_oggetto
FROM regola_accettazione_oper_banc r, oggetto_operazione_bancaria o
where not exists (
select 1
FROM limitaz_ogg_tipo_oper_banc l
where nvl(l.d_fine_validita,trunc(sysdate)+1)>trunc(sysdate)
and l.d_inizio_validita <= trunc(sysdate)
and l.e_tpodv_k_tipo_operazione=:appoggio.tipo_operaz
and l.e_ogg_oper_k_oggetto=r.e_ogg_oper_k_oggetto
and l.e_uni_oper_k_unita_oper_util= :appoggio.e_uni_oper_k_unita_oper_esegui )
and r.e_oper_ban_k_operaz_bancaria=:appoggio.form
and r.e_ogg_oper_k_oggetto=o.k_oggetto
and o.e_ogg_oper_k_oggetto is null
and o.k_oggetto != nvl(:appoggio.oggetto_autom,,'0')
and o.k_oggetto like substr(:appoggio.oggetto,1,2)||'%'
and r.d_inizio_validita <= :appoggio.d_contab
and to_date(nvl(to_char(r.d_fine_validita,DD/MM/YYYY'),31/12/3999'),'DD/MM/YYYY')> :appoggio.d_contab
and o.f_natura_oggetto in ('G','P') and r.f_oggetto_automatizzato!='S'
I'm not able to "attach" the not exist clause to the rest of query.
How can I do it?
Thank you very much.Not exists can be used in an expression through using a ReportQuery sub-query.
i.e.
ExpressionBuilder outerBuilder = new ExpressionBuilder();
ReadAllQuery outerQuery = new ReadAllQuery(Employee.class, outerBuilder);
ExpressionBuilder subBuilder = new ExpressionBuilder();
ReportQuery subQuery = new ReportQuery(Address.class, subBuilder);
subQuery.addAttribute("id");
subQuery.setSelectionCriteria(
subBuilder.get("city").equal(outerBuilder.get("address").get("city")
.and(subBuilder.notEqual(outerBuilder.get("address")))));
outerQuery.setSelectionCriteria(
outerBuilder.notExists(subQuery));
List results = (List) session.executeQuery(outerQuery);
Refer to the documentation section on sub-queries for more information.
I would suggest simlpifying the where clause until you get the sub-query working to start.
You can also always use a custom SQL query in TopLink. -
Can any one tell me how to use EXISTS clause inplace of IN operator.
Hi All,
Can any one tell me how to use EXISTS clause AND (JC.EMPL_ID, JC.EMPL_RCD) inplace of IN operator.
SELECT COUNT (1)
FROM SYSADM.OHR_PERS_CURR PC
, SYSADM.OHR_JOB_CURR JC
WHERE PC.EMPL_ID = JC.EMPL_ID
AND (JC.EMPL_ID, JC.EMPL_RCD) in (
SELECT HS.EMPL_ID, HS.EMPL_RCD
FROM SYSADM.HU_SCRTY_JOB HS, ODSHR.OHR_SCRTY_USER_CFG OS
WHERE HS.HU_SCRTY_CFG_ID = OS.HU_SCRTY_CFG_ID
AND OS.DB_LOGIN = USER)
Thank you.SELECT COUNT (1)
FROM SYSADM.OHR_PERS_CURR PC
, SYSADM.OHR_JOB_CURR JC
WHERE PC.EMPL_ID = JC.EMPL_ID
AND EXISTS (
SELECT null
FROM SYSADM.HU_SCRTY_JOB HS, ODSHR.OHR_SCRTY_USER_CFG OS
WHERE HS.HU_SCRTY_CFG_ID = OS.HU_SCRTY_CFG_ID
AND OS.DB_LOGIN = USER
AND HS.EMPL_ID = JS.EMPL_ID AND HS.EMPL_RCD = JC.EMPL_RCD)
But why ?
Rgds. -
HI I see that by the use of exists clause while joining
1) oralce provides a better execution plan ... and 2) it eliminates duplicates automatically
but my question is how to access the columns of the inner tables in the select clause ?
EG:
select a.sno, b.course_name
from a,b
where a.cid=b.cid
----------------------in the below query How do i access b.course_name in the select clause? similarly even if it contains more tables nested, i should be able to access the column of the inner tables from the select clause . How to do this . hope i am clear
select a.sno from a where exists ( select 1 from b where b.cid=a.cid)You cannot access columns from tables in an EXISTS (or NOT EXISTS) clause outside of that clause. You can only select data from tables (and other objects) that you are actually selecting from.
Justin -
Spatial query inside the exists clause return ora-13226
The following does not work:
select b.state, b.county from counties b where exists
(select 's' from states a where a.state = 'New Jersey'
and mdsys.sdo_relate (b.geom, a.geom, 'mask=INSIDE querytype=WINDOW' ) = 'TRUE');
ERROR at line 1:
ORA-13226: interface not supported without a spatial index
ORA-06512: at "MDSYS.MD", line 1723
ORA-06512: at "MDSYS.MDERR", line 8
ORA-06512: at "MDSYS.SDO_3GL", line 302
ORA-06512: at line 1
The following does work:
select b.* from states a,
counties b where a.state = 'New Jersey'
and mdsys.sdo_relate (b.geom, a.geom, 'mask=INSIDE querytype=WINDOW') = 'TRUE';
I found bug 1243095 telling that this is not a bug but a limitation of the spatial operator. It cannot be invoked on a table that is not spatially indexed. In fact, the table is indexed but oracle cannot find the spatial index because table b(counties) is declared outside the EXISTS clause.
In my case, I use object table. I cannot use the workaround specified above because I should use the DISTINCT clause but I cannot define the MAP and ORDER function (this is a general query).
I've found another workaround :
select b.state, b.county from counties b where exists
(select 's' from states a where a.state = 'New Jersey'
and mdsys.sdo_relate (a.geom, b.geom, 'mask=CONTAINS querytype=WINDOW') = 'TRUE');
but sdo_relate still doesn't use the spatial index of table b (even if I specify it explicitely in the operator) and the query is very slow (more than 15 minutes).
Is there a better workaround ?OK but I work in object model.
And if I don't use the EXISTS clause, I must use the distinct clause.(I used the exists because of that)
If I will to retrieve all the country that have at least a state beginning with the C letter, I will wrote :
select c.* from country c, table(c.states) s where s.column_value.name like 'C%';
(It is a simplified request to express the problem)
In this case, I must use the distinct clause to select one occurence of each country objet (one country may contains more than one state beginning with C).
select distinct c.* from country c, table(c.states) s where s.column_value.name like 'C%';
For that, I must define a MAP or ORDER function for EACH type used in the country object.
My first question is : I must retrieve all different country objects. Why the request doesn't use the MAP or ORDER function of the country type to distinct them ? Is there another syntax (or a hint) to express that ?
In this case, it will make an ORA-00932 : incoherent datatype because the type of the nested table column cannot contain map or order method.
Any suggestion ?
Thanks in advance. -
Execution of subquery of IN and EXISTS clause.
Hi Friends,
Suppose we have following two tables:
emp
empno number
ename varchar2(100)
deptno number
salary number
dept
deptno number
location varchar2(100)
deptname varchar2(100)
status varchar2(100)
Where dept is the master table for emp.
Following query is fine to me:
SELECT empno, ename
FROM emp,dept
WHERE emp.deptno = dept.deptno
AND emp.salary >=5000
AND dept.status = 'ACTIVE';
But I want to understand the behaviour of inline query (Used with IN and EXISTS clause) for which I have used this tables as an example (Just as Demo).
1)
Suppose we rewrite the above query as following:
SELECT empno, ename
FROM emp
WHERE emp.salary >=5000
AND deptno in (SELECT deptno FROM dept where status = 'ACTIVE')
Question: as shown in above query, suppose in our where clause, we have a condition with IN construct whose subquery is independent (it is not using any column of master query's resultset.). Then, will that query be executed only once or will it be executed for N number of times (N= number of records in emp table)
In other words, how may times the subquery of IN clause as in above query be executed by complier to prepared the subquery's resultset?
2)
Suppose the we use the EXISTS clause (or NOT EXISTS clause) with subquery where, the subquery uses the field of master query in its where clause.
SELECT E.empno, E.ename
FROM emp E
WHERE E.salary >=5000
AND EXISTS (SELECT 'X' FROM dept D where status = 'ACTIVE' AND D.deptno = E.deptno)
Here also, I got same confusion. For how many times the subquery for EXISTS will be executed by oracle. For one time or for N number of times (I think, it will be N number of times).
3)
I know we can't define any fix thumbrule and its highly depends on requirement and other factors, but in general, Suppose our main query is on heavily loaded large transaction table and need to check existance of record in some less loaded and somewhat smaller transaction table, than which way will be better from performance point of view from above three. (1. Use of JOIN, 2. Use of IN, 3. Use of EXISTS)
Please help me get solutions to these confusions..
Thanks and Regards,
Dipali..Dipali,
First, I posted the links with my name only, I don;t know how did you pick another handle for addressing it?Never mind that.
>
Now another confusion I got.. I read that even if we used EXISTS and , CBO feels (from statistics and all his analysis) that using IN would be more efficient, than it will rewrite the query. My confusion is that, If CBO is smart enough to rewrite the query in its most efficient form, Is there any scope/need for a Developer/DBA to do SQL/Query tuning? Does this means that now , developer need not to work hard to write query in best menner, instade just what he needs to do is to write the query which resluts the data required by him..? Does this now mean that now no eperts are required for SQL tuning?
>
Where did you read that?Its good to see the reference which says this.I haven't come across any such thing where CBO will rewrite the query like this. Have a look at the following query.What we want to do is to get the list of all teh departments which have atleast one employee working in it.So how would be we write this query? Theremay be many ways.One,out of them is to use distinct.Let's see how it works,
SQL> select * from V$version;
BANNER
Oracle Database 11g Enterprise Edition Release 11.1.0.6.0 - Production
PL/SQL Release 11.1.0.6.0 - Production
CORE 11.1.0.6.0 Production
TNS for 32-bit Windows: Version 11.1.0.6.0 - Production
NLSRTL Version 11.1.0.6.0 - Production
SQL> set timing on
SQL> set autot trace exp
SQL> SELECT distinct D.deptno, D.dname
2 FROM scott.dept D,scott.emp E
3 where e.deptno=d.deptno
4 order by d.deptno;
Elapsed: 00:00:00.12
Execution Plan
Plan hash value: 925733878
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)| T
ime |
| 0 | SELECT STATEMENT | | 9 | 144 | 7 (29)| 0
0:00:01 |
| 1 | SORT UNIQUE | | 9 | 144 | 7 (29)| 0
0:00:01 |
| 2 | MERGE JOIN | | 14 | 224 | 6 (17)| 0
0:00:01 |
| 3 | TABLE ACCESS BY INDEX ROWID| DEPT | 4 | 52 | 2 (0)| 0
0:00:01 |
| 4 | INDEX FULL SCAN | PK_DEPT | 4 | | 1 (0)| 0
0:00:01 |
|* 5 | SORT JOIN | | 14 | 42 | 4 (25)| 0
0:00:01 |
| 6 | TABLE ACCESS FULL | EMP | 14 | 42 | 3 (0)| 0
0:00:01 |
Predicate Information (identified by operation id):
5 - access("E"."DEPTNO"="D"."DEPTNO")
filter("E"."DEPTNO"="D"."DEPTNO")
SQL>
SQL> SELECT distinct D.deptno, D.dname
2 FROM scott.dept D,scott.emp E
3 where e.deptno=d.deptno
4 order by d.deptno;
DEPTNO DNAME
10 ACCOUNTING
20 RESEARCH
30 SALES
Elapsed: 00:00:00.04
SQL>So CBO did what we asked it do so.It made a full sort merge join.Now there is nothing wrong in it.There is no intelligence added by CBO to it.So now what, the query looks okay isn't it.If the answer is yes than let's finish the talk here.If no than we proceed further.
We deliberately used the term "atleast" here.This would govern that we are not looking for entirely matching both the sources, emp and dept.Any matching result should solve our query's result.So , with "our knowledge" , we know that Exist can do that.Let's write teh query by it and see,
SQL> SELECT D.deptno, D.dname
2 FROM scott.dept D
3 WHERE EXISTS
4 (SELECT 1
5 FROM scott.emp E
6 WHERE E.deptno = D.deptno)
7 ORDER BY D.deptno;
DEPTNO DNAME
10 ACCOUNTING
20 RESEARCH
30 SALES
Elapsed: 00:00:00.00
SQL>Wow, that's same but there is a small difference in the timing.Note that I did run the query several times to elliminate the physical reads and recursive calls to effect the demo. So its the same result, let's see the plan.
SQL> SELECT D.deptno, D.dname
2 FROM scott.dept D
3 WHERE EXISTS
4 (SELECT 1
5 FROM scott.emp E
6 WHERE E.deptno = D.deptno)
7 ORDER BY D.deptno;
Elapsed: 00:00:00.00
Execution Plan
Plan hash value: 1090737117
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Ti
me |
| 0 | SELECT STATEMENT | | 3 | 48 | 6 (17)| 00
:00:01 |
| 1 | MERGE JOIN SEMI | | 3 | 48 | 6 (17)| 00
:00:01 |
| 2 | TABLE ACCESS BY INDEX ROWID| DEPT | 4 | 52 | 2 (0)| 00
:00:01 |
| 3 | INDEX FULL SCAN | PK_DEPT | 4 | | 1 (0)| 00
:00:01 |
|* 4 | SORT UNIQUE | | 14 | 42 | 4 (25)| 00
:00:01 |
| 5 | TABLE ACCESS FULL | EMP | 14 | 42 | 3 (0)| 00
:00:01 |
Predicate Information (identified by operation id):
4 - access("E"."DEPTNO"="D"."DEPTNO")
filter("E"."DEPTNO"="D"."DEPTNO")Can you see a keyword called Semi here? This means that Oralce did make an equi join but not complete.Compare the bytes/rows returned from this as well as cost with the first query.Can you notice the difference?
So what do we get from all this?You asked that if CBO becomes so smart, won't we need developers/dbas at that time?The answer is , what one wants to be, a monkey or an astranaut? Confused,read this,
http://www.method-r.com/downloads/doc_download/6-the-oracle-advisors-from-a-different-perspective-karen-morton
So it won't matter how much CBO would become intelligent, there will be still limitations to where it can go, what it can do.There will always be a need for a human to look all the automations.Rememember even the most sofisticated system needs some button to be pressed to get it on which is done by a human hand's finger ;-).
Happy new year!
HTH
Aman.... -
Re: adding Union clause to existing seeded VO
Hi all,
we have a requirement to add union clause to existing VO which is standard one.. please help me if it is possible...
regards,
Raghava.Hi,
Following is the error stack for the code i wrote above....
we have a standard EO based VO and we need to add union clause to the VO query.. is there any approach to achieve this except extending VO?
The VO query is...
SELECT pca.COST_ALLOCATION_ID,
pca.EFFECTIVE_START_DATE,
pca.EFFECTIVE_END_DATE,
pca.BUSINESS_GROUP_ID,
pca.COST_ALLOCATION_KEYFLEX_ID,
pca.ASSIGNMENT_ID,
pca.PROPORTION as proportion,
pca.REQUEST_ID,
pca.PROGRAM_APPLICATION_ID,
pca.PROGRAM_ID,
pca.PROGRAM_UPDATE_DATE,
pca.LAST_UPDATE_DATE,
pca.LAST_UPDATED_BY,
pca.LAST_UPDATE_LOGIN,
pca.CREATED_BY,
pca.CREATION_DATE,
pca.OBJECT_VERSION_NUMBER,
pca.ROWID
FROM PAY_COST_ALLOCATIONS_F pca
WHERE to_date(:1,'YYYY-MM-DD') between effective_start_date and effective_end_date and :2 = assignment_id
The Union Clause needed is
and 1 = 2
union
(select cost_allocation_flex_id,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null from test_table)
I tried it thru CO as below...
OAApplicationModule oa =(OAApplicationModule) oapagecontext.getApplicationModule(oawebbean);
OAViewObject vo = (OAViewObject)oa.findViewObject("CostingEntryDetailVO");
String whereclause ="COST_ALLOCATION_KEYFLEX_ID=6217) " +
" AND 1=2 " +
" union (( select cost_allocation_flex_id,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null from test_table )";
if (vo!=null)
vo.setWhereClause(whereclause);
vo.executeQuery();
The error stack is:
oracle.apps.fnd.framework.OAException: oracle.jbo.SQLStmtException: JBO-27122: SQL error during statement preparation. Statement: SELECT * FROM (SELECT pca.COST_ALLOCATION_ID,
pca.EFFECTIVE_START_DATE,
pca.EFFECTIVE_END_DATE,
pca.BUSINESS_GROUP_ID,
pca.COST_ALLOCATION_KEYFLEX_ID,
pca.ASSIGNMENT_ID,
pca.PROPORTION as proportion,
pca.REQUEST_ID,
pca.PROGRAM_APPLICATION_ID,
pca.PROGRAM_ID,
pca.PROGRAM_UPDATE_DATE,
pca.LAST_UPDATE_DATE,
pca.LAST_UPDATED_BY,
pca.LAST_UPDATE_LOGIN,
pca.CREATED_BY,
pca.CREATION_DATE,
pca.OBJECT_VERSION_NUMBER,
pca.ROWID
FROM PAY_COST_ALLOCATIONS_F pca
WHERE to_date(:1,'YYYY-MM-DD') between effective_start_date and effective_end_date and :2 = assignment_id) QRSLT WHERE (nullCOST_ALLOCATION_KEYFLEX_ID=6217 AND 1=2 union (( select cost_allocation_flex_id,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null from test_table )) ORDER BY effective_start_date
at oracle.apps.fnd.framework.OAException.wrapperException(OAException.java:896)
at oracle.apps.fnd.framework.webui.OAWebBeanHelper.processRequest(OAWebBeanHelper.java:612)
at oracle.apps.fnd.framework.webui.OAWebBeanContainerHelper.processRequest(OAWebBeanContainerHelper.java:251)
at oracle.apps.fnd.framework.webui.OAPageLayoutHelper.processRequest(OAPageLayoutHelper.java:1166)
at oracle.apps.fnd.framework.webui.beans.layout.OAPageLayoutBean.processRequest(OAPageLayoutBean.java:1569)
at oracle.apps.fnd.framework.webui.OAWebBeanHelper.processRequestChildren(OAWebBeanHelper.java:964)
at oracle.apps.fnd.framework.webui.OAWebBeanHelper.processRequestChildren(OAWebBeanHelper.java:931)
at oracle.apps.fnd.framework.webui.OAWebBeanHelper.processRequest(OAWebBeanHelper.java:655)
at oracle.apps.fnd.framework.webui.OAWebBeanContainerHelper.processRequest(OAWebBeanContainerHelper.java:251)
at oracle.apps.fnd.framework.webui.beans.form.OAFormBean.processRequest(OAFormBean.java:385)
at oracle.apps.fnd.framework.webui.OAWebBeanHelper.processRequestChildren(OAWebBeanHelper.java:964)
at oracle.apps.fnd.framework.webui.OAWebBeanHelper.processRequestChildren(OAWebBeanHelper.java:931)
at oracle.apps.fnd.framework.webui.OAWebBeanHelper.processRequest(OAWebBeanHelper.java:655)
at oracle.apps.fnd.framework.webui.OAWebBeanContainerHelper.processRequest(OAWebBeanContainerHelper.java:251)
at oracle.apps.fnd.framework.webui.beans.OABodyBean.processRequest(OABodyBean.java:353)
at oracle.apps.fnd.framework.webui.OAPageBean.processRequest(OAPageBean.java:2513)
at oracle.apps.fnd.framework.webui.OAPageBean.preparePage(OAPageBean.java:1894)
at oracle.apps.fnd.framework.webui.OAPageBean.preparePage(OAPageBean.java:538)
at oracle.apps.fnd.framework.webui.OAPageBean.preparePage(OAPageBean.java:426)
at OA.jspService(_OA.java:212)
at com.orionserver.http.OrionHttpJspPage.service(OrionHttpJspPage.java:59)
at oracle.jsp.runtimev2.JspPageTable.service(JspPageTable.java:379)
at oracle.jsp.runtimev2.JspServlet.internalService(JspServlet.java:594)
at oracle.jsp.runtimev2.JspServlet.service(JspServlet.java:518)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:856)
at com.evermind.server.http.ServletRequestDispatcher.invoke(ServletRequestDispatcher.java:713)
at com.evermind.server.http.ServletRequestDispatcher.forwardInternal(ServletRequestDispatcher.java:370)
at com.evermind.server.http.ServletRequestDispatcher.unprivileged_forward(ServletRequestDispatcher.java:259)
at com.evermind.server.http.ServletRequestDispatcher.access$100(ServletRequestDispatcher.java:51)
at com.evermind.server.http.ServletRequestDispatcher$2.oc4jRun(ServletRequestDispatcher.java:193)
at oracle.oc4j.security.OC4JSecurity.doPrivileged(OC4JSecurity.java:284)
at com.evermind.server.http.ServletRequestDispatcher.forward(ServletRequestDispatcher.java:198)
at com.evermind.server.http.EvermindPageContext.forward(EvermindPageContext.java:395)
at OA.jspService(_OA.java:221)
at com.orionserver.http.OrionHttpJspPage.service(OrionHttpJspPage.java:59)
at oracle.jsp.runtimev2.JspPageTable.service(JspPageTable.java:379)
at oracle.jsp.runtimev2.JspServlet.internalService(JspServlet.java:594)
at oracle.jsp.runtimev2.JspServlet.service(JspServlet.java:518)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:856)
at com.evermind.server.http.ResourceFilterChain.doFilter(ResourceFilterChain.java:64)
at oracle.apps.jtf.base.session.ReleaseResFilter.doFilter(ReleaseResFilter.java:26)
at com.evermind.server.http.EvermindFilterChain.doFilter(EvermindFilterChain.java:15)
at oracle.apps.fnd.security.AppsServletFilter.doFilter(AppsServletFilter.java:318)
at com.evermind.server.http.ServletRequestDispatcher.invoke(ServletRequestDispatcher.java:621)
at com.evermind.server.http.ServletRequestDispatcher.forwardInternal(ServletRequestDispatcher.java:370)
at com.evermind.server.http.HttpRequestHandler.doProcessRequest(HttpRequestHandler.java:871)
at com.evermind.server.http.HttpRequestHandler.processRequest(HttpRequestHandler.java:453)
at com.evermind.server.http.AJPRequestHandler.run(AJPRequestHandler.java:313)
at com.evermind.server.http.AJPRequestHandler.run(AJPRequestHandler.java:199)
at oracle.oc4j.network.ServerSocketReadHandler$SafeRunnable.run(ServerSocketReadHandler.java:260)
at com.evermind.util.ReleasableResourcePooledExecutor$MyWorker.run(ReleasableResourcePooledExecutor.java:303)
at java.lang.Thread.run(Thread.java:619)
## Detail 0 ##
java.sql.SQLSyntaxErrorException: ORA-00907: missing right parenthesis
at oracle.jdbc.driver.SQLStateMapping.newSQLException(SQLStateMapping.java:91)
at oracle.jdbc.driver.DatabaseError.newSQLException(DatabaseError.java:133)
at oracle.jdbc.driver.DatabaseError.throwSqlException(DatabaseError.java:206)
at oracle.jdbc.driver.T4CTTIoer.processError(T4CTTIoer.java:455)
at oracle.jdbc.driver.T4CTTIoer.processError(T4CTTIoer.java:413)
at oracle.jdbc.driver.T4C8Oall.receive(T4C8Oall.java:1034)
at oracle.jdbc.driver.T4CPreparedStatement.doOall8(T4CPreparedStatement.java:194)
at oracle.jdbc.driver.T4CPreparedStatement.executeForDescribe(T4CPreparedStatement.java:791)
at oracle.jdbc.driver.T4CPreparedStatement.executeMaybeDescribe(T4CPreparedStatement.java:866)
at oracle.jdbc.driver.OracleStatement.doExecuteWithTimeout(OracleStatement.java:1189)
at oracle.jdbc.driver.OraclePreparedStatement.executeInternal(OraclePreparedStatement.java:3387)
at oracle.jdbc.driver.OraclePreparedStatement.executeQuery(OraclePreparedStatement.java:3431)
at oracle.jdbc.driver.OraclePreparedStatementWrapper.executeQuery(OraclePreparedStatementWrapper.java:1491)
at oracle.jbo.server.QueryCollection.buildResultSet(QueryCollection.java:860)
at oracle.jbo.server.QueryCollection.executeQuery(QueryCollection.java:669)
at oracle.jbo.server.ViewObjectImpl.executeQueryForCollection(ViewObjectImpl.java:3723)
at oracle.jbo.server.OAJboViewObjectImpl.executeQueryForCollection(Unknown Source)
at oracle.apps.fnd.framework.server.OAViewObjectImpl.executeQueryForCollection(OAViewObjectImpl.java:4559)
at oracle.jbo.server.ViewRowSetImpl.execute(ViewRowSetImpl.java:743)
at oracle.jbo.server.ViewRowSetImpl.executeQueryForMasters(ViewRowSetImpl.java:892)
at oracle.jbo.server.ViewRowSetImpl.executeQueryForMode(ViewRowSetImpl.java:806)
at oracle.jbo.server.ViewRowSetImpl.executeQuery(ViewRowSetImpl.java:800)
at oracle.jbo.server.ViewObjectImpl.executeQuery(ViewObjectImpl.java:3643)
at oracle.apps.fnd.framework.server.OAViewObjectImpl.executeQuery(OAViewObjectImpl.java:439)
at genus.oracle.apps.pay.selfservice.assignmentcosting.webui.xxxAssignmentCostingEntryCO.processRequest(xxxAssignmentCostingEntryCO.java:80)
at oracle.apps.fnd.framework.webui.OAWebBeanHelper.processRequest(OAWebBeanHelper.java:596)
at oracle.apps.fnd.framework.webui.OAWebBeanContainerHelper.processRequest(OAWebBeanContainerHelper.java:251)
at oracle.apps.fnd.framework.webui.OAPageLayoutHelper.processRequest(OAPageLayoutHelper.java:1166)
at oracle.apps.fnd.framework.webui.beans.layout.OAPageLayoutBean.processRequest(OAPageLayoutBean.java:1569)
at oracle.apps.fnd.framework.webui.OAWebBeanHelper.processRequestChildren(OAWebBeanHelper.java:964)
at oracle.apps.fnd.framework.webui.OAWebBeanHelper.processRequestChildren(OAWebBeanHelper.java:931)
at oracle.apps.fnd.framework.webui.OAWebBeanHelper.processRequest(OAWebBeanHelper.java:655)
at oracle.apps.fnd.framework.webui.OAWebBeanContainerHelper.processRequest(OAWebBeanContainerHelper.java:251)
at oracle.apps.fnd.framework.webui.beans.form.OAFormBean.processRequest(OAFormBean.java:385)
at oracle.apps.fnd.framework.webui.OAWebBeanHelper.processRequestChildren(OAWebBeanHelper.java:964)
at oracle.apps.fnd.framework.webui.OAWebBeanHelper.processRequestChildren(OAWebBeanHelper.java:931)
at oracle.apps.fnd.framework.webui.OAWebBeanHelper.processRequest(OAWebBeanHelper.java:655)
at oracle.apps.fnd.framework.webui.OAWebBeanContainerHelper.processRequest(OAWebBeanContainerHelper.java:251)
at oracle.apps.fnd.framework.webui.beans.OABodyBean.processRequest(OABodyBean.java:353)
at oracle.apps.fnd.framework.webui.OAPageBean.processRequest(OAPageBean.java:2513)
at oracle.apps.fnd.framework.webui.OAPageBean.preparePage(OAPageBean.java:1894)
at oracle.apps.fnd.framework.webui.OAPageBean.preparePage(OAPageBean.java:538)
at oracle.apps.fnd.framework.webui.OAPageBean.preparePage(OAPageBean.java:426)
at OA.jspService(_OA.java:212)
at com.orionserver.http.OrionHttpJspPage.service(OrionHttpJspPage.java:59)
at oracle.jsp.runtimev2.JspPageTable.service(JspPageTable.java:379)
at oracle.jsp.runtimev2.JspServlet.internalService(JspServlet.java:594)
at oracle.jsp.runtimev2.JspServlet.service(JspServlet.java:518)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:856)
at com.evermind.server.http.ServletRequestDispatcher.invoke(ServletRequestDispatcher.java:713)
at com.evermind.server.http.ServletRequestDispatcher.forwardInternal(ServletRequestDispatcher.java:370)
at com.evermind.server.http.ServletRequestDispatcher.unprivileged_forward(ServletRequestDispatcher.java:259)
at com.evermind.server.http.ServletRequestDispatcher.access$100(ServletRequestDispatcher.java:51)
at com.evermind.server.http.ServletRequestDispatcher$2.oc4jRun(ServletRequestDispatcher.java:193)
at oracle.oc4j.security.OC4JSecurity.doPrivileged(OC4JSecurity.java:284)
at com.evermind.server.http.ServletRequestDispatcher.forward(ServletRequestDispatcher.java:198)
at com.evermind.server.http.EvermindPageContext.forward(EvermindPageContext.java:395)
at OA.jspService(_OA.java:221)
at com.orionserver.http.OrionHttpJspPage.service(OrionHttpJspPage.java:59)
at oracle.jsp.runtimev2.JspPageTable.service(JspPageTable.java:379)
at oracle.jsp.runtimev2.JspServlet.internalService(JspServlet.java:594)
at oracle.jsp.runtimev2.JspServlet.service(JspServlet.java:518)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:856)
at com.evermind.server.http.ResourceFilterChain.doFilter(ResourceFilterChain.java:64)
at oracle.apps.jtf.base.session.ReleaseResFilter.doFilter(ReleaseResFilter.java:26)
at com.evermind.server.http.EvermindFilterChain.doFilter(EvermindFilterChain.java:15)
at oracle.apps.fnd.security.AppsServletFilter.doFilter(AppsServletFilter.java:318)
at com.evermind.server.http.ServletRequestDispatcher.invoke(ServletRequestDispatcher.java:621)
at com.evermind.server.http.ServletRequestDispatcher.forwardInternal(ServletRequestDispatcher.java:370)
at com.evermind.server.http.HttpRequestHandler.doProcessRequest(HttpRequestHandler.java:871)
at com.evermind.server.http.HttpRequestHandler.processRequest(HttpRequestHandler.java:453)
at com.evermind.server.http.AJPRequestHandler.run(AJPRequestHandler.java:313)
at com.evermind.server.http.AJPRequestHandler.run(AJPRequestHandler.java:199)
at oracle.oc4j.network.ServerSocketReadHandler$SafeRunnable.run(ServerSocketReadHandler.java:260)
at com.evermind.util.ReleasableResourcePooledExecutor$MyWorker.run(ReleasableResourcePooledExecutor.java:303)
at java.lang.Thread.run(Thread.java:619)
java.sql.SQLSyntaxErrorException: ORA-00907: missing right parenthesis
at oracle.jdbc.driver.SQLStateMapping.newSQLException(SQLStateMapping.java:91)
at oracle.jdbc.driver.DatabaseError.newSQLException(DatabaseError.java:133)
at oracle.jdbc.driver.DatabaseError.throwSqlException(DatabaseError.java:206)
at oracle.jdbc.driver.T4CTTIoer.processError(T4CTTIoer.java:455)
at oracle.jdbc.driver.T4CTTIoer.processError(T4CTTIoer.java:413)
at oracle.jdbc.driver.T4C8Oall.receive(T4C8Oall.java:1034)
at oracle.jdbc.driver.T4CPreparedStatement.doOall8(T4CPreparedStatement.java:194)
at oracle.jdbc.driver.T4CPreparedStatement.executeForDescribe(T4CPreparedStatement.java:791)
at oracle.jdbc.driver.T4CPreparedStatement.executeMaybeDescribe(T4CPreparedStatement.java:866)
at oracle.jdbc.driver.OracleStatement.doExecuteWithTimeout(OracleStatement.java:1189)
at oracle.jdbc.driver.OraclePreparedStatement.executeInternal(OraclePreparedStatement.java:3387)
at oracle.jdbc.driver.OraclePreparedStatement.executeQuery(OraclePreparedStatement.java:3431)
at oracle.jdbc.driver.OraclePreparedStatementWrapper.executeQuery(OraclePreparedStatementWrapper.java:1491)
at oracle.jbo.server.QueryCollection.buildResultSet(QueryCollection.java:860)
at oracle.jbo.server.QueryCollection.executeQuery(QueryCollection.java:669)
at oracle.jbo.server.ViewObjectImpl.executeQueryForCollection(ViewObjectImpl.java:3723)
at oracle.jbo.server.OAJboViewObjectImpl.executeQueryForCollection(Unknown Source)
at oracle.apps.fnd.framework.server.OAViewObjectImpl.executeQueryForCollection(OAViewObjectImpl.java:4559)
at oracle.jbo.server.ViewRowSetImpl.execute(ViewRowSetImpl.java:743)
at oracle.jbo.server.ViewRowSetImpl.executeQueryForMasters(ViewRowSetImpl.java:892)
at oracle.jbo.server.ViewRowSetImpl.executeQueryForMode(ViewRowSetImpl.java:806)
at oracle.jbo.server.ViewRowSetImpl.executeQuery(ViewRowSetImpl.java:800)
at oracle.jbo.server.ViewObjectImpl.executeQuery(ViewObjectImpl.java:3643)
at oracle.apps.fnd.framework.server.OAViewObjectImpl.executeQuery(OAViewObjectImpl.java:439)
at genus.oracle.apps.pay.selfservice.assignmentcosting.webui.xxxAssignmentCostingEntryCO.processRequest(xxxAssignmentCostingEntryCO.java:80)
at oracle.apps.fnd.framework.webui.OAWebBeanHelper.processRequest(OAWebBeanHelper.java:596)
at oracle.apps.fnd.framework.webui.OAWebBeanContainerHelper.processRequest(OAWebBeanContainerHelper.java:251)
at oracle.apps.fnd.framework.webui.OAPageLayoutHelper.processRequest(OAPageLayoutHelper.java:1166)
at oracle.apps.fnd.framework.webui.beans.layout.OAPageLayoutBean.processRequest(OAPageLayoutBean.java:1569)
at oracle.apps.fnd.framework.webui.OAWebBeanHelper.processRequestChildren(OAWebBeanHelper.java:964)
at oracle.apps.fnd.framework.webui.OAWebBeanHelper.processRequestChildren(OAWebBeanHelper.java:931)
at oracle.apps.fnd.framework.webui.OAWebBeanHelper.processRequest(OAWebBeanHelper.java:655)
at oracle.apps.fnd.framework.webui.OAWebBeanContainerHelper.processRequest(OAWebBeanContainerHelper.java:251)
at oracle.apps.fnd.framework.webui.beans.form.OAFormBean.processRequest(OAFormBean.java:385)
at oracle.apps.fnd.framework.webui.OAWebBeanHelper.processRequestChildren(OAWebBeanHelper.java:964)
at oracle.apps.fnd.framework.webui.OAWebBeanHelper.processRequestChildren(OAWebBeanHelper.java:931)
at oracle.apps.fnd.framework.webui.OAWebBeanHelper.processRequest(OAWebBeanHelper.java:655)
at oracle.apps.fnd.framework.webui.OAWebBeanContainerHelper.processRequest(OAWebBeanContainerHelper.java:251)
at oracle.apps.fnd.framework.webui.beans.OABodyBean.processRequest(OABodyBean.java:353)
at oracle.apps.fnd.framework.webui.OAPageBean.processRequest(OAPageBean.java:2513)
at oracle.apps.fnd.framework.webui.OAPageBean.preparePage(OAPageBean.java:1894)
at oracle.apps.fnd.framework.webui.OAPageBean.preparePage(OAPageBean.java:538)
at oracle.apps.fnd.framework.webui.OAPageBean.preparePage(OAPageBean.java:426)
at OA.jspService(_OA.java:212)
at com.orionserver.http.OrionHttpJspPage.service(OrionHttpJspPage.java:59)
at oracle.jsp.runtimev2.JspPageTable.service(JspPageTable.java:379)
at oracle.jsp.runtimev2.JspServlet.internalService(JspServlet.java:594)
at oracle.jsp.runtimev2.JspServlet.service(JspServlet.java:518)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:856)
at com.evermind.server.http.ServletRequestDispatcher.invoke(ServletRequestDispatcher.java:713)
at com.evermind.server.http.ServletRequestDispatcher.forwardInternal(ServletRequestDispatcher.java:370)
at com.evermind.server.http.ServletRequestDispatcher.unprivileged_forward(ServletRequestDispatcher.java:259)
at com.evermind.server.http.ServletRequestDispatcher.access$100(ServletRequestDispatcher.java:51)
at com.evermind.server.http.ServletRequestDispatcher$2.oc4jRun(ServletRequestDispatcher.java:193)
at oracle.oc4j.security.OC4JSecurity.doPrivileged(OC4JSecurity.java:284)
at com.evermind.server.http.ServletRequestDispatcher.forward(ServletRequestDispatcher.java:198)
at com.evermind.server.http.EvermindPageContext.forward(EvermindPageContext.java:395)
at OA.jspService(_OA.java:221)
at com.orionserver.http.OrionHttpJspPage.service(OrionHttpJspPage.java:59)
at oracle.jsp.runtimev2.JspPageTable.service(JspPageTable.java:379)
at oracle.jsp.runtimev2.JspServlet.internalService(JspServlet.java:594)
at oracle.jsp.runtimev2.JspServlet.service(JspServlet.java:518)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:856)
at com.evermind.server.http.ResourceFilterChain.doFilter(ResourceFilterChain.java:64)
at oracle.apps.jtf.base.session.ReleaseResFilter.doFilter(ReleaseResFilter.java:26)
at com.evermind.server.http.EvermindFilterChain.doFilter(EvermindFilterChain.java:15)
at oracle.apps.fnd.security.AppsServletFilter.doFilter(AppsServletFilter.java:318)
at com.evermind.server.http.ServletRequestDispatcher.invoke(ServletRequestDispatcher.java:621)
at com.evermind.server.http.ServletRequestDispatcher.forwardInternal(ServletRequestDispatcher.java:370)
at com.evermind.server.http.HttpRequestHandler.doProcessRequest(HttpRequestHandler.java:871)
at com.evermind.server.http.HttpRequestHandler.processRequest(HttpRequestHandler.java:453)
at com.evermind.server.http.AJPRequestHandler.run(AJPRequestHandler.java:313)
at com.evermind.server.http.AJPRequestHandler.run(AJPRequestHandler.java:199)
at oracle.oc4j.network.ServerSocketReadHandler$SafeRunnable.run(ServerSocketReadHandler.java:260)
at com.evermind.util.ReleasableResourcePooledExecutor$MyWorker.run(ReleasableResourcePooledExecutor.java:303)
at java.lang.Thread.run(Thread.java:619) -
Helllo All,
One Order (table oe_order_headers_all ) can have mulitple lines(table oe_order_lines_all) associated with it.
Both tables are joined with header_id.
Now I need to run a query for a specific date range. suppose i gave both date parameters as 26-mar-10.
Then the orders that are shipped on 26th only should come.
Here let say few lines shipped on 26th and the final lines got shipped on 27th mar
So if i ran the query for 26th march then we should not get the data.
If i ran for 27th mar then i should get the data.
(Only when all lines got shipped then on that date i should get data)
Below is th sample query. which i wrote(only i need to modify the exist clause here)
Actually i have problem with Exist Clause.Exist clause should be written to meet the above said condition.
Select ooh.* from oe_order_headers_all ooh
where 1=1
and
EXISTS (
( SELECT 1
from apps.oe_order_lines l
where l.header_id = ooh.header_id and
trunc (l.shipment_date ) >= nvl (:DATE_FROM ,
trunc (l.shipment_date ) )
and trunc (l.shipment_date ) <= nvl ( :DATE_TO,
trunc ( l.shipment_date ) )
)You do not need exists for that:
select ooh.*
from oe_order_headers_all ooh,
select header_id
from apps.oe_order_lines
group by header_id
having max(shipment_date) < nvl(:DATE_TO,shipment_date) + 1
and min(shipment_date) >= nvl(:DATE_FROM,shipment_date)
) l
where l.header_id = ooh.header_id
/SY. -
I have seen in some of the posts that using 'EXISTS' clause in place of 'IN' yields better performance results.
For example
update customer
set type = 'emp'
where cid in (select empid from employees)
I have 1 million rows in customer and 500k rows in employee table in this case is it better to use 'EXISTS' instead of 'IN' clause. Also does datatype of the column have effect on the type of clause being used.
Any suggestions/inputs ???
ThanksAndre Crone recently published some interesting thoughts on the Amis blog. Check it out.
Cheers, APC -
Where Exist clause to improve query performance
select * from emp
where emp_code in (select emp_code from emp_acct)
it is said tht its always better to use where exist clause instead of IN.
I hav written the same query using where Exist,
select * from emp e
where exists (select null from emp_acct ea where e.emp_code = ea.emp_acct)
but both these queries are sharing the same cost.
is there is any other way to use exist to decrease cost of the query.
---PiyushYou can't compare the cost of two different queries.
You can't relate cost to the running time of the query.
Having said that, why is this not just a join?
select e.*
from emp e
, emp_acct ea
where e.emp_code = ea.emp_codecheers,
Anthony -
Update statement with EXISTS clause
I saw this code in one of the procedures we are using ... is it possible to avoid EXIST caluse:
update table_x p
set p.internal_issue_ky = (select sh.internal_issue_ky
from security_history sh, XT_SECURITY xs
where sh.internal_wins_issue_id = xs.internal_wins_issue_id
and sh.as_of_dt = xs.as_of_date
and p.internal_wins_issue_id = sh.internal_wins_issue_id
and p.effective_dt between sh.as_of_dt and sh.next_as_of_dt
where exists
(select sh.internal_issue_ky
from security_history sh, XT_SECURITY xs
where sh.internal_wins_issue_id = xs.internal_wins_issue_id
and sh.as_of_dt = xs.as_of_date
and p.internal_wins_issue_id = sh.internal_wins_issue_id
and p.effective_dt between sh.as_of_dt and sh.next_as_of_dt
Thanks.Without the EXISTS, every record in the table will be updated, and those that don't exist in the subquery will be updated with NULL. The EXIST clause ensures that only those records that form the subset in the subquery are updated, and is necessary here.
-
Bug in WITH clause (subquery factoring clause) in Oracle 11?
I'm using WITH to perform a set comparison in order to qualify a given query as correct or incorrect regarding an existing solution. However, the query does not give the expected result - an empty set - when comparing the solution to itself in Oracle 11 whereas it does in Oracle 10. A minimal example os posted below as script. There are also some observations about changes to the tables or the query that make Oracle 11 returning correct results but in my opinion these changes must not change the semantics of the queries.
Is this a bug or am I getting something wrong? The Oracle versions are mentioned in the script.
-- Bug in WITH clause (subquery factoring clause)
-- in Oracle Database 11g Enterprise Edition 11.2.0.1.0?
DROP TABLE B PURGE;
DROP TABLE K PURGE;
DROP TABLE S PURGE;
CREATE TABLE S (
m number NOT NULL,
x varchar2(30) NOT NULL
CREATE TABLE K (
k char(2) NOT NULL,
x varchar2(50) NOT NULL
CREATE TABLE B (
m number NOT NULL ,
k char(2) NOT NULL ,
n number
INSERT INTO S VALUES(1, 'h');
INSERT INTO S VALUES(2, 'l');
INSERT INTO S VALUES(3, 'm');
INSERT INTO K VALUES('k1', 'd');
INSERT INTO K VALUES('k2', 'i');
INSERT INTO K VALUES('k3', 'm');
INSERT INTO K VALUES('k4', 't');
INSERT INTO K VALUES('k5', 't');
INSERT INTO K VALUES('k6', 's');
INSERT INTO B VALUES(1, 'k1', 40);
INSERT INTO B VALUES(1, 'k2', 30);
INSERT INTO B VALUES(1, 'k4', 50);
INSERT INTO B VALUES(3, 'k1', 10);
INSERT INTO B VALUES(3, 'k2', 20);
INSERT INTO B VALUES(3, 'k1', 30);
INSERT INTO B VALUES(3, 'k6', 90);
COMMIT;
ALTER TABLE S ADD CONSTRAINT S_pk PRIMARY KEY (m);
ALTER TABLE K ADD CONSTRAINT K_pk PRIMARY KEY (k);
ALTER TABLE B ADD CONSTRAINT B_S_fk
FOREIGN KEY (m) REFERENCES S(m) ON DELETE CASCADE;
CREATE OR REPLACE VIEW v AS
SELECT S.m, B.n
FROM S JOIN B ON S.m=B.m JOIN K ON B.k=K.k
WHERE K.x='d'
ORDER BY B.n DESC;
-- Query 1: Result should be 0
WITH q AS
SELECT S.m, B.n
FROM S JOIN B ON S.m=B.m JOIN K ON B.k=K.k
WHERE K.x='d'
ORDER BY B.n DESC
SELECT COUNT(*)
FROM
SELECT * FROM q
MINUS
SELECT * FROM v
UNION ALL
SELECT * FROM v
MINUS
SELECT * FROM q
-- COUNT(*)
-- 6
-- 1 rows selected
-- Query 2: Result set should be empty (Query 1 without counting)
WITH q AS
SELECT S.m, B.n
FROM S JOIN B ON S.m=B.m JOIN K ON B.k=K.k
WHERE K.x='d'
ORDER BY B.n DESC
SELECT *
FROM
SELECT * FROM q
MINUS
SELECT * FROM v
UNION ALL
SELECT * FROM v
MINUS
SELECT * FROM q
-- M N
-- null 10
-- null 30
-- null 40
-- 1 40
-- 3 10
-- 3 30
-- 6 rows selected
-- Observations:
-- Incorrect results in Oracle Database 11g Enterprise Edition 11.2.0.1.0:
-- Query 1 returns 6, Query 2 returns six rows.
-- Correct in Oracle Database 10g Enterprise Edition 10.2.0.1.0.
-- Correct without the foreign key.
-- Correct if attribute x is renamed in S or K.
-- Correct if attribute x is left out in S.
-- Correct without the ORDER BY clause in the definition of q.
-- Only two results if the primary key on K is left out.
-- Correct without any change if not using WITH but subqueries (see below).
-- Fixed queries
-- Query 1b: Result should be 0
SELECT COUNT(*)
FROM
SELECT * FROM
SELECT S.m, B.n
FROM S JOIN B ON S.m=B.m JOIN K ON B.k=K.k
WHERE K.x='d'
ORDER BY B.n DESC
MINUS
SELECT * FROM v
UNION ALL
SELECT * FROM v
MINUS
SELECT * FROM
SELECT S.m, B.n
FROM S JOIN B ON S.m=B.m JOIN K ON B.k=K.k
WHERE K.x='d'
ORDER BY B.n DESC
-- COUNT(*)
-- 0
-- 1 rows selected
-- Query 2b: Result set shoud be empty (Query 1b without counting)
SELECT *
FROM
SELECT * FROM
SELECT S.m, B.n
FROM S JOIN B ON S.m=B.m JOIN K ON B.k=K.k
WHERE K.x='d'
ORDER BY B.n DESC
MINUS
SELECT * FROM v
UNION ALL
SELECT * FROM v
MINUS
SELECT * FROM
SELECT S.m, B.n
FROM S JOIN B ON S.m=B.m JOIN K ON B.k=K.k
WHERE K.x='d'
ORDER BY B.n DESC
-- M N
-- 0 rows selectedYou're all gonna love this one.....
The WITH clause works. But not easily.
Go ahead, build the query, (as noted in a recent thread, I, too, always use views), set the grants and make sure DISCOVERER and EULOWNER have SELECT privs.
1. Log into Disco Admin as EULOWNER. Trust me.
2. Add the view as a folder to the business area.
3. Log into Disco Desktop as EULOWNER. Don't laugh. It gets better.
4. Build the workbook and the worksheet (or just the worksheet if apropos)
5. Set the appropriate "sharing" roles and such
6. Save the workbook to the database.
7. Save the workbook to your computer.
8. Log out of Desktop.
9. Log back into Desktop as whatever, whoever you usually are to work.
10. elect "open existing workbook"
11. Select icon for "open from my computer". See? I told you it would get better!
12. Open the save .dis file from your computer.
13. Save it to the database.
14. Open a web browser and from there, you're on your own.
Fortran in VMS. Much easier and faster. I'm convinced the proliferation of the web is a detriment to the world at large...On the other hand, I'm also waiting for the Dodgers to return to Brooklyn.
Maybe you are looking for
-
Lenovo System update installati​on fails
i think it fails to install the service. windows 7 64 bit. latest and greatest systemupdate503-2013-10-31.exe full installation logs here http://pastebin.com/rBVAWj51 thanks for the help. Solved! Go to Solution.
-
No options in print windows HP Laserjet P1505
Trying to print Quark 6.5 document and specify Screen Frequency on HP Laserjet P1505, but cannot access any print options. I think it is a missing PPD thing, and I can't find a PPD listed for the printer in Quark PPDs. Can anyone help please?
-
OS X Server 10.4.11 - OS X Server 10.5.5 - PDC - No Windows login
Hey there, we just upgraded a 10.4.11 Server to 10.5.5. Some little issues occured afterwards which we were possible to solve but one big problem remained. Before upgrading the server, Windows XP Clients and a Windows 2003 Server could use our OD use
-
PCR: Characteristics vs form interface
Hi, While creating a new PCR or modifying an existing PCR, I am not sure what to do with the Characteristcs in QISRSCENARIO. Is this the one used in SFP to do the drag and drop. In that case, what for is the interface. Can anyone pl explain. Regards
-
I have created a simple config file using something like: XMLEncoder e = new XMLEncoder( new BufferedOutputStream( new FileOutputStream("Config.xml"))); e.writeObject