OUTER JOIN 의 GUIDE LINE
제품 : ORACLE SERVER
작성날짜 : 2002-04-10
OUTER JOIN 에 대하여
====================
Purpose
Outer join의 효과과 이용방법에 대해 이해한다.
Explanation
1. 개념
다음의 용어에 대해 우선 살펴보자 :
1) outer-join column - symbol(+) 을 사용하는 column 이다 .
예를 들어 EMPNO(+) ,DEPT.DEPTNO(+) 는 outer join column들이다.
2) simple predicate - AND , OR,NOT 을 가지지 않는 단순한 관계표현으로
A=B 의 관계로 표현된다.
3) outer join predicate - 한개 이상의 outer join column 을 갖는 simple
predicate 이다.
2. OUTER JOIN 사용법 - RULES
outer join predicate 는 오직 1 table 의 column 들 만이 outer join
column 으로 이용되어져야 한다. 즉 한 single outer join predicate 의
모든 outer join column 은 모두 같은 table이어야 한다.
이런 취지에서 다음 statement 는 틀린 것이다.
EMP.EMPNO(+) = DEPT.DEPTNO(+)
이것은 두 table 의 outer join column 들이다.
한 predicate 의 한 column 이 outer join column 이면 같은 table 의 모든
column 은 outer join column 이어야 한다.
이 취지에서 다음 문장은 틀린 것이다.
EMP.SAL + EMP.COMM(+) = SALGRADE.HIGH
한 table 의 column 들이 outer join 것과 아닌 것과 outer join 인것으로
섞여있기 때문이다.
predicate 에서 (+) 표시가 붙은 table 은 다른 table 을 direct 하게
outer join 한다. indirect 하게 다른 tabe 을 outer join 한다는 것은
그들 table 자체가 또 outer join 하는 경우이다.
이 경우 한 table 은 direct하게든 indeirect 하게든 자기 자신에게 outer
join 하는 경우는 허용되지 않는다.
다음의 문장은 이런 취지에서 틀린 경우이다.
EMP.EMPNO(+) = PERS.EMPNO
AND PERS.DEPTNO(+) = DEPT.DEPTNO
AND DEPT.JOB(+) = EMP.JOB - circular outer
join relationship
3. OUTER JOIN 실행
주어진 table T 에는 outer join 과 non-outer join 이 있다.
실행시 다음처럼 수행된다.
1) The result of joining all tables mentioned in table T's
outer join predicates is formed ( by recursive application
of this algorithm ).
2) For each row of the result, a set of composite rows is
formed, each consisting of the original row in the
result joined to a row in table T for which the composite
row satisfies all of table T's outer join predicates.
3) If a set of composite rows is the null set, a composite
row is created consisting of the original row in the
result joined to a row similar to those in table T, but
with all values set to null.
4) Rows that do not pass the non-outer join predicates are removed.
This may be summarised as follows. Outer join
predicates ( those with (+) after a column of table T ), are
evaluated BEFORE table T is augmented with a null row. The null
row is added only if there are NO rows in table T that satisfy
the outer join predicates. Non-outer join predicates are
evaluated AFTER table T is augmented with a null row (if needed)
4. OUTER JOIN - RECOMMENDATIONS
Certain types of outer joins in complicated logical
expressions may not be well formed. In general, outer join
columns in predicates that are branches of an OR should be
avoided. Inconsistancies between the branches of the OR can
result in an ambiguous query, and this may not be detected. It
is best to confine outer join columns to the top level of the
'where' clause, or to nested AND's only.
5. OUTER JOIN - ILLUSTRATIVE EXAMPLES
1) Simple Outer Join
SELECT ENAME, LOC
FROM DEPT, EMP
WHERE DEPT.DEPTNO = EMP.DEPTNO(+)
The predicate is evaluated BEFORE null augmentation. If
there is a DEPT row for which there are no EMP rows, then a null
EMP row is concatenated to the DEPT row.
2) Outer Join With Simple Post-Join Predicates
SELECT ENAME, LOC
FROM DEPT, EMP
WHERE DEPT.DEPTNO = EMP.DEPTNO(+)
AND EMP.DEPTNO IS NULL
The second simple predicate is avaluated AFTER null
augmentation, since there is no (+), removing rows which were
not the result of null augmentation and hence leaving only DEPT
rows for which there was no corresponding EMP row.
3) Outer Join With Additional Pre-Join Predicates
SELECT ENAME, LOC
FROM DEPT, EMP
WHERE DEPT.DEPTNO = EMP.DEPTNO(+)
AND 'CLERK' = EMP.JOB(+)
AND EMP.DEPTNO IS NULL
The predicate on EMP.JOB is evaluated at the same time
as the one on EMP.DEPTNO - before null augmentation. As a
result, a null row is augmented to any DEPT row for which there
are no corresponding clerks's in the EMP table. Therefore, this
query displays departments containing no clerks.
Note that it the (+) were omitted from the EMP.JOB
predicate, no rows would be returned. In this case, both the
EMP.JOB and EMP.DEPTNO IS NULL predicates are evaluated AFETR
the outer join, and there can be no rows for which both are
true.
I had to put it in a subquery? (if that's what it's called)
SELECT a1.date_field DateAndHour, b1.OR_date, NVL(b1.record_count,0)
FROM MASTER_DATE_TABLE a1,
(SELECT TO_CHAR(b.OR_IN_DTTM,'YYYYMMDDHH24') OR_date, COUNT(*) record_count
FROM hsa_tgt.PICIS_OR b
GROUP BY TO_CHAR(b.OR_IN_DTTM,'YYYYMMDDHH24')) b1
WHERE a1.date_field = b1.OR_date (+)
GROUP BY a1.date_field, b1.OR_date, b1.record_count
HAVING (TO_DATE(a1.date_field,'YYYYMMDDHH24') BETWEEN '01-Jan-2006' AND '31-Jan-2006')
ORDER BY a1.date_field;
Similar Messages
-
Hi,
Let's suppose I have to write an outer join like this:
select ...
from table_1 a, table_2 b
where a.field1 = b.field1
and a.field2 >= b.field2
but I know that for some values there might not to be a matching between the two tables.
Should I rewtire a query as follows?
select ...
from table_1 a, table_2 b
where a.field1 *(+) =* b.field1
and a.field2 *(+) >=* b.field2
I mean, should I put the (+) in both of matches?
Thanks!Please consider the following when you post a question.
1. New features keep coming in every oracle version so please provide your Oracle DB Version to get the best possible answer.
You can use the following query and do a copy past of the output.
select * from v$version 2. We dont know your DB structure or How your Data is. So you need to let us know. The best way would be to give some sample data like this.
I have the following table called sales
with sales
as
select 1 sales_id, 1 prod_id, 1001 inv_num, 120 qty from dual
union all
select 2 sales_id, 1 prod_id, 1002 inv_num, 25 qty from dual
select *
from sales 3. Rather than telling what you want in words its more easier when you give your expected output.
For example in the above sales table, I want to know the total quantity and number of invoice for each product.
The output should look like this
Prod_id sum_qty count_inv
1 145 2 4. When ever you get an error message post the entire error message. With the Error Number, The message and the Line number.
5. Next thing is a very important thing to remember. Please post only well formatted code. Unformatted code is very hard to read.
Your code format gets lost when you post it in the Oracle Forum. So in order to preserve it you need to
use the {noformat}{noformat} tags.
The usage of the tag is like this.
<place your code here>\
6. If you are posting a performance related question. Please read
{thread:id=501834} and {thread:id=863295}.
Following those guide will be very helpful. -
Update Statement with left outer join
hi,
i have to update a column in table "a" from table "b" and both of them joined with left outer join
How can I do this
Thanks in AdvancePlease consider the following when you post a question. This would help us help you better
1. New features keep coming in every oracle version so please provide Your Oracle DB Version to get the best possible answer.
You can use the following query and do a copy past of the output.
select * from v$version 2. This forum has a very good Search Feature. Please use that before posting your question. Because for most of the questions
that are asked the answer is already there.
3. We dont know your DB structure or How your Data is. So you need to let us know. The best way would be to give some sample data like this.
I have the following table called sales
with sales
as
select 1 sales_id, 1 prod_id, 1001 inv_num, 120 qty from dual
union all
select 2 sales_id, 1 prod_id, 1002 inv_num, 25 qty from dual
select *
from sales 4. Rather than telling what you want in words its more easier when you give your expected output.
For example in the above sales table, I want to know the total quantity and number of invoice for each product.
The output should look like this
Prod_id sum_qty count_inv
1 145 2 5. When ever you get an error message post the entire error message. With the Error Number, The message and the Line number.
6. Next thing is a very important thing to remember. Please post only well formatted code. Unformatted code is very hard to read.
Your code format gets lost when you post it in the Oracle Forum. So in order to preserve it you need to
use the {noformat}{noformat} tags.
The usage of the tag is like this.
<place your code here>\
7. If you are posting a *Performance Related Question*. Please read
{thread:id=501834} and {thread:id=863295}.
Following those guide will be very helpful.
8. Please keep in mind that this is a public forum. Here No question is URGENT.
So use of words like *URGENT* or *ASAP* (As Soon As Possible) are considered to be rude. -
I'm trying to recreate a logo and I want to join a line and circle, so that the outer circle is merged with the top line, as in the figure below. All the pathfinder tools don't give me what I'm after, I know there's got to be a simple way to do this, but I'm stuck.
How can I accomplish this?Thersher,
Jacob's steps are great. Here are some visuals to go along with his instructions.
1) Create the circle. I also made a guide to make everything easier for me.
2) Create the line.
3) Select the circle and use the Scissors tool to cut the circle at the two intersection points.
4) Delete the unwanted segment.
5) Do the same for the unwanted portion of the line.
6) Direct Select each of the two pairs of end points and Join them with Ctrl/Cmd+J. -
The following code is an example of how to perform an outer join, in this case with ReportQuery (thanks Doug):
ExpressionBuilder eb = new ExpressionBuilder();
ReportQuery rq = new ReportQuery(Employee.class, eb);
rq.addAttribute("firstName");
rq.addAttribute("lastName");
rq.addAttribute("areaCode", eb.anyOfAllowingNone("phoneNumbers").get("areaCode"));
List<ReportQueryResult> results = (List<ReportQueryResult>) session.executeQuery(rq);My question is about the logic Toplink uses to generate the outer join statement with the "(+)" in the generated sql.
Does Toplink only generate the join statement if the same attribute is chosen in the select statement (in the above example "areaCode")?
Along the same line of questioning, does it matter which attribute was in the get() call? So, in the above example did it have to be areaCode, or could it have been any other attribute of phoneNumber, and it still would have performed the join?
In my case, because the selection attributes are built up dynamicly, should I add all attributes of my child class (my equivalent PhoneNumber class)?Thanks for your reply Doug.
One last question, hopefully.
I have a parent table with 2 child tables. When attempting an outer join with both, toplink does not attempt to outer join either. I understand why, sort of - as you get an error when attempting this in sqlplus with "(+)" syntax.
I understand that you can outer join > 1 other table to a parent with ansi sql syntax:
select dept.*,emp.*
from dept left outer join emp
on dept.deptno = emp.deptnoWill toplink allow > 1 child table outer join to a parent table? -
Full outer Join:ORA-01790
Hi All,
The issue may be silly, but we cant make it out:
DB : Oracle Database 10g Enterprise Edition Release 10.2.0.1.0 - ProdWe are running the below query with no issues:
select t1.text,t2.text text2,t1.line,decode(upper(t1.text),upper(t2.text),1,0) flg
from
(select text,row_number() over(order by line) line
from user_source
where name = 'COLL_MVIEW_REFRESH_PROC_LBK'
and replace(trim(text),chr(10)) is not null
) t1,
(select text ,row_number() over(order by line) line
from user_source
where name = 'COLL_MVIEW_REFRESH_PROC'
and trim(replace(text,chr(10))) is not null) t2
where t1.line = t2.lineBut when trying for an outer join it is giving error like
ORA-01790: expression must have same datatype as corresponding expressionOuter Join Query:
select t1.text,t2.text,t1.line,decode(upper(t1.text),upper(t2.text),1,0) flg
from
(select text,row_number() over(order by line) line
from user_source
where name = 'COLL_MVIEW_REFRESH_PROC_LBK'
and replace(trim(text),chr(10)) is not null
) t1 full outer join
(select text ,row_number() over(order by line) line
from user_source
where name = 'COLL_MVIEW_REFRESH_PROC'
and trim(replace(text,chr(10))) is not null) t2
on( t1.line = t2.line )Any idea what is wrong here?
Thanks,
JeneeshNot sure what is wrong with your version. It might have to do with row_number not working on an empty row (outer joined).
How about this alternative?
The approach is a bit different, but it uses only one access to the user_source view.
select s.lineNo, min(s.text1) text1, min(s.text2) text2, decode(upper(min(s.text1)), upper(min(s.text2)), 1, 0) flag
from
(select decode(u.name, 'COLL_MVIEW_REFRESH_PROC_LBK', u.text) text1
,decode(u.name, 'COLL_MVIEW_REFRESH_PROC'
, u.text) text2
,u.name,
row_number() over (partition by u.name order by u.line) lineNo
from user_source u
where u.name in ('COLL_MVIEW_REFRESH_PROC_LBK','COLL_MVIEW_REFRESH_PROC'
/* and u.TYPE = 'PROCEDURE' */
and replace(trim(u.text),chr(10)) is not null
) s
group by s.lineNo
order by s.lineNo;Edited by: Sven W. on Nov 18, 2008 5:24 PM -
Left Outer Join with more than two tables in both CR 8.5 and XIR2
I am trying to create a report and I have tried two versions of Crystal but I ultimately need the report in CR8.5 for compatibility with the client's system. I think I am starting to figure out what might be wrong and it might be my understanding of SQL, but I can't see why someone hasn't needed this in the past. Ultimately I want to see all projects and any journal entry that might be posted for that project.
Database is MySQL 5.0.38 and using MySQL ODBC driver 3.51.19.
Project header table information will be populated. Each line item on a journal entry can be tagged with the project ID. But for me to pull the journal entry date I need also to link to a third table for the journal entry header info.
I want to see all projects, whether a journal entry has been posted or not.
So the links are like this
ProjectHeader --->Left Outer Join ---> JELines ---> Inner Join ---> JEHeader
I think in this scenerio Crystal is treating the LOJ as an IJ.
I created two brand new reports today, one in CR8.5 and one in CR XIR2. Once I edited the automatic CR8.5 SQL statement (which I have been doing for years, usually without problem), they both ran properly. I linked customers to their invoices. Customers without invoices showed properly. But then I linked the invoices to the payments of the invoices and immediately lost customers without orders in both reports.
So apparently only two tables are allowed in Outer Joins. Does this make sense? I checked out the w3schools tutorial on SQL and it doesn't mention this limitation and I can't find anywhere else that it specifically indicates this but all samples of code I have seen only show two tables. I just thought for presentation as a sample that was easiest to understand and we could expand as necessary.
If this is correct, how does one go about accounting for this kind of thing? One solution that goes through my mind is creating a view at the database level for the link between journal entry lines and journal entry headers. Would this be a good solution under normal circumstances?
A second option that I had to implement because of timelines, is to use a subreport linked to the main report through the project ID to pull the information for the journal entries and just pass the totals I need to the main report through a shared variable.
These aren't normal circumstances because I don't have access to the database so I can't create the view. I have come across this concept several times and I have been able to use subreports to solve it but I am trying to find a better solution for the future as sometimes subreports can be slow. So are there any alternatives I have not considered here?
TIA rasincSo after some more work and another post. I was able to get this to work.
Items disappear when linking to another table
My issues were two fold. I was selecting on the tables on the right-side of the original Inner Join. However, I was checking for Nulls. This apparently is correct but you must check for the Nulls first eg. (IsNull (JEHeader.Field1) OR JEHeader.Field1 <= 100). I had my original statement reversed checking for <= 100 before checking for Nulls.
I also did not set all links to be Left Outer Join. I had the Inner Join. I actually have about 6 tables in this report so all the links need to be set Outer Join. So this now seems to be corrected.
Thanks -
Left outer join VS Is NULL .. Please help me to understand this.
Hi Experts,
I have a requirement to use Leftouter join on a column. But unfortunately i couldnt implement this in OBIEE. so instead iam using = and is NULL condition. kindly help me to understand this or give me a solution.
Advance Thanks
I am pasting the query here. look at the last line of the query there i want to modify.
select Targ.organization_id,Targ.cycle_count_header_name,Targ.cycle_count_header_id,Targ.cc_class_name
,Targ.total_cycle_count_per_month,NVL(Act.Actual_count,0)actual_count,targ.month_year,Act.count_stat,targ.year count_date_current,length(act.count_status) count_status,nvl(length(act.count_status),0)
from
(select
Dim_date.Year,
Dim_date.month_year,
target.organization_id,
target.cycle_count_header_name,
target.cycle_count_header_id,
target.abc_class_id,
target.CC_class_name,
target.inventory_item_id_count,
target.cycle_count_per_year,
target.total_cycle_count_per_year,
target.total_cycle_count_per_month
from
(SELECT DISTINCT
TO_NUMBER (TO_CHAR (count_date_current, 'yyyy'), '9999') Year,
TO_CHAR (count_date_current, 'MON-YYYY') month_year
FROM mtl_cycle_count_entries_v)Dim_date,
(SELECT mth.organization_id,
mth.cycle_count_header_name,
mth.cycle_count_header_id,
mtc.abc_class_id,
mtc.CC_class_name,
COUNT (mti.inventory_item_id) inventory_item_id_count,
MIN (mtc.num_counts_per_year) cycle_count_per_year,
COUNT (mti.inventory_item_id)
* MIN (mtc.num_counts_per_year)
total_cycle_count_per_year,
ROUND (
(COUNT (mti.inventory_item_id)
* MIN (mtc.num_counts_per_year))
/ 12)
total_cycle_count_per_month,
TO_NUMBER (TO_CHAR (mth.creation_date, 'yyyy'), '9999') Year
FROM mtl_cycle_count_headers_v mth,
mtl_cycle_count_items_v mti,
mtl_cycle_count_classes_v mtc
WHERE mth.cycle_count_header_id = mti.cycle_count_header_id
AND mth.cycle_count_header_id = mtc.cycle_count_header_id
AND mth.organization_id = mtc.organization_id
AND mtc.abc_class_id = mti.abc_class_id
GROUP BY mth.organization_id,
mth.cycle_count_header_id,
mth.cycle_count_header_name,
mtc.abc_class_id,
mtc.CC_class_name,
TO_NUMBER (TO_CHAR (mth.creation_date, 'yyyy'), '9999')
) Target
where dim_date.Year=Target.Year) Targ,
(SELECT --TRUNC (count_date_current) count_date_current,
TO_CHAR (count_date_current, 'MON-YYYY') Month_year,
abc_class_name,
count_status count_stat,
organization_id,
cycle_count_header_id,
count_status,
SUM (NUMBER_OF_COUNTS) Actual_count
FROM MTL_CYCLE_COUNT_ENTRIES_V
GROUP BY organization_id,
--TRUNC (count_date_current),
cycle_count_header_id,
TO_CHAR (count_date_current, 'MON-YYYY'),
abc_class_name,
count_status)Act
WHERE act.cycle_count_header_id(+) = targ.cycle_count_header_id
AND act.organization_id(+) = targ.organization_id
AND act.abc_class_name(+) = targ.cc_class_name
AND act.Month_year(+)=targ.month_year
AND targ.organization_id=254
AND targ.Cycle_count_header_id=3026
AND targ.CC_CLASS_NAME= 'A PARTS'
and act.count_status (+)='Rejected'I need to replace the final line act.count_status(+)='Rejected' with
(act.count_status='Rejected' and act.count_status is NULL)But i am getting difference in data. what might be the reason?.. I am a naive user to oracle. Kindly help me and any help will be appreciated.
Thanks alot.Data set for both i am enclosing here. Kindly have a look in to that.
254 OPSCAST0909 3026 A PARTS 7 1 Dec-09 Rejected 2009
254 OPSCAST0909 3026 A PARTS 7 0 Feb-09 2009
254 OPSCAST0909 3026 A PARTS 7 0 Sep-09 2009
254 OPSCAST0909 3026 A PARTS 7 0 Jul-09 2009
254 OPSCAST0909 3026 A PARTS 7 0 May-09 2009 Data Set for outer join
254 OPSCAST0909 3026 A PARTS 7 0 Oct-09 2009
254 OPSCAST0909 3026 A PARTS 7 0 Jun-09 2009
254 OPSCAST0909 3026 A PARTS 7 0 Jan-09 2009
254 OPSCAST0909 3026 A PARTS 7 0 Nov-09 2009
254 OPSCAST0909 3026 A PARTS 7 0 Apr-09 2009
254 OPSCAST0909 3026 A PARTS 7 0 Aug-09 2009
254 OPSCAST0909 3026 A PARTS 7 0 Mar-09 2009
254 OPSCAST0909 3026 A PARTS 7 1 Dec-09 Rejected 2009
254 OPSCAST0909 3026 A PARTS 7 0 Feb-09 2009
254 OPSCAST0909 3026 A PARTS 7 0 Jul-09 2009
254 OPSCAST0909 3026 A PARTS 7 0 May-09 2009
254 OPSCAST0909 3026 A PARTS 7 0 Jun-09 2009 Data set of IS NULL
254 OPSCAST0909 3026 A PARTS 7 0 Jan-09 2009
254 OPSCAST0909 3026 A PARTS 7 0 Apr-09 2009
254 OPSCAST0909 3026 A PARTS 7 0 Aug-09 2009
254 OPSCAST0909 3026 A PARTS 7 0 Mar-09 2009 -
Left outer join problem -- need feedback
using crystal 2008
haveing prolbems with a left outerjoin to get a blank field(null) to show up.
basically i have some po line have have long descriptions or text fields that i want to include with the report. Below is my sql statement. I have written a formula with a join between 2 fields to get the report to work- this does but- it leave the polines off that do not have a long description. I have tried left outer joins but seem to be having problems. The long description field where the data is actually at is under my po.line table, although serveral area have long description fields -
*one note i had to add a duplicate table to the field to get some items in my header to work properly - not sure if this is effecting the report or not.
OK- when I set up the link to a LO join enforce from = to
and dont add the ldtext.field to the report the left outjoin works(but no long description)and all my line items show up.
1. when I keep the same join and add either just the ld.text field to the report it comes back with a error saying invalid table
2. when i use my formula that joins the ld.text and po.line and place it in the report with the same left outerjoin i get the same failure.
3. when i dont reference the ldtext(field) at all in the report it works fine w/ the lo join
4. when i Dont use a left outer join and use my formula(see below)
if not isnull(({LONGDESCRIPTION.LDTEXT }))
then {POLINE.DESCRIPTION}+{LONGDESCRIPTION.LDTEXT}
else {POLINE.DESCRIPTION}
and link from poline.ld
to ld.ldtext - my formula works and populates the po.line and the ld.text together - except that any po.line with no description will not show up. Like its not there.
Not sure what to do?
here is my current sql statement with the longdescription field in the select statement
here is the error statement i am getting:
Failed to retrieve data from the database:
Details:42000[intersolv][odb sql base driver][sql base] 00906 itn invalid table name[database vendor code:906]
sql statement:
SELECT "PO"."PONUM", "PO"."STATUS", "PO"."VENDOR",
"COMPANIES"."NAME", "COMPANIES"."ADDRESS1",
"COMPANIES"."ADDRESS2", "COMPANIES"."ADDRESS3",
"COMPANIES"."ADDRESS4", "COMPANIES"."PHONE",
"COMPANIES"."FAX", "COMPANIES_1"."NAME",
"COMPANIES_1"."ADDRESS1", "COMPANIES_1"."ADDRESS2",
"COMPANIES_1"."ADDRESS3", "COMPANIES_1"."ADDRESS4",
"COMPANIES_1"."CONTACT", "COMPANIES_1"."PHONE",
"COMPANIES_1"."FAX", "PO"."PURCHASEAGENT",
"PO"."ORDERDATE",
"PO"."REQUIREDDATE", "PO"."PAYMENTTERMS",
"PO"."SHIPVIA", "PO"."FREIGHTTERMS", "PO"."FOB",
"POLINE"."DESCRIPTION", "POLINE"."ITEMNUM",
"POLINE"."ORDERQTY", "POLINE"."UNITCOST",
"POLINE"."LOADEDCOST", "POLINE"."POLINENUM",
"PO"."SHIPTOATTN", "LONGDESCRIPTION"."LDTEXT"
FROM ("MAXIMO"."PO" "PO" LEFT OUTER JOIN
"MAXIMO"."LONGDESCRIPTION" "LONGDESCRIPTION" ON "PO"."LDKEY"="LONGDESCRIPTION"."LDKEY"),
"MAXIMO"."POLINE" "POLINE",
"MAXIMO"."COMPANIES" "COMPANIES_1",
"MAXIMO"."COMPANIES" "COMPANIES"
WHERE ("PO"."PONUM"="POLINE"."PONUM") AND ("PO"."VENDOR"="COMPANIES_1"."COMPANY") AND ("PO"."SHIPTO"="COMPANIES"."COMPANY") AND "PO"."PONUM"='3386-053'If you took the time to read this thanks.... turns out... and I just want to pull my hair out over this. My connection had a old odbc driver so somehow it would not allow a left outer join....go figure - weeks of agony over that..... thanks ....have to say love this forum.
-
OUTER JOIN -- Error: ORA-01417 (a table may be outer joined to at most one
Hi there,
I have a rather simple task: retrieve all the records in a table, for agiven domain p_domain_id (input parameter). The problem is that there are about 6 FKs in the table, and I need the names (strings) corresponding to those FKs (from other tables). Unfortunately, some of the FKs are NULL, so in '=' I loose records. Without the last 2 lines in WHERE clause, I get the correct result. With d2 in place (and without the "(+)" ) I loose 2 records. With the d3 (and also without "(+)"), I do not get any record.
With the "(+)", the code compiles but I get the run time error ORA-01417
NOTE: I put the "+" within parentheses, in order to show it like a text in this editor.
What's an elegant solution to this?
Thanks a lot.
Here's the code:
SELECT
a.DOMAIN,
b.NAME,
a.DE_ID,
a.NAME,
a.PREFERRED_LABEL,
a.TECHNICAL_DEFINITION,
a.PUBLIC_DEFINITION,
a.DE_TYPE,
c1.NAME,
a.HAS_PARAMETER,
a.VALUE_CLASS,
c2.NAME,
a.INDEX_TERMS,
a.DATA_TABLE_ID,
d1.TABLE_NAME,
a.SP_INSERT,
a.SP_UPDATE,
a.SP_GET_BYMRN,
a.SP_GET_BYATTRIBUTE,
a.VALUE_TABLE_ID,
d2.TABLE_NAME,
a.PARAM_TABLE_ID,
d3.TABLE_NAME,
a.PARAM_DOMAIN_LOGIC,
a.SP_LOV,
a.LOWER_LIMIT,
a.UPPER_LIMIT,
a.BOOLEAN_Y,
a.BOOLEAN_N,
a.COMMENTS,
a.ENTERED_BY,
commons_API.get_person_full_name(a.ENTERED_BY),
a.ENTERED_ON
FROM
DATA_ELEMENT_INDEX a,
DE_DOMAIN b,
GENERAL_LIST c1,
GENERAL_LIST c2,
TABLE_GROUP d1,
TABLE_GROUP d2,
TABLE_GROUP d3
WHERE
DOMAIN = p_domain_id AND
b.DOMAIN_ID = a.DOMAIN AND
c1.ID = a.DE_TYPE AND
c2.ID = a.VALUE_CLASS AND
d1.TABLE_ID = a.DATA_TABLE_ID AND -- it works well without the next two lines
d2.TABLE_ID = a.VALUE_TABLE_ID "(+)" AND
d3.TABLE_ID = a.PARAM_TABLE_ID "(+)"
ORDER BY a.NAME;
Edited by: user10817976 on Oct 19, 2009 8:14 AMOne of my standard replies...
Oracle syntax does not support outer joining to more than one table.
However ANSI syntax does...
SQL> select * from a;
ID B_KEY C_KEY
1 2 3
2 1 4
3 3 1
4 4 2
SQL> select * from b;
ID C_KEY2
1 1
2 5
3 3
4 2
SQL> select * from c;
KEY1 KEY2 DTA
1 1 1-1
1 2 1-2
1 3 1-3
1 4 1-4
2 1 2-1
2 2 2-2
2 3 2-3
2 4 2-4
3 1 3-1
3 2 3-2
3 3 3-3
3 4 3-4
4 1 4-1
4 2 4-2
4 3 4-3
4 4 4-4
16 rows selected.
SQL> ed
Wrote file afiedt.buf
1 select a.id as a_id, b.id as b_id, c.key1 as c_key1, c.key2 as c_key3, c.dta
2 from a, b, c
3 where a.b_key = b.id
4 and a.c_key = c.key1 (+)
5* and b.c_key2 = c.key2 (+)
SQL> /
and a.c_key = c.key1 (+)
ERROR at line 4:
ORA-01417: a table may be outer joined to at most one other table
SQL> ed
Wrote file afiedt.buf
1 select a.id as a_id, b.id as b_id, c.key1 as c_key1, c.key2 as c_key3, c.dta
2 from a JOIN b ON (a.b_key = b.id)
3* LEFT OUTER JOIN c ON (a.c_key = c.key1 and b.c_key2 = c.key2)
SQL> /
A_ID B_ID C_KEY1 C_KEY3 DTA
3 3 1 3 1-3
4 4 2 2 2-2
2 1 4 1 4-1
1 2
SQL> -
Full outer join --- bug? Urgent
Hi,
I have a simple mapping using 2 source tables and doing an full outer join. While executing the mapping it is throwing me out with an error --
Starting Execution LOAD_SAP
Starting Task LOAD_SAP
ORA-01790: expression must have same datatype as corresponding expression
ORA-02063: preceding line from ODSD@LOC_TGT_LOC_ODSD
ORA-06512: at "DWH_USER.LOAD_SAP", line 12
ORA-06512: at "DWH_USER.LOAD_SAP", line 481
ORA-06512: at "DWH_USER.LOAD_SAP", line 795
ORA-06512: at "DWH_USER.LOAD_SAP", line 1973
ORA-06512: at line 1
Completing Task LOAD_SAP
Completing Execution LOAD_SAP
The SQL generated at line 12 is -
CURSOR "JOIN_c" IS
SELECT
/*+ DRIVING_SITE("CONNECTION_LOC_TGT_LOC_ODSD") */
"CONNECTION_LOC_TGT_LOC_ODSD"."END_USER_CUST_ID" "END_USER_CUST_ID",
"SERVICE_LOC_TGT_LOC_ODSD"."SERVICE_NAME" "SERVICE_NAME",
"CONNECTION_LOC_TGT_LOC_ODSD"."CE_CLLI" "CE_CLLI",
"CONNECTION_LOC_TGT_LOC_ODSD"."PE_CLLI" "PE_CLLI"
FROM "ODS"."CONNECTION"@"ODSD"@"LOC_TGT_LOC_ODSD" "CONNECTION_LOC_TGT_LOC_ODSD"
FULL OUTER JOIN "ODS"."SERVICE"@"ODSD"@"LOC_TGT_LOC_ODSD" "SERVICE_LOC_TGT_LOC_ODSD" ON ("CONNECTION_LOC_TGT_LOC_ODSD"."END_USER_CUST_ID" = "SERVICE_LOC_TGT_LOC_ODSD"."END_USER_CUST_ID") ;
If I replace the Full outer join with an equi join everything works fine. The SQL generated with an equi-join is ---
SELECT
/*+ DRIVING_SITE("CONNECTION_LOC_TGT_LOC_ODSD") */
"CONNECTION_LOC_TGT_LOC_ODSD"."END_USER_CUST_ID" "END_USER_CUST_ID",
"SERVICE_LOC_TGT_LOC_ODSD"."SERVICE_NAME" "SERVICE_NAME",
"CONNECTION_LOC_TGT_LOC_ODSD"."CE_CLLI" "CE_CLLI",
"CONNECTION_LOC_TGT_LOC_ODSD"."PE_CLLI" "PE_CLLI"
FROM "ODS"."CONNECTION"@"ODSD"@"LOC_TGT_LOC_ODSD" "CONNECTION_LOC_TGT_LOC_ODSD",
"ODS"."SERVICE"@"ODSD"@"LOC_TGT_LOC_ODSD" "SERVICE_LOC_TGT_LOC_ODSD" WHERE ( "CONNECTION_LOC_TGT_LOC_ODSD"."END_USER_CUST_ID" = "SERVICE_LOC_TGT_LOC_ODSD"."END_USER_CUST_ID" );
We are using Oracle 9.2.0.4 AND OWB Clinet 9.2.0.2.8 and runtime repository 9.2.0.2.0.
Any help on this appreciated?The discussion on this thread has moved to the later thread Problem with JOINs
Nikolai -
Left Outer Join not working in Infoset.
Hello Friends,
I have two ODSes , one for planned data (zplan) and other is billing z ods (zsd_o03).
now the situation is such that in my planned ODS for one sold to party .
SOLD TO MATERRIAL CALMONT PLANNED QUANTIY
14315 100 06.2007 54
14315 200 06.2007 20
14315 300 06.2007 30
14315 400 06.2007 10
But in my Billing ODS iam having for Sold to 14315
SOLD TO MATERRIAL CALMONT ACTUAL QUANTIY
14315 100 06.2007 20
14315 200 06.2007 30
And my Bex ouput should be like
SOLD TO MATERIAL CALMONT planned ACTUAL QUANTIY
14315 100 06.2007 54 20
14315 200 06.2007 20 30
14315 300 06.2007 30 0
14315 400 06.2007 10 0
So for this i made one Infoset and these ODses are linked by Sold_to , Materail,
Calmonth.
First i tried using Inner joing option , but the bottom two lines were not ciming , so used left outer join , and activated and recreated the query but still its showiong me the output same as inner join .. i.e
14315 100 06.2007 54 20
14315 200 06.2007 20 30
So i checked by writing a ABAP code in Se38 , but there its showing me the correct result ..
So please anybody help me out because iam thinking that infoset is the right way to do this kind of reporting , or esle shall i make one ODS and populate it through this ABAP code..
Thanks in advance.Hi , can anybody help me in this regard..
Thanks .. -
SAP QUERY/INFOSET with OUTER JOIN
Hi,
I have created an infoset (SQ02) using two tables for SAP query.
Table: AGR_TEXTS. Fields: AGR_NAME, SPRAS, LINE, TEXT.
TABLE: AGR_FLAGS. Fields: AGR_NAME, FLAG_TYPE, FLAG_VALUE.
Joined these two tables using outer join. Defined the join condition as AGR_NAME = AGR_NAME. Saved and Generated the infoset.
Created SAP Query (SQ01) using the above created infoset.
In the basic list,
Marked AGR_NAME (AGR_TEXTS), TEXT, FLAG_VALUE as listed fields.
Marked AGR_NAME (AGR_TEXTS), SPRAS, LINE, FLAG_TYPE as selection fields.
Save the query. When execute the query provided the inputs for all the selection fields in the selection screen as given below:
AGR_NAME=Z*
SPRAS=E
LINE=00000
FLAG_TYPE=LICENSE_01
Executed the Query.
Got the results only the matched records as per the selection field FLAG_TYPE.
But I want all the records from table AGR_TEXTS and matched records from table AGR_FLAGS.
I want the report (output) as below,
_AGR_NAME TEXT FLAG_VALUE_
ZCA_BASIC_ACCESS_GLOBAL Non-critical basic access for all users. 53
ZCA_BASIC_ENDUSER_ACCESS UK:CA Basic Enduser Access
ZCA_BASIC_ENDUSER_ACCESS_UK UK:CA Basic Enduser Access UK 52
ZCA_BASIC_ENDUSER_SU52_UK UK:CA Basic Enduser Access to change Parameter ID's
But I got the report (output) as below,
_AGR_NAME TEXT FLAG_VALUE_
ZCA_BASIC_ACCESS_GLOBAL Non-critical basic access for all users. 53
ZCA_BASIC_ENDUSER_ACCESS_UK UK:CA Basic Enduser Access UK 52
Apprecited your help. Thanks.
Code Formatted by: Alvaro Tejada Galindo on Dec 30, 2009 2:20 PMIdentify a KF for which there are non-zero values for all accounts in the cube.
Create the query with Account (from MP coming from both IO and cube) and this KF. KF will have 0 values for accounts not existing in the cube. Create a condition to show only the 0 value for the KF. This should show you all the accounts in the IO which are not in the cube. -
How to use OUTER JOIN in Oracle Answers Filters?
Hi, I need to have a filter on an 'Oracle Answers' report.
The query from the NQQuery.log appears as below. (I have simplified the SELECT clause here for easy reading)
SELECT t692.enquiry_business_route AS c1,
t692.enquiry_id AS c11, t913.YEAR AS c12,
t913.full_date AS c13, t666.surname AS c14,
t666.post_code AS c15, t855.company_name AS c16,
t983.notes AS c30
FROM
mkt_dw_enev_enhi_dim t983,
mkt_dw_key_partner_dim t855,
mkt_dw_event_type_dim t821,
mkt_dw_customer_dim t666,
mkt_dw_time_dim t913,
mkt_dw_enquiry_event_fact t692
WHERE (
t692.enquiry_id = t983.enqu_id
AND t666.customer_dim_key = t692.customer_dim_key
AND t692.event_date_time_key = t913.time_dim_key
AND TRUNC(t983.event_date)= t913.FULL_DATE
AND t692.event_type = t821.event_type_dim_key
AND t692.key_partner_dim_key = t855.key_partner_dim_key
AND t821.event_type_category = 'RECEIVE_FEE'
AND t913.YEAR = 2009
and t692.enquiry_id = 535986
For the following two lines I would like to have the OUTER JOIN.
AND t692.event_type = t821.event_type_dim_key(+)
AND t821.event_type_category(+) = 'RECEIVE_FEE' (THIS IS THE FILTER CONDITION, AT THE MOMENT IT DOESN'T WORK WITH OUTER JOIN SYMBOL)
Please could you let me know the best way of achieving the above.
Thanks
SrikanthIn the BMM layer in the join condition you will be able to specify the join to be (left, right or full outer join).
You can even add the required table in the LTS(logical table source) and also specify a left, right or full outer join there as well.
There is an interesting work around as mentioned in the below blog to get to the Outer join results with out changing anything in rpd but in Answers.
http://obiee101.blogspot.com/2008/11/obiee-outerjoin-workaround.html
Hope it helps
Thanks
prash -
Outer join trouble in Oracle 8i
Hello
I'm trying to join two tables - one with account information, and one with transaction information.
For each account I want to find the latest transaction date. -If any transactions of the specified types...
If all accounts had one or more transactions of the types I want, there would be no problem..
select a.account_id, max(t.transaction_date)
from accounts a, transactions b
where t.transaction_code in (0,1,2,3,4,5,7,8)
and a.account_id = t.account_id
group by a.account_id;
How do I do it since I also want to see the accounts
without any transactions?
Cannot use the outer join (+) - since my sql-query
contains the keyword 'in' ('or' gave the same result)..
ORA-01719.
SisselHave you tried in-line query
Select A.account_id, T.Max_Trans_Date
from Accounts A,
(select account_id, max(transaction_Date) Max_Trans_date
from Transactions
where Transaction_Code in (0,1,2,3,4,5,7,8)
group by Account_Id) T
where A.Account_Id = X.Account_Id(+)
Maybe you are looking for
-
Can I create a new account and keep all of my purchases and downloads?
Can I create a new account and keep all of my old content? Recently got divorced and share the itunes account with my ex. I want a new account but do not want to lose all of my old content. Is this possible?
-
Java.lang.UnsatisfiedLinkError: DBDisconnect
Hi Guys, I tried using the Connection pool APIs from db2jcc.jar for DB2 UDB v8.1. While i try to execute the following code i got the exception java.lang.UnsatisfiedLinkError: DBDisconnect. Please help me to find the problem, there is no .dll to be l
-
ITunes Music folder with my iTunes folder
I'm trying to organize my music and I have a problem: If I open my main music folder and then open my iTunes folder, I see many folders of all my assorted artists. Among those is another folder called "iTunes Music" that seems to duplicate all the sa
-
How do I import files from My Canon XF300 into FCPX
This is driving me mad, I am trying to import files from my Canon XF300 into FCPX I have tried everything but no sucess any help would be welcomed. Regards Fred
-
Is Dreamweaver backward compatible to 2005 or do I need to recreate my entire Web site?
After many years, my company finally upgraded to CS5. I have a site created in the 2005 version of Dreamweaver, with a navigation bar exported from Fireworks as an htm file "required" on every page. After installing CS5, my design pages show only the