Outer join with Oracle syntax
Hi, I am new to oracle and I worked this request for reports for about 2 weeks, please take a look at my requestSELECT mmt.transaction_date "Transaction Date",
msib.segment1 "Item",
gcc.segment1||'-'||gcc.segment2||'-'||gcc.segment3||'-'||gcc.segment4||'-'||gcc.segment5||'-'||gcc.segment6||'-'||(nvl(gcc.segment7,'000000')) "account",
(CASE mttype.transaction_type_name
WHEN 'Average cost update' THEN
((nvl(mmt.new_cost,0) - nvl(mmt.prior_cost,0)) * nvl(mmt.quantity_adjusted,0)) + nvl(mmt.variance_amount,0)
ELSE
(mmt.Primary_quantity * nvl(mmt.actual_cost, 0) + nvl(mmt.variance_amount, 0))
END) "Transaction Value",
mttype.description "Transaction Type",
mmt.subinventory_code "Subinventory",
ood.organization_code "Org",
msib.Primary_UOM_Code "UOM",
mmt.Primary_Quantity "Primary Quantity",
mtr.description "Reason",
mmt.transaction_reference "Reference"
FROM mtl_material_transactions mmt,
mtl_system_items_b msib,
mtl_transaction_accounts mta,
gl_code_combinations gcc,
mtl_transaction_types mttype,
Org_Organization_Definitions ood,
mtl_transaction_reasons mtr
WHERE mmt.transaction_date >= :P_DATE_FROM
and mmt.transaction_date < :P_DATE_TO +1
and mmt.organization_id = :P_ORGANIZATION
and msib.organization_ID = mmt.organization_ID
and msib.inventory_item_id=mmt.inventory_item_id
and mta.transaction_id=mmt.transaction_id
and gcc.code_combination_id = mta.reference_account
and mttype.transaction_type_id=mmt.transaction_type_id
and mmt.reason_id=mtr.reason_id(+)
and ood.organization_id=mmt.organization_id
and mttype.transaction_type_id = :P_TRANSACTION_TYPE
and msib.segment1 = :P_ITEM
AND gcc.segment2 = :P_ACCOUNT
null values is on the mtl_material_transactions table, which is reason_id, subinventory_code and transaction_referenceput desired option on would show all archives on mtl_material_transactions with null values
so I put the symbol of the outer join right?
BTW
I tried to put the (+) sign on various locations but it still not good and I am really at a loss
Hello
Whenever you have any questions, post a small example data (CREATE TABLE and only relevant columns, INSERT statements) and the desired results from these data. I know that's not always easy, but it is really necessary. Compounds that, I do not understand your problem.
It could be useful that simplify you the problem. If you were not interested in, say, the mta, gcc, tables msib and ood, would you still have the same problem? If so, forget all these tables and just after, CREATE TABLE and INSERT statements for the remaining tables and the results you want from this data.
Explain, using specific examples, how you get these results from these data.
Always tell what version of Oracle you are using.
The query you posted will not exclude any line of mmt just because it doesn't have a corresponding line in the mtr; That's what the condition:
and mmt.reason_id=mtr.reason_id(+)
but it will exclude mmt lines if they do not have matching rows in other tables. Maybe you need + plus join and may under certain conditions non-join, such as conditions
gcc.segment2 (+) = :P_ACCOUNT
Too much. It's just a guess. Without seeing your sample data and the correct results, you should get from this data, I can't say.
Tags: Database
Similar Questions
-
Dear elders,
Firstly, sorry if my question is considered to be 'very novice' but I have this problem of confusion.
Can I use the left outer join with summary?
For example:
Work table
Table No.JobCode JobGroupCode 111A 1100 112B 1100 113C 1100 121A 1200 333F 3300
Activity tableJobGroupCode ParentCode 1100 1000 1200 1000 1300 1000 3300 3000
I want to choose with this resultJobcode Mandays 111A 5 112B 7 113C 3
All I did was:Job.JobCode Job.JobGroupCode JobGroup.Parentcode Mandays 111A 1100 1000 5 112B 1100 1000 7 113C 1100 1000 3 121A 1200 1000 0 333F 3300 3000 0
and I got was only jobcode activity table, not exactly what I want to get all the work table jobcode. Could you please tell me, where I was wrong?select j.jobcode, j.jobgroupcode, jg.parentcode, sum(a.mandays) from job j inner join jobgroup jg on j.jobgroupcode = jg.jobgroupcode left join activity a on j.jobcode = a.jobcode group by j.jobcode, j.jobgroupcode, jg.parentcode
result
Thank you very much.Job.JobCode Job.JobGroupCode JobGroup.Parentcode Mandays 111A 1100 1000 5 112B 1100 1000 7 113C 1100 1000 3
Published by: user11197113 on May 25, 2009 03:31
Published by: user11197113 on May 25, 2009 03:32Hello (and welcome!).
Edit
OK, try this:
select j.jobcode, j.jobgroupcode, jg.parentcode, NVL(sum(a.mandays),0) from job j inner join jobgroup jg on j.jobgroupcode = jg.jobgroupcode left join activity a on j.jobcode = a.jobcode group by j.jobcode, j.jobgroupcode, jg.parentcode
That will give you this:
JOBC JOBG PARE SUM(A.MANDAYS) ---- ---- ---- -------------- 111A 1100 1000 5 112B 1100 1000 7 113C 1100 1000 3 121A 1200 1000 0 333F 3300 3000 0
These are real results of your test data.
-
SSRS for lack of outer join with the Oracle data source
It seems to be a problem with the Oracle driver used in the Reporting SERVICES query designer.
When you use an Oracle data source, if I create an outer join in the graphic designer, it automatically inserts '{OJ' before the join and '} ' after her. This is an incorrect syntax for Oracle and refuses to start. The curly braces and the JO editable in designer text, but if I go back to the graphic designer and immediately to reintegrate them.
Only, this has started to happen a year or two ago - before that it worked, but with the old (+) syntax.
Can it not be healed? It makes things very difficult.
-Geoff
Hi Geoff,
Thanks for posting in the Microsoft Community.
However, the question you posted would be better suited in the Forums of the Oracle Support; We recommend that you post your query in Oracle Support Forums to get help:
If you have any other questions or you need Windows guru, do not hesitate to post your questions and we will be happy to help you.
-
outer join with syntax plus sign
To do this in Sql outer joins can be used as grammar:
( + )
What are the standards (ISO, ANSI and what version) created this grammar?
Or is it only the invention of Oracle?
Published by: CharlesRoos on July 1st, 2010 07:23Apparently, he was "there are chandeliers" ;)
http://asktom.Oracle.com/pls/asktom/f?p=100:11:0:P11_QUESTION_ID:2419891400346921578 #2439016200346544570
-
Why left outer join with a table gives me more lines?
Hi gurus,
I can see "view_a" and a table 'table_a '.
view_a a county of 100 lines. Now, when I left outer join that discovers with a 'table_a', I expect all 100 lines.
However, I'm more than 100 lines. Is it still possible?
Also even to analyze these situations, how can I move forward?
Because it is very high volumn of sight and takes longer to run.
Select count (*) view_a, view_b
where view_a.col1 = view_b.col1 (+)
and view_a.col2 = view_b.col2 (+);
Thank you
I can see "view_a" and a table 'table_a '.
view_a a county of 100 lines. Now, when I left outer join that discovers with a 'table_a', I expect all 100 lines.
However, I'm more than 100 lines. Is it still possible?
Also even to analyze these situations, how can I move forward?
Because it is very high volumn of sight and takes longer to run.
Select count (*) view_a, view_b
where view_a.col1 = view_b.col1 (+)
and view_a.col2 = view_b.col2 (+);
Which is not necessarily related to the use of an outer join.
Just join of two tables in general will give you more rows of one table has.
Scott DEPT table contains ONE row for deptno = 10
The EMP table has THREE rows of deptno = 10
The number of rows you plan if you join two tables using an equi-join?
Three - what is MORE lines the DEPT table has for deptno = 10
Select * from Department where deptno = 10
DEPTNO, DNAME, LOC
10, ACCOUNTING, NEW YORKSelect * from emp where deptno = 10
MGR, EMPLOYMENT ENAME, EMPNO, HIREDATE, SAL, COMM, DEPTNO
7782, CLARK, MANAGER, 7839, 6/9/1981,2450, 10
7839, KING, PRESIDENT, 17 NOVEMBER 00, 10
7934, MILLER, CLERK, 7782, 23 JANUARY 00: 10Select dept.*, emp.*
Department, emp
where dept.deptno = 10
and dept.deptno = emp.deptnoDEPTNO, DNAME, LOC, EMPNO, ENAME, JOB, MGR, HIREDATE, SAL, COMM, DEPTNO_1
10, ACCOUNTING, NEW YORK, 7782, CLARK, MANAGER, 7839, 6/9/1981,2450, 10
10, ACCOUNTING, NEW YORK, 7839, KING, PRESIDENT, 17 NOVEMBER 00, 10
10, ACCOUNTING, NEW YORK, 7934, MILLER, CLERK, 7782, 23 JANUARY 00: 10So if these are the lines ONLY in the table EMP and DEPT the query would give you THREE lines despite the DEPT table only ONE line.
No do you expect? You get ALL the child rows that belong to the parent company. Otherwise, how could it possibly work?
The OUTER join includes lines where the parent row exists but there is NO child line as others have shown.
Outer joins
Outer join extends the result of a simple join. Outer join returns all rows that satisfy the join condition and also returns some or all rows in a table for which no line of the other meet the join condition.
Get more lines to exist in one of the paintings is a basic necessity. It usually has NOTHING to with the question of whether you have an outside to join or not.
See the section on the JOINTS in the Oracle documentation
http://docs.Oracle.com/CD/B28359_01/server.111/b28286/queries006.htm
-
outer join with the additional constraint
Hello
With the help of Oracle 11 g R2.
I would of outer join tables 2 together and put down restrictions on the types of records that are returned in the query result. Here's a mock-up of the tables and data.
create table aaa (col1 number not null, col2 number not null)
create table bbb (col1 number not null, col2 number not null)
insert into values of aaa (1: 80)
insert into values aaa (2, 90)
insert into values aaa (3, 80)
insert into values aaa (4, 90)
insert into values aaa (5, 80)
insert into bbb values (3, 600)insert into values of bbb (4, 700)
This is the query
select a.col1, a.col2, b.col1, b.col2 from aaa a, bbb b where a.col1 = b.col1 (+) and (a.col2, b.col2) <> ((90, 700))
The result of the query is as follows.
col1 col1 col2 col2
1 80
3 80 3 600
5 80
Where col1 = 4 has been deleted, which is an expected result. However, where col1 = 2 has also been removed, which is not a desired outcome. Your response is appreciated.
Hello
Here is a way that works for the given sample data:
SELECT *.
AAA a
LEFT OUTER JOIN bbb b ON a.col1 = b.col1
WHERE the NVL (a.col2, 0) <> 90
OR NVL (b.col2, 0) <> 700
;
I don't know if that will satisfy your requirements with other data, since you didn't say what your needs are.
Whenever you have a WHERE clause is applied after the outer join, all columns of the table in option (table bbb in this example) must be used in an NVL, NVL2 or something like a CASE expression that takes into account null values; otherwise, the effect will be the same as an inner join.
-
HELP SQL (auto / full outer join with date corresponding)
I'm having a hard time get this query nailed... hoping someone can help me sorted.
create table tab1 (identification number,
date of eff_date,
Code1 varchar2 (2),
Code2 varchar2 (2)
)
/
insert into tab1 values (2, to_date('2015-01-14','YYYY-MM-DD'), 'DAT', 'AS');
insert into tab1 values (2, to_date('2015-03-19','YYYY-MM-DD'), 'DAT', 'AS');
insert into tab1 values (2, to_date('2015-08-28','YYYY-MM-DD'), 'DAT', 'AS');
insert into tab1 values (2, to_date('2015-11-12','YYYY-MM-DD'), 'DAT', 'AS');
insert into tab1 values (2, to_date('2015-01-03','YYYY-MM-DD'), "DAT", "AE");
insert into tab1 values (2, to_date('2015-03-14','YYYY-MM-DD'), "DAT", "AE");
insert into tab1 values (2, to_date('2015-04-18','YYYY-MM-DD'), "DAT", "AE");
insert into tab1 values (2, to_date('2015-09-14','YYYY-MM-DD'), "DAT", "AE");
insert into tab1 values (2, to_date('2015-01-14','YYYY-MM-DD'), "DAT", "BS");
insert into tab1 values (2, to_date('2015-02-14','YYYY-MM-DD'), "DAT", "BS");
insert into tab1 values (2, to_date('2015-03-14','YYYY-MM-DD'), "DAT", "BS");
insert into tab1 values (2, to_date('2015-05-14','YYYY-MM-DD'), 'DAT', 'BE');
insert into tab1 values (3, to_date('2015-09-16','YYYY-MM-DD'), 'DAT', 'AS');
insert into tab1 values (3, to_date('2015-04-16','YYYY-MM-DD'), "DAT", "AE");
tab1
ID, date, code 1, code2
2. DID DAT 2015-01-14
2. DID DAT 2015-03-19
2. DID DAT 2015-08-28
2. DID DAT 2015-11-12
2 AE DAT 2015-01-03
2 AE DAT 2015-03-14
2 AE DAT 2015-04-18
2 AE DAT 2015-09-14
2 BS DAT 2015-01-14
2 BS DAT 2015-02-14
2 BS DAT 2015-03-14
BE DAT 2 2015-05-14
3. DID DAT 2015-09-16
3 AE DAT 2015-04-16
What I need to do...
1 auto join to match EI for each partition ID
2. THAT the date must be less than or equal to the date of the AE and when there is more then a line corresponding to this criterion has chosen the date of closest EI of the date of the ACE.
3. it must be a full outer join because I want to show all lines, even if it is not a match. There is a beginning, but not record end end gold but no record of departure
4. If there is an AE line for many AS lines (the SA date is less then equals the date of EI) then join this AE line to all 3 rows of ACE
5. the same rules for BS and BE.
result should look like this.
ID, date, code 1, id_1 code2, date_1, code1_1, code2_1
2 2015-01-14 DAT AS 2 AE DAT 2015-03-14
2 2015-03-19 DAT AS 2 AE DAT 2015-04-18
2 2015-08-28 DAT AS 2 AE DAT 2015-09-14
2 2015-11-12 DAT DID ZERO ZERO ZERO ZERO
NO NO NO NO 2 AE DAT 2015-01-03
2015-01-2 14 DAT BS 2 BE DAT 2015-05-14
2015-02-2 14 DAT BS 2 BE DAT 2015-05-14
2015 03-2 14 DAT BS 2 BE DAT 2015-05-14
3 2015-09-16 DAT DID ZERO ZERO ZERO ZERO
NO NO NO NO 3 AE DAT 2015-04-16
My attempt was somewhat along these lines (dealing only with SA / combos AE) but it does not manage the many scenarios one (req 4).
Select a.*, b.* from
(select row_number () on the rn (partition by a.id order a.eff_date), a.*)
of tab1 where a.code2 = 'AS') a
full outer join
(select row_number () on the rn (b.eff_date order by b.id partition), b.*)
tab1 b where b.code2 = 'Æ') b
on a.id = b.id
and a.rn = b.rn
and a.eff_date < = b.eff_date
Hello
owbdev99 wrote:
I'm having a hard time get this query nailed... hoping someone can help me sorted.
create table tab1 (identification number,
date of eff_date,
Code1 varchar2 (2),
Code2 varchar2 (2)
)
/
insert into tab1 values (2, to_date('2015-01-14','YYYY-MM-DD'), 'DAT', 'AS');
...
Thanks for posting the CREATE TABLE and INSERT. I know it can be a lot of trouble. You want to get answers that work, not you? Make sure that the statements you post too much work. Test (and, if necessary, attach) your statements before committing. You said code1 be VARCHAR2, but all the instructions insertion have values of 3 characters for code1.
You are on the right track, with an analytical function, but ROW_NUMBER solves this problem. 1 "THAT line" could correspond to the 1st, 2nd, 3rd or any other line 'AE' and vice versa. Try to use the analytical MIN function instead or ROW_NUMBER, like this:
WITH got_next_e_date AS
(
SELECT id, eff_date, code1, code2
MIN (CASE
WHEN SUBSTR (code2, 2) = 'E '.
THEN eff_date
END
) OVER (PARTITION BY ID.
, SUBSTR (code2, 1, 1)
ORDER BY eff_date DESC
) AS next_e_date
OF tab1
)
s AS
(
SELECT *.
OF got_next_e_date
"WHERE SUBSTR (code2, 2) s ="
)
e
(
SELECT *.
OF got_next_e_date
WHERE SUBSTR (code2, 2) = 'E '.
)
SELECT s.id
s.eff_date
s.code1
s.code2
e.id AS id_1
e.eff_date AS eff_date_1
e.code1 AS code1_1
e.code2 AS code2_1
S
FULL OUTER JOIN e ON s.id = e.id
AND s.next_e_date = e.eff_date
AND SUBSTR (s.code2, 1, 1) = SUBSTR (e.code2, 1, 1)
ORDER OF NVL (s.id, e.id)
, NVL (SUBSTR (s.code2, 1, 1)
, SUBSTR (e.code2, 1, 1)
)
s.eff_date
;
Out (as you asked):
ID EFF_DATE CODE1, CODE2 ID_1 EFF_DATE_1 CODE1_1 CODE2_1
--- ---------- ----- ----- ----- ---------- ------- -------
2 2015-01-14 DAT AS 2 AE DAT 2015-03-14
2 2015-03-19 DAT AS 2 AE DAT 2015-04-18
2 2015-08-28 DAT AS 2 AE DAT 2015-09-14
2. DID DAT 2015-11-12
2 AE DAT 2015-01-03
2015-01-2 14 DAT BS 2 BE DAT 2015-05-14
2015-02-2 14 DAT BS 2 BE DAT 2015-05-14
2015 03-2 14 DAT BS 2 BE DAT 2015-05-14
3. DID DAT 2015-09-16
3 AE DAT 2015-04-16
I guess code2 is always 2 characters, and the 2nd character is always ' or 'E '.
I assume that the combination [id, eff_date, code2] is unique.
If these assumptions are wrong, you need a few minor changes, but nothing big.
-
Using Left Outer Join with reference
I have three tables.
Table 1: BOOK_DETAILS
Fields: BOOK_ID, BOOK_NAME
Table 2: BOOK_ISSUE_RECORD
Fields: BOOK_ID, USER_NAME
Table 3: BOOK_AUTHOR
Fields: BOOK_ID, AUTHOR_NAME
I must link table 1 and table 2 with a left outer join, because even if the book is not the questions to anyone, his name should come.
I have once again display the name of the author of books for each book.
I am able to create a query with the left outer join between table 1 and table 2. However, I am not able to give a reference to Table 3.
Can someone help me with this please.
Concerning
Hawkerselect d.book_name, a.book_author, i.user_name from book_details d join book_author a on (d.book_id = a.book_id) left join book_issue_recors i on (d.book_id = i.book_id) /
SY.
-
Outer join when made between the columns of the two tables is easy to understand and I'm familiar with it. But when it comes to the same join with a constant, my head starts spinning... you guys can help me with this? I would appreciate that show you with examples.
Thanks a ton.Hello
>
Ok... I want to understand the output of the last sql statement given here.
...
Select * from a, b
where col_a (+) = col_b
and col_a (+) = 1It shows put it is as follows
col_a, col_b
1 1
2 NULL
NULL NULLJoining means: 'display all rows in table b and the corresponding rows in the table one '.
Since it is an outer join, it also means "view b lines even if there is no corresponding row in a.Thus, the output contains 3 lines, which correspond to the 3 lines in b.
Only one of them (the one with col_b = 1) had a game in a.col_a, if the column is NULL in the other lines.With the sample data you posted, you will get the same results without condition
and col_a (+) = 1
If you want to understand what makes this condition, use some examples of data where this condition would fail.
For example, add this line to the table a:insert into a values (2);
and run your original query (including the)
and col_a (+) = 1
). what output you get? You get the same exact results you did without the new line in a.
In other words, the b line where col_b = 2 has still no matches in the table has.
True, there is now a line of table where col_a = 2, but which does not constitute a game. A match is defined by two conditions:where col_a (+) = col_b and col_a (+) = 1
in order to have a pair of lines which meets only the first condition
where col_a (+) = col_b
is not enough.
-
Hello
We have this basic question that works very well:
Select pp.upc, a.barcode from the ALBUM, PHYSICALPRODUCT RP where lpad (pp.upc, 13, '0') = lpad (a.barcode, 13, '0')
But we wanted to do an outer join. If we remove the lpad, it works. But if we as below, we have ORA-00936, lack of expression:
Select pp.upc, a.barcode from the ALBUM, PHYSICALPRODUCT RP where lpad (pp.upc, 13, '0') (+) = lpad (a.barcode, 13, '0')
If anyone can help us in this regard.
Thks.Outer join can be used outside the functions of text
It will be likeselect pp.upc, a.barcode from ALBUM a, PHYSICALPRODUCT pp where lpad(pp.upc (+), 13, '0') = lpad(a.barcode, 13, '0')
-
outer join on query with the GOLD clause
Hi all, I have a problem outerjoining a clause or a request with
Here's my data
as you can see I am attaching the table 1 and table 2. I join with txt1, if txt1 is null, then join by txt2, if null, then reach by txt3 and so on.WITH table1 AS ( SELECT 'test' txt1, 'pak' txt2, 'ced' txt3, 'su' txt4 FROM dual UNION ALL SELECT null txt1, 'pak' txt2, 'ced2' txt3, 'su2' txt4 FROM dual UNION ALL SELECT null txt1, NULL txt2, 'ced3' txt3, 'su3' txt4 FROM dual UNION ALL SELECT null txt1, NULL txt2, null txt3, 'su3' txt4 FROM dual UNION ALL SELECT 'text5' txt1, NULL txt2, null txt3, 'su3' txt4 FROM dual UNION ALL SELECT null txt1, NULL txt2, null txt3, null txt4 FROM dual ) ,table2 AS ( SELECT 111 pid, 'test' txt1, 'pak4' txt2, 'ced' txt3, 'su' txt4 FROM dual UNION ALL SELECT 222 pid, 'test1' txt1, 'pak' txt2, 'ced2' txt3, 'su2' txt4 FROM dual UNION ALL SELECT 333 pid, 'test2' txt1, 'pak3' txt2, 'ced3' txt3, 'su4' txt4 FROM dual UNION ALL SELECT 444 pid, 'test2' txt1, 'pak3' txt2, 'ced4' txt3, 'su3' txt4 FROM dual ) SELECT b.pid, a.* from table1 a, table2 b WHERE (a.txt1 = b.txt1 OR a.txt1 IS NULL AND a.txt2=b.txt2 OR Nvl(a.txt2, a.txt1) IS NULL AND a.txt3 = b.txt3 OR Nvl(a.txt2, a.txt1) IS NULL AND a.txt3 IS NULL AND a.txt4 = b.txt4 )
the above produces this output code
This output is partially correct. only 4 lines were in display and two has been left outPID TXT1 TXT2 TXT3 TXT4 === ==== === ==== ==== 111 test pak ced su 222 pak ced2 su2 333 ced3 su3 444 su3
I tried to use the outer join, but oracle will complain that I can't use outerjoin with the GOLD clause.SELECT 'text5' txt1, NULL txt2, null txt3, 'su3' txt4 FROM dual UNION ALL SELECT null txt1, NULL txt2, null txt3, null txt4 FROM dual
can someone modify my query to display the output below?
PID TXT1 TXT2 TXT3 TXT4 === ==== === ==== ==== 111 test pak ced su 222 pak ced2 su2 333 ced3 su3 444 su3 NULL NULL NULL NULL NULL test5
Not sure you can do it with the style of the Oracle of outer joins, but open ANSI style joins is simple, in fact exactly as you had it.
SQL> set null null; SQL> WITH table1 AS ( 2 SELECT 'test' txt1, 'pak' txt2, 'ced' txt3, 'su' txt4 FROM dual UNION ALL 3 SELECT null txt1, 'pak' txt2, 'ced2' txt3, 'su2' txt4 FROM dual UNION ALL 4 SELECT null txt1, NULL txt2, 'ced3' txt3, 'su3' txt4 FROM dual UNION ALL 5 SELECT null txt1, NULL txt2, null txt3, 'su3' txt4 FROM dual UNION ALL 6 SELECT 'text5' txt1, NULL txt2, null txt3, 'su3' txt4 FROM dual UNION ALL 7 SELECT null txt1, NULL txt2, null txt3, null txt4 FROM dual), 8 table2 AS ( 9 SELECT 111 pid, 'test' txt1, 'pak4' txt2, 'ced' txt3, 'su' txt4 FROM dual UNION ALL 10 SELECT 222 pid, 'test1' txt1, 'pak' txt2, 'ced2' txt3, 'su2' txt4 FROM dual UNION ALL 11 SELECT 333 pid, 'test2' txt1, 'pak3' txt2, 'ced3' txt3, 'su4' txt4 FROM dual UNION ALL 12 SELECT 444 pid, 'test2' txt1, 'pak3' txt2, 'ced4' txt3, 'su3' txt4 FROM dual) 13 SELECT b.pid, a.* 14 from table1 a 15 LEFT JOIN table2 b 16 ON (a.txt1 = b.txt1 OR 17 a.txt1 IS NULL AND a.txt2=b.txt2 OR 18 Nvl(a.txt2, a.txt1) IS NULL AND a.txt3 = b.txt3 OR 19 Nvl(a.txt2, a.txt1) IS NULL AND a.txt3 IS NULL AND a.txt4 = b.txt4); PID TXT1 TXT2 TXT3 TXT4 ---------- ------ ------ ------ ------ 111 test pak ced su 222 null pak ced2 su2 333 null null ced3 su3 444 null null null su3 null text5 null null su3 null null null null null
John
-
BAD RESULTS WITH OUTER JOINS AND TABLES WITH A CHECK CONSTRAINT
HII All,
Could any such a me when we encounter this bug? Please help me with a simple example so that I can search for them in my PB.
Bug:-8447623
Bug / / Desc: BAD RESULTS WITH OUTER JOINS AND TABLES WITH a CHECK CONSTRAINT
I ran the outer joins with check queries constraint 11G 11.1.0.7.0 and 10 g 2, but the result is the same. Need to know the scenario where I will face this bug of your experts and people who have already experienced this bug.
Version: -.
SQL> select * from v$version; BANNER -------------------------------------------------------------------------------- Oracle Database 11g Enterprise Edition Release 11.1.0.7.0 - 64bit Production PL/SQL Release 11.1.0.7.0 - Production CORE 11.1.0.7.0 Production TNS for Solaris: Version 11.1.0.7.0 - Production NLSRTL Version 11.1.0.7.0 - Production
Why do you not use the description of the bug test case in Metalink (we obviously can't post it here because it would violate the copyright of Metalink)? Your test case is not a candidate for the elimination of the join, so he did not have the bug.
Have you really read the description of the bug in Metalink rather than just looking at the title of the bug? The bug itself is quite clear that a query plan that involves the elimination of the join is a necessary condition. The title of bug nothing will never tell the whole story.
If you try to work through a few tens of thousands of bugs in 11.1.0.7, of which many are not published, trying to determine whether your application would be affected by the bug? Wouldn't be order of magnitude easier to upgrade the application to 11.1.0.7 in a test environment and test the application to see what, if anything, breaks? Understand that the vast majority of the problems that people experience during an upgrade are not the result of bugs - they are the result of changes in behaviour documented as changes in query plans. And among those who encounter bugs, a relatively large fraction of the new variety. Even if you have completed the Herculean task of verifying each bug on your code base, which would not significantly easier upgrade. In addition, at the time wherever you actually performed this analysis, Oracle reportedly released 3 or 4 new versions.
And at this stage would be unwise to consider an upgrade to 11.2?
Justin
-
[8i] need help with full outer join combined with a cross join...
I can't understand how to combine a full outer join with a different type of join... is it possible?
Here are some create table and insert for examples of database:
And, the results that I want to get:CREATE TABLE my_tab1 ( record_id NUMBER NOT NULL , workstation VARCHAR2(4) , my_value NUMBER CONSTRAINT my_tab1_pk PRIMARY KEY (record_id) ); INSERT INTO my_tab1 VALUES(1,'ABCD',10); INSERT INTO my_tab1 VALUES(2,'ABCD',15); INSERT INTO my_tab1 VALUES(3,'ABCD',5); INSERT INTO my_tab1 VALUES(4,'A123',5); INSERT INTO my_tab1 VALUES(5,'A123',10); INSERT INTO my_tab1 VALUES(6,'A123',20); INSERT INTO my_tab1 VALUES(7,'????',5); CREATE TABLE my_tab2 ( workstation VARCHAR2(4) , wkstn_name VARCHAR2(20) CONSTRAINT my_tab2_pk PRIMARY KEY (workstation) ); INSERT INTO my_tab2 VALUES('ABCD','WKSTN 1'); INSERT INTO my_tab2 VALUES('A123','WKSTN 2'); INSERT INTO my_tab2 VALUES('B456','WKSTN 3'); CREATE TABLE my_tab3 ( my_nbr1 NUMBER , my_nbr2 NUMBER ); INSERT INTO my_tab3 VALUES(1,2); INSERT INTO my_tab3 VALUES(2,3); INSERT INTO my_tab3 VALUES(3,4);
I tried a number of different things, google my problem and no luck yet...workstation sum(my_value) wkstn_name my_nbr1 my_nbr2 --------------------------------------------------------------- ABCD 30 WKSTN 1 1 2 ABCD 30 WKSTN 1 2 3 ABCD 30 WKSTN 1 3 4 A123 35 WKSTN 2 1 2 A123 35 WKSTN 2 2 3 A123 35 WKSTN 2 3 4 B456 0 WKSTN 3 1 2 B456 0 WKSTN 3 2 3 B456 0 WKSTN 3 3 4 ???? 5 NULL 1 2 ???? 5 NULL 2 3 ???? 5 NULL 3 4
So, what I want, it's a full outer join of t1 and t2 on workstation and a cross join of one with the t3. I wonder if I can't find examples of it online because it is not possible...SELECT t1.workstation , SUM(t1.my_value) , t2.wkstn_name , t3.my_nbr1 , t3.my_nbr2 FROM my_tab1 t1 , my_tab2 t2 , my_tab3 t3 ...
Note: I'm stuck dealing with Oracle 8i
Thank you!!Hello
The query I posted yesterday is a little more complex that it should be.
My_tab2.workstation is unique, there is no reason to make a separate subquery as mt1. We can join my_tab1 to my_tab2 and get the SUM in a subquery.SELECT foj.workstation , foj.sum_my_value , foj.wkstn_name , mt3.my_nbr1 , mt3.my_nbr2 FROM ( -- Begin in-line view foj for full outer join SELECT mt1.workstation , SUM (mt1.my_value) AS sum_my_value , mt2.wkstn_name FROM my_tab1 mt1 , my_tab2 mt2 WHERE mt1.workstation = mt2.workstation (+) GROUP BY mt1.workstation , mt2.wkstn_name -- UNION ALL -- SELECT workstation , 0 AS sum_my_value , wkstn_name FROM my_tab2 WHERE workstation NOT IN ( -- Begin NOT IN sub-query SELECT workstation FROM my_tab1 WHERE workstation IS NOT NULL ) -- End NOT IN sub-query ) foj -- End in-line view foj for full outer join , my_tab3 mt3 ORDER BY foj.wkstn_name , foj.workstation , mt3.my_nbr1 , mt3.my_nbr2 ;
Thanks for posting the CREATE TABLE and INSERT statements, and very clear expected results!
user11033437 wrote:
... So, what I want, it's a full outer join of t1 and t2 on workstation and a cross join of one with the t3.She, exactly!
The trickiest part is when and how get SUM (my_value). You could address the question of exactly what my_tab3 must be attached to a cross that's exactly what should look like the result set of the full outer join between my_tab1 and my_tab2 to. To do this, take your desired results, remove columns that do not come from the outer join complete and delete duplicate rows. You will get:workstation sum(my_value) wkstn_name ----------- ------------- ---------- ABCD 30 WKSTN 1 A123 35 WKSTN 2 B456 0 WKSTN 3 ???? 5 NULL
So the heart of the problem is how to get these results of my_tab1 and my_tab2, which is done in the subquery FOJ above.
I tried to use auto-documenté in my code names. I hope you can understand.
I could spend hours explaining the different parts of this query more in detail, but I don't know that I would lose some of that time, explain things that you already understand. If you want an explanation of the specific element (s), let me know. -
He had to know the right outer join using...
He had to know the right outer join using...
For example: first query left outer join for the emp table: SELECT EMPNO, ENAME, D.DEPTNO FROM EMP E, Department D WHERE the E.DEPTNO = D.DEPTNO)
Second query left outer join for the Dept table: SELECT EMPNO, ENAME, D.DEPTNO FROM EMP E, Department D WHERE the D.DEPTNO = E.DEPTNO)
In the example above I just Exchange where condition condition to get an outer join of two table with a left outer join itself. Wat is use right outer join, instead, I can swap the status of table name for the result. Please suggest...
Hello
chan001 wrote:
He had to know the right outer join using...
For example: first query left outer join for the emp table: SELECT EMPNO, ENAME, D.DEPTNO FROM EMP E, Department D WHERE the E.DEPTNO = D.DEPTNO)
Second query left outer join for the Dept table: SELECT EMPNO, ENAME, D.DEPTNO FROM EMP E, Department D WHERE the D.DEPTNO = E.DEPTNO)
In the example above I just Exchange where condition condition to get an outer join of two table with a left outer join itself. Wat is use right outer join, instead, I can swap the status of table name for the result. Please suggest...
The two examples above use the old syntax outer join of Oracle. (I guess there should be a sign inside the parentheses, e.g.. +)
... WHERE E.DEPTNO = D.DEPTNO (+)
)
The LEFT OUTER JOIN and RIGHT OUTER JOIN terms apply only to the ANSI join syntax, e. g.
.
.. FROM EMP E
DEPT LEFT OUTER JOIN D ON E.DEPTNO = D.DEPTNO
As Blushadow said above, there's no real point in having LEFT OUTER JOIN and RIGHT OUTER JOIN; What you can do with one (or a combination of both) can be done with the other. Most people use LEFT OUTER JOIN systematically and never use RIGHT OUTER JOIN.
There are situations where using a combination of the two would mean a little less striking, but only a little less and this kind of situation is very common, and one may wonder if the somewhat shorter code is more specific. I suggest that forget you RIGHT OUTER JOIN.
-
Problem with Oracle performance
Hi all
I use Oracle database 11 g 2.
I am facing a problem with one of my queries.
Scenario is:
I associate myself with 3 tables.
The engine is saa_hist.saa_rep_product_activity (70 million lines).
The second table is scmsa_hist.scmsa_sub_feature_trueup (900 million lines).
The third table is saa_hist.saa_rep_subscriber_activity (35 million lines).
The output of the query will be only about 120K.
I'm majoriy of the columns in the first table. On the other hand, we get 2 columns and in table 3, we get a single column.
When I join all 3 tables as it appears in the query runs for 6 hours. (The
SELECT / * + PARALLEL_INDEX(R,SAA_REP_PRODUCT_ACTIVITY_BI,12)
PARALLEL(SUB,24)
PARALLEL_INDEX(RR,SAA_REP_SUBSCRIBER_ACTIVITY_I1,8)
*/
R.*, sub.mrc, sub. RATEPLANCODE, rr.measure_group_id
Saa_hist.saa_rep_product_activity r
JOIN scmsa_hist.scmsa_sub_feature_trueup sub
ON sub.job_log_id = r.job_log_id
AND sub.service_number = r.msisdn
AND sub.ban = r.account_number
AND sub.soc_code = r.product_id_code
LEFT OUTER JOIN saa_hist.saa_rep_subscriber_activity rr
ON rr.quantity = 1
AND rr.service_universal_id = r.service_universal_id
AND rr.msisdn = r.msisdn
AND rr.account_number = r.account_number
WHERE r.billing_subsystem_id = 1
AND 1 = 1
AND r.batch_key BETWEEN 674 AND 675;
The explain command plan looks good for this one and the cost is also okay(222K). I don't see any S-> data flow in the Section of IN-OUT of the explain plan P.
-----------------------------------------------------------------------------------------------------------------
| ID | Operation | Name | TQ | IN-OUT | PQ Distrib.
-----------------------------------------------------------------------------------------------------------------
| 0 | SELECT STATEMENT |
| 1. COORDINATOR PX |
| 2. PX SEND QC (RANDOM). : TQ10001 | Q1, 01 | P > S | QC (RAND) |
| 3. NESTED EXTERNAL LOOPS | Q1, 01 | SVCP |
| 4. HASH JOIN | Q1, 01 | SVCP |
| 5. JOIN FILTER PART CREATE | : BF0000 | Q1, 01 | SVCP |
| RECEIVE 8 2 PX | Q1, 01 | SVCP |
| 7. PX SEND LOCAL BROADCAST | : TQ10000 | Q1 00 | P > P | BCST LOCAL |
| 8. PX HASH PARTITION ALL | Q1 00 | ISSUE |
| 9. TABLE ACCESS BY LOCAL INDEX ROWID | SAA_REP_PRODUCT_ACTIVITY | Q1 00 | SVCP |
| 10. CONVERSION OF BITMAP IN ROWID | Q1 00 | SVCP |
| 11. BITMAP INDEX RANGE SCAN | SAA_REP_PRODUCT_ACTIVITY_BI | Q1 00 | SVCP |
| 12. FILTER-HASH PARTITION PX JOIN | Q1, 01 | ISSUE |
| 13. TABLE ACCESS FULL | SCMSA_SUB_FEATURE_TRUEUP | Q1, 01 | SVCP |
| 14. RANGE OF PARTITION ALL THE | Q1, 01 | SVCP |
| 15. HASH PARTITION ALL | Q1, 01 | SVCP |
| 16. TABLE ACCESS BY LOCAL INDEX ROWID | SAA_REP_SUBSCRIBER_ACTIVITY | Q1, 01 | SVCP |
| 17. INDEX RANGE SCAN | SAA_REP_SUBSCRIBER_ACTIVITY_I1 | Q1, 01 | SVCP |
-----------------------------------------------------------------------------------------------------------------
But when I joined the first two tables and run as shown below, the request is get executed in 13 Minutes.
SELECT / * + PARALLEL_INDEX(R,SAA_REP_PRODUCT_ACTIVITY_BI,12)
PARALLEL(SUB,24)
*/
R.*, sub.mrc, sub. RATEPLANCODE, rr.measure_group_id
Saa_hist.saa_rep_product_activity r
JOIN scmsa_hist.scmsa_sub_feature_trueup sub
ON sub.job_log_id = r.job_log_id
AND sub.service_number = r.msisdn
AND sub.ban = r.account_number
AND sub.soc_code = r.product_id_code;
Therefore, I created a temporary table with this data and made a left outer join with the other 3 table. It runs a few seconds and I can say all the data I am able to take less than 15 minutes to 6 hours.
So my question is that why Oracle is a strange behavior.
I tried all approaches to avoid this kind of behavior methods but unable to produce the same thing as how I did in the second approach.
For example, I joined the first two tables and use NO_MERGE hint with the third table and always NO_MERGE, PUSH_PRED's not going anywhere. I tried Inline view and it doesn't give me any improvement in performance.
I'm tempted to do it using WITH Clause with two tables and then joined the data set with the third table. But still does not.
I tried hint ORDINATE and yet so big difference.
I even tried to force some clues which are presentm, but the 50Million cost ranges from 200K.
I think I'm exhausted all the possibilities.
I'd appreciate any Oracle guru can help me what is the issue.
Thank you
NKMYou could start trying to impose (with extensive predicates) what you discover or believe work better.
In this case I usually found the ansi syntax not useful and often the optimizer ignore my intentions:(mais il n'y a pas de mal essayer)select x.*, rr.measure_group_id from (select r.* sub.mrc, sub.rateplancode, from (select * from saa_hist.saa_rep_product_activity where billing_subsystem_id = 1 and batch_key between 674 and 675 ) r, scmsa_hist.scmsa_sub_feature_trueup sub where sub.job_log_id = r.job_log_id and sub.service_number = r.msisdn and sub.ban = r.account_number and sub.soc_code = r.product_id_code ) x, (select service_universal_id, account_number, msisdn, measure_group_id from saa_hist.saa_rep_subscriber_activity where quantity = 1 ) rr where x.service_universal_id = rr.service_universal_id(+) and x.msisdn = rr.msisdn(+) and x.account_number = rr.account_number(+)
Concerning
Etbin
Maybe you are looking for
-
Hello! I want to know. Mounted iMac SSD (new), it connects via SATA and PCI-E?
-
Clock widget will not be updated properly after 2.2.2
I noticed that after the recent 2.2.2 downloaded all the widgets clock on my 2 Ciq update not timely. I tried a few of those. This includes the Motorola Date/time widget. Several times the displayed time is running 10-15 minutes late. Anyone experinc
-
How to buy an old drive recovery for HP 2000-2d29WM of 2 months?
I spent all day and half the night trying to get some help with this unwanted piece of portable. I refuse to jump through the hoops, with a person to halfway around the world that I can barely understand. All I want is a way to make a recovery for
-
WMIC command fails for the domain user
Hi all I use windows 7 and testing commands wmic as below WMIC/node: "Computer1" / User: "domain\username" / Password: "password" PROCESS CALL Create "calc.exe" Most of the time control fails with RPC server unavailable to users in the domain (defaul
-
Vista SP2 and Vipre Premium Version 4
I installed Vipre Premium Version 4 on my Vista SP2 computer. It includes a firewall which I am certain is enabled. However, Vista continues to point out that I have no firewall. I walked into the Help menu which told me to go to the Security page