CONNECT BY with CROSS JOIN and WHERE not executing as described in doc
Hello all,
please see these two statements. They are the same, but the 1st uses t1 INNER JOIN t2 while the snd uses a CROSS JOIN with WHERE.
The 2nd statement shows one row more than the first, but the CROSS JOIN with WHERE is the same as the INNER JOIN.
The result would be OK if Oracle did:
JOIN -> CONNECT BY PRIOR -> WHERE
But according to the docs it does:
JOIN (and WHEREs for JOINS) -> CONNECT BY PRIOR -> Rest of WHERE
See http://docs.oracle.com/cd/E11882_01/server.112/e26088/queries003.htm#SQLRF52332 for details. There it says:
Oracle processes hierarchical queries as follows:
A join, if present, is evaluated first, whether the join is specified in the FROM clause or with WHERE clause predicates.
The CONNECT BY condition is evaluated.
Any remaining WHERE clause predicates are evaluated.
+.....+
Is this a bug? I'd say yes, because it differs from the docs and it also is not what people are used to ("a,b WHERE" is the same as "a INNER JOIN b").
Thanks,
Blama
--Statement 1:
WITH t1
AS
(SELECT 1 a, 2 b FROM DUAL UNION ALL
SELECT 2 a, 3 b FROM DUAL UNION ALL
SELECT 3 a, 4 b FROM DUAL UNION ALL
SELECT 4 a, 5 b FROM DUAL UNION ALL
SELECT 5 a, 6 b FROM DUAL),
t2 AS
(SELECT 1 c FROM DUAL UNION ALL
SELECT 2 c FROM DUAL UNION ALL
SELECT 3 c FROM DUAL UNION ALL
SELECT 5 c FROM DUAL)
SELECT DISTINCT t1.a, t2.c, t1.b, level, SYS_CONNECT_BY_PATH(t1.a, '/') Path
FROM t1 INNER JOIN t2
ON t1.a = t2.c
CONNECT BY t1.a = PRIOR t1.b
START WITH t1.a = 1
ORDER BY
1,2,3;
--Result:
--1 1 2 1 /1
--2 2 3 2 /1/2
--3 3 4 3 /1/2/3
--Statement 2:
WITH t1
AS
(SELECT 1 a, 2 b FROM DUAL UNION ALL
SELECT 2 a, 3 b FROM DUAL UNION ALL
SELECT 3 a, 4 b FROM DUAL UNION ALL
SELECT 4 a, 5 b FROM DUAL UNION ALL
SELECT 5 a, 6 b FROM DUAL),
t2 AS
(SELECT 1 c FROM DUAL UNION ALL
SELECT 2 c FROM DUAL UNION ALL
SELECT 3 c FROM DUAL UNION ALL
SELECT 5 c FROM DUAL)
SELECT DISTINCT t1.a, t2.c, t1.b, level, SYS_CONNECT_BY_PATH(t1.a, '/') Path
FROM t1 CROSS JOIN t2
WHERE t1.a = t2.c
CONNECT BY t1.a = PRIOR t1.b
START WITH t1.a = 1
ORDER BY
1,2,3;
--Result:
--1 1 2 1 /1
--2 2 3 2 /1/2
--3 3 4 3 /1/2/3
--5 5 6 5 /1/2/3/4/5My details:
Oracle Database 11g Enterprise Edition Release 11.2.0.2.0 - 64bit Production
PL/SQL Release 11.2.0.2.0 - Production
CORE 11.2.0.2.0 Production
TNS for Solaris: Version 11.2.0.2.0 - Production
NLSRTL Version 11.2.0.2.0 - Production
blama wrote:
Hello Paul,
that means that "a,b" isn't the same as "a CROSS JOIN b".
I don't think that that is really the case.
Do you have docs on this one?No explicit docs just (my) logic - having said that, I suppose it is implied that if you are doing ANSI style joins, it's not the where clauses that
are specifying the join.
If you do t1,t2 where t1.a=t2.a then Oracle figures out the kind of join from the (relevant) where clauses and treats the other where clauses after the CONNECT BY.
If you do t1 cross join t2 where t1.a=t2.a then you are saying the join is completely specified by the CROSS JOIN - i.e it's Cartesian. Oracle doesn't look at the where clauses for this. Therefore
all where clauses are treated as 'other' and are evaluated after the CONNECT BY.
So, in my mind it's 10g that has the bug.
Similar Messages
-
Absolute dynamic select query with dynamic join and where
Has anyone ever tried creating an absolutely dynamic SELECT query with dynamic Join and Where conditions.
I have a requirement of creating such a query in an Utility Class, and i have written the code. But its throwing my sysntax errors.
Please let me know where am I going wrong OR is it really possible to create such a dynamic Query??
SELECT (FIELDS) INTO TABLE IT_TABLES
FROM ( (ME->TABLE1) inner join ( me->table2 )
on ( on_condition ) )
WHERE (me->where_fields).
Ags.It worked for me in a following way:
select * into corresponding fields of table <result_table>
from (join_string)
where (l_where).
Where the contents of join_string were dynamically build using concatenation. So it will be something like
concatenate ME->TABLE1 'as a INNER JOIN' me->table2 'as b ON (' into join_string separated by space.
<...>
add here matching/reference colums, something like
concatenate 'a~' me->TABLE1_JOIN_COL into temp1.
concatenate 'b~' me->TABLE2_JOIN_COL into temp2.
concatenate join_string temp1 '=' temp2 into join_string separated by space.
<...>
concatenate join_string ')' into join_string separated by space.
And then use similar approach for l_where variable. -
Creative Suite stop working after backing up the program from Time Machine. Adobe is treating people with total disrespect and does not even have a phone number where we could call. I will move soon to other software. I paid for the software and it is totally abusive this behavior from Adobe.
Trying to reinstall via transfer does not work.
Phone support | Orders, returns exchanges
http://helpx.adobe.com/x-productkb/global/phone-support-orders.html
For the link below click the Still Need Help? option in the blue area at the bottom and choose the chat option...
Serial number and activation chat support (non-CC)
http://helpx.adobe.com/x-productkb/global/service1.html ( http://adobe.ly/1aYjbSC ) -
I just started my Macbook air the first time, connected it with my wlan and know it asks me for a password and it does not accept the only password I know, what can I do?
It needs the user password for the wireless router, that would have been set by whomever installed the router, if that was you then try to find the password. If you can not find the password reset the router to factory default and set it up again.
-
Issue with recursive join and filter records
I am having an issue with recursive join and filtering records for the following rules. The table, sample records, test script and rules are as below
drop table PC_COVKEY_PD;
create table PC_COVKEY_PD (
PC_COVKEY varchar(50),
COVERAGE_NUMBER varchar(3),
SEQUENCE_ALPHA varchar(3),
TRANSACTION_TYPE varchar(3),
COV_CHG_EFF_DATE date,
TIMESTAMP_ENTERED timestamp
delete from PC_COVKEY_PD;
commit;
Insert into PC_COVKEY_PD values ('10020335P8017MT0010012','001','001','02',to_date('01/FEB/2010','DD/MON/RRRR'),to_timestamp('02/JAN/2010 01:55:59.990216 AM','DD/MON/RRRR HH12:MI:SS.FF6 AM'));
Insert into PC_COVKEY_PD values ('10020335P8017MT0050012','005','001','02',to_date('01/FEB/2010','DD/MON/RRRR'),to_timestamp('02/JAN/2010 01:56:00.268099 AM','DD/MON/RRRR HH12:MI:SS.FF6 AM'));
Insert into PC_COVKEY_PD values ('10020335P8017MT0010032','001','003','03',to_date('14/JAN/2011','DD/MON/RRRR'),to_timestamp('14/JAN/2011 04:25:19.018217 PM','DD/MON/RRRR HH12:MI:SS.FF6 AM'));
Insert into PC_COVKEY_PD values ('10020335P8017MT0010042','001','004','03',to_date('21/JAN/2011','DD/MON/RRRR'),to_timestamp('21/JAN/2011 04:00:31.719444 PM','DD/MON/RRRR HH12:MI:SS.FF6 AM'));
Insert into PC_COVKEY_PD values ('10020335P8017MT0050022','005','002','03',to_date('21/JAN/2011','DD/MON/RRRR'),to_timestamp('21/JAN/2011 04:02:48.953594 PM','DD/MON/RRRR HH12:MI:SS.FF6 AM'));
commit;
--select * from PC_COVKEY_PD order by COV_CHG_EFF_DATE,TIMESTAMP_ENTERED;
PC_COVKEY COVERAGE_NUMBER SEQUENCE_ALPHA TRANSACTION_TYPE COV_CHG_EFF_DATE TIMESTAMP_ENTERED
10020335P8017MT0010012 001 001 02 01/FEB/2010 02/JAN/2010 01:55:59.990216 AM
10020335P8017MT0050012 005 001 02 01/FEB/2010 02/JAN/2010 01:56:00.268099 AM
10020335P8017MT0010032 001 003 03 14/JAN/2011 14/JAN/2011 04:25:19.018217 PM
10020335P8017MT0010042 001 004 03 21/JAN/2011 21/JAN/2011 04:00:31.719444 PM
10020335P8017MT0050022 005 002 03 21/JAN/2011 21/JAN/2011 04:02:48.953594 PM
*/Rule;
Every PC_COVKEY, query should recursively join and generate set of records depending on latest SEQUENCE_ALPHA for the coverage number at that point of time. For ex,
for 10020335P8017MT0010042 (4 row) should generate 2 records
1. 10020335P8017MT0010042001004 (PC_COVKEY || COVERAGE_NUMBER || latest SEQUENCE_ALPHA--004 for cover 001), SEQUENCE_ALPHA 001 for cover 001 is not the latest for 10020335P8017MT0010042.
2. 10020335P8017MT0010042005001 (coverage number 005, and latest sequence alpha-001 for cover 005).
SEQUENCE_ALPHA 002 for cover 005 is not the latest for 10020335P8017MT0010042 as it happened later stage.
for 10020335P8017MT0050022 (5 row) should generate 2 records as
1. 10020335P8017MT0050022001004 (PC_COVKEY || COVERAGE_NUMBER || latest SEQUENCE_ALPHA--004 for cover 001),
2. 10020335P8017MT0010042005002 (coverage number 005, and latest sequence alpha-002 for cover 005)
WITH SNAPSHOT_CVR_CTP as (
SELECT pcd1.PC_COVKEY,
pcd1.PC_COVKEY||pcd2.COVERAGE_NUMBER||pcd2.SEQUENCE_ALPHA as cov_key,
pcd2.COVERAGE_NUMBER,
pcd2.SEQUENCE_ALPHA,
pcd2.COVERAGE_NUMBER||pcd2.SEQUENCE_ALPHA as CVRSEQ,
max(pcd2.COVERAGE_NUMBER||pcd2.SEQUENCE_ALPHA) over (partition by pcd1.PC_COVKEY, pcd1.COVERAGE_NUMBER
order by pcd2.COV_CHG_EFF_DATE, pcd2.TIMESTAMP_ENTERED) as MaxSeq,
pcd2.COV_CHG_EFF_DATE,
pcd2.TIMESTAMP_ENTERED
FROM
PC_COVKEY_PD pcd1,
PC_COVKEY_PD pcd2
select * from SNAPSHOT_CVR_CTP SC
WHERE sc.PC_COVKEY = '10020335P8017MT0010042' -- 4 row
--AND COVERAGE_NUMBER||SC.MAXSEQ = COVERAGE_NUMBER||SEQUENCE_ALPHA
ORDER BY TIMESTAMP_ENTERED
PC_COVKEY COV_KEY COVERAGE_NUMBER SEQUENCE_ALPHA CVRSEQ MAXSEQ COV_CHG_EFF_DATE TIMESTAMP_ENTERED
10020335P8017MT0010042 10020335P8017MT0010042001001 001 001 001001 001001 01/FEB/2010 02/JAN/2010 01:55:59.990216 AM
10020335P8017MT0010042 10020335P8017MT0010042005001 005 001 005001 005001 01/FEB/2010 02/JAN/2010 01:56:00.268099 AM
10020335P8017MT0010042 10020335P8017MT0010042001003 001 003 001003 005001 14/JAN/2011 14/JAN/2011 04:25:19.018217 PM
10020335P8017MT0010042 10020335P8017MT0010042001004 001 004 001004 005001 21/JAN/2011 21/JAN/2011 04:00:31.719444 PM
10020335P8017MT0010042 10020335P8017MT0010042005002 005 002 005002 005002 21/JAN/2011 21/JAN/2011 04:02:48.953594 PM
I am trying to filter row using MAXSEQ but at the moment MAXSEQ values are not coming as expected. I expect following value for COV_KEY combination
COV_KEY MAXSEQ
10020335P8017MT0010042001001 001004
10020335P8017MT0010042005001 005001 -- match
10020335P8017MT0010042001003 001004
10020335P8017MT0010042001004 001004 -- match
10020335P8017MT0010042005002 005001Would appreciate if anyone can get MAxSEQ as expected.Something like..
with dist_cov_numbers as
select distinct coverage_number cov_number
from PC_COVKEY_PD
all_data as
select pcd.*,d.cov_number new_coverage_number,
max(decode(coverage_number,d.cov_number,sequence_alpha))
over( partition by d.cov_number
order by COV_CHG_EFF_DATE,TIMESTAMP_ENTERED
) max_seq
from PC_COVKEY_PD pcd,dist_cov_numbers d
select pc_covkey,pc_covkey||new_coverage_number||max_seq new_key,
pc_covkey||coverage_number||sequence_alpha actual_key
from all_data
order by COV_CHG_EFF_DATE, TIMESTAMP_ENTERED;
PC_COVKEY NEW_KEY ACTUAL_KEY
10020335P8017MT0010012 10020335P8017MT0010012001001 10020335P8017MT0010012001001
10020335P8017MT0010012 10020335P8017MT0010012005 10020335P8017MT0010012001001
10020335P8017MT0050012 10020335P8017MT0050012001001 10020335P8017MT0050012005001
10020335P8017MT0050012 10020335P8017MT0050012005001 10020335P8017MT0050012005001
10020335P8017MT0010032 10020335P8017MT0010032001003 10020335P8017MT0010032001003
10020335P8017MT0010032 10020335P8017MT0010032005001 10020335P8017MT0010032001003
10020335P8017MT0010042 10020335P8017MT0010042005001 10020335P8017MT0010042001004
10020335P8017MT0010042 10020335P8017MT0010042001004 10020335P8017MT0010042001004
10020335P8017MT0050022 10020335P8017MT0050022005002 10020335P8017MT0050022005002
10020335P8017MT0050022 10020335P8017MT0050022001004 10020335P8017MT0050022005002
10 rows selected Edited by: jeneesh on Nov 22, 2012 10:54 AM -
Good Morning,
I just did a software update on my phone (finally) last night and now my phone will not come on. It keeps showing the charger pointing up to a blue circle with iTunes inside and will not go any further. Can ANYONE help me please???The phone is in restore mode and the picture is telling you what to do. Connect the phone, by cable, to iTunes in the computer you normally use for syncing, and retore the phone.
-
I installed ADE and when I try to download ebook it tries to open with Adobe reader and does not give option to open with ADE
It sounds as if you downloaded Adobe Acrobat Pro. If you did, uninstall it. Then repair Adobe Reader.
The free Acrobat account has no connection to any of this. -
USB drive with install image is showing in Startup Manager on a Mac Pro, but wont boot. Showing circle with cross strip, and shut down automatically. USB device are made and work on two different MacBook Pro, but used on Mac Pro. Any help?
OS X installers have always been fairly specific, hardware-wise. I haven't read anything reflecting that situation with the Recovery HD, so it may be that the Recovery HD created for the MacBook Pro does not have the necessary drivers for the Mac Pro. Obviously, nothing definitive here, but a possibility.
-
When I open my MacBook Air the keyboard comes up along with the screen and does not stay still. So I need to hold down the keyboard while i open it. Other than that it works fine despite the fact that the fan noise some times is loud and sometimes it's getting warm at the base. I wonder if this can be fixed if i go to one of the apple branches.
Yes. Take the computer to the Apple store to have it fixed.
Best -
How can I filter to find photos NOT pinned to a map? I have 28,000 phots with many mapped and many not. The Search function does not include GPS data. I haven't found way to search metadata inside or out of Elements.
How can I filter to find photos NOT pinned to a map? I have 28,000 phots with many mapped and many not. The Search function does not include GPS data. I haven't found way to search metadata inside or out of Elements.
-
Documents edited with added text and sketch not shown while emailing in iPad 2.
Documents edited with added text and sketch not shown while emailing in iPad 2.
Hi Rakmana,
This is most likely an issue with Apple's iOS Mail program's.
I think you are opening your modified PDF in Apple built-in PDF Preview. Apple's code does not properly draw the comments, but if you look at the PDF in virtually any other PDF application that isn't just using Apple''s code, or on any desktop computer, you will see the comments you've added.
Thanks
-Satyadev -
Is there a fix for the connectivity problems with iPhone 5S and ISO 7.0.2?
Is there a fix for the bluetooth connectivity problems with iPhone 5S and ISO 7.0.4?
I am having problems connecting the BT Audio and the handsfree phone connectyion is unreliable in 2012 Mitsubishi Lancer XL.
All worked OK with ISO 6.Hello CraigNicholson
You would need to sync with iTunes to get that process to work for you. Check out the article below for more information on how to resolve that issue to get the proper token to use Push Notifications again.
iPad and iPod touch: Unable to use YouTube or Push notifications
http://support.apple.com/kb/ts3305
Regards,
-Norm G. -
am unable to burn any info-photo ect on to a disk. I have a 27" I mac mid 2010 version. I put in a disk, hit burn, it runs for about 3 mins and ejects the disk sayiny there was an error with the drive and will not restart.
The optical drive has probably failed. It's a fairly common thing with these slim SuperDrives. Does it read any discs you put into it? You can try resetting the SMC and pram but I'll be surprised if it helps.
To reset the SMC
Shut down the computer.
Unplug the computer's power cord.
Wait fifteen seconds.
Attach the computer's power cord.
Wait five seconds, then press the power button to turn on
Resetting PRAM and NVRAM
Shut down the computer.
Locate the following keys on the keyboard: Command, Option, P, and R. You will need to hold these keys down simultaneously in step 4.
Turn on the computer.
Press and hold the Command-Option-P-R keys. You must press this key combination before the gray screen appears.
Hold the keys down until the computer restarts and you hear the startup sound for the second time.
Release the keys. -
I recently got my iphone from AT&T which came with a charger and know the charger says "this cable is incompatible with this iphone and is not reliable" can anyone tell me how I can fix this or what to do?
Contact AT&T to have them replace the cable.
-
love firefox but am running on MAC OS X 4.0 still. what version of firefox can i download to be compatible with my system and where can i download? jo
Firefox 3.6.21 - http://www.mozilla.com/en-US/firefox/all-older.html
Maybe you are looking for
-
Extracting data from Oracle to a flat file
I'm looking for options to extract data a table or view at a time to a text file. Short of writing the SQL to do it, are there any other ideas? I'm dealing with large volumes of data, and would like a bulk copy routine. Thanks in advance for your hel
-
IPod Software Update Server can not be contacted
I have a vintage iPod Mini that I am attempting to Restore on a iMac PPC with iTunes 9. When I select the Restore button in iTunes, a dialog box appears stating that the iPod Update Server can not be contacted. Resolutions from the iTunes Help rela
-
Mail Adapter ZIP File Attachment
Hello, I have created an interface using the mail receiver to mail a file as an attachment to an email address. I have used an ABAP mapping to create the Mail message associating the required content of Mail message. This all works fine and the email
-
Why is audio out-of-synch with video on VOB files
I used a Pioneer DVR to import ~120 8mm and Hi8mm and Digital8 analog tapes to convert them to DVD's. These ~120 DVD's are in VOB format. These are 4:3 video (not HD). I did test this flow and didn't notice a few of the VOB's did not have the audi
-
How to change the height and width of a control?
Dear all, is there anyway to change the height and width of a control? In the property nodes, i am just able to read the bound values but cudnt write to it. How can i set the bound values for a control? Thanks, Ritesh