Cross-join statements
Can someone explain me, why result of this query:
select * from sys.v_$sql
where hash_value in
(select hash_value from sys.v_$sql_plan
where options = 'CARTESIAN' and operation LIKE '%JOIN%' )
order by hash_value; is that statement:
select count(1) from all_objects where object_name = :1;My point to run this query is find all cartesian join statements.
I am not sure but may it has something to do with multiple tables used through the view "all_objects" ...
Regards
Similar Messages
-
Hi,
I have queried the cross join of 2 select statements:
select * from (select statement 1 .......) t1
cross join
(select statement 2 ....) t2
I get different results when I’m changing the order of the tables in the cross join statement:
select * from (select statement 2 .......) t2
cross join
(select statement 1 ....) t1
How could it be?
AviadHi, thank u for your patience.
CREATE TABLE "AVIAD"."LapTopSales" ("Customer " NVARCHAR2(50),
"ID" NVARCHAR2(50), "Price" FLOAT(126), "Product"
NVARCHAR2(50), "Purchase date" DATE, "Store City"
NVARCHAR2(50), "Store Price" FLOAT(126))
insert into "AVIAD"."LapTopSales" values ('L','P0',7555,'Dell P600','2007-04-23 00:00:00','Herzliya',7000);
insert into "AVIAD"."LapTopSales" values ('XKQF','P1',7834,'Toshiba P200-140','2007-04-23 00:00:00','Tel Aviv',6500);
insert into "AVIAD"."LapTopSales" values ('NXPD','P2',5631,'HP NX530','2007-04-23 00:00:00','Tel Aviv',4600);
insert into "AVIAD"."LapTopSales" values ('TPPFD','P3',7555,'Acer 3600','2007-04-23 00:00:00','Haifa',7000);
insert into "AVIAD"."LapTopSales" values ('GYT','P4',7555,'Acer 3600','2007-04-23 00:00:00','Jerusalem',7000);
insert into "AVIAD"."LapTopSales" values ('T','P5',5631,'HP NX530','2007-04-23 00:00:00','Jerusalem',4600);
insert into "AVIAD"."LapTopSales" values ('JCHD','P6',3212,'Acer 2400','2007-04-23 00:00:00','Herzliya',2700);
insert into "AVIAD"."LapTopSales" values ('FMYYY','P7',4821,'Dell P500','2007-04-23 00:00:00','Jerusalem',4100);
insert into "AVIAD"."LapTopSales" values ('AA','P8',8260,'Toshiba L30-10X','2007-04-23 00:00:00','Jerusalem',7102);
insert into "AVIAD"."LapTopSales" values ('XMPQP','P9',4821,'Dell P500','2007-04-23 00:00:00','Tel Aviv',4100);
insert into "AVIAD"."LapTopSales" values ('NL','P10',7900,'Acer 3800','2007-04-23 00:00:00','Tel Aviv',7200);
insert into "AVIAD"."LapTopSales" values ('AXP','P11',9225,'Sony V4-6X','2007-04-23 00:00:00','Jerusalem',8000);
insert into "AVIAD"."LapTopSales" values ('RDUJ','P12',7900,'Acer 3800','2007-04-23 00:00:00','Herzliya',7200);
insert into "AVIAD"."LapTopSales" values ('VHA','P13',4821,'Dell P500','2007-04-23 00:00:00','Tel Aviv',4100);
insert into "AVIAD"."LapTopSales" values ('WOR','P14',3512,'Dell P400','2007-04-23 00:00:00','Jerusalem',3000);
insert into "AVIAD"."LapTopSales" values ('DDVU','P15',3212,'Acer 2400','2007-04-23 00:00:00','Tel Aviv',2700);
insert into "AVIAD"."LapTopSales" values ('OE','P16',3821,'Acer 2500','2007-04-24 00:00:00','Tel Aviv',2900);
insert into "AVIAD"."LapTopSales" values ('NS','P17',9225,'Sony V4-6X','2007-04-24 00:00:00','Haifa',8000);
insert into "AVIAD"."LapTopSales" values ('DJ','P18',3961,'HP NX7300','2007-04-24 00:00:00','Natanya',3000);
insert into "AVIAD"."LapTopSales" values ('CXQ','P19',7555,'Acer 3600','2007-04-24 00:00:00','Natanya',7000);
insert into "AVIAD"."LapTopSales" values ('FG','P20',7412,'Sony V1-2X','2007-04-24 00:00:00','Tel Aviv',6300);
insert into "AVIAD"."LapTopSales" values ('TVE','P21',4821,'Dell P500','2007-04-24 00:00:00','Jerusalem',4100);
insert into "AVIAD"."LapTopSales" values ('VERW','P22',3733,'Toshiba L40-13G','2007-04-24 00:00:00','Jerusalem',3000);
insert into "AVIAD"."LapTopSales" values ('PA','P23',3212,'Acer 2400','2007-04-24 00:00:00','Tel Aviv',2700);
insert into "AVIAD"."LapTopSales" values ('WDJPQ','P24',4821,'Dell P500','2007-04-24 00:00:00','Natanya',4100);
insert into "AVIAD"."LapTopSales" values ('IKNE','P25',7412,'Sony V1-2X','2007-04-24 00:00:00','Herzliya',6300);
insert into "AVIAD"."LapTopSales" values ('LF','P26',3733,'Toshiba L40-13G','2007-04-24 00:00:00','Haifa',3000);
insert into "AVIAD"."LapTopSales" values ('J','P27',3212,'Acer 2400','2007-04-24 00:00:00','Natanya',2700);
insert into "AVIAD"."LapTopSales" values ('CW','P28',8260,'Toshiba L30-10X','2007-04-24 00:00:00','Jerusalem',7102);
insert into "AVIAD"."LapTopSales" values ('JLHJ','P29',4821,'Dell P500','2007-04-24 00:00:00','Natanya',4100);
insert into "AVIAD"."LapTopSales" values ('RE','P30',4821,'Dell P500','2007-04-24 00:00:00','Jerusalem',4100);
insert into "AVIAD"."LapTopSales" values ('KMI','P31',8331,'Sony V1-4X','2007-04-24 00:00:00','Tel Aviv',7100);
insert into "AVIAD"."LapTopSales" values ('D','P32',7555,'Acer 3600','2007-04-24 00:00:00','Herzliya',7000);
insert into "AVIAD"."LapTopSales" values ('EL','P33',8331,'Sony V1-4X','2007-04-24 00:00:00','Natanya',7100);
insert into "AVIAD"."LapTopSales" values ('SI','P34',7100,'HP NX800','2007-04-24 00:00:00','Tel Aviv',6400);
insert into "AVIAD"."LapTopSales" values ('NWVVO','P35',7834,'Toshiba P200-140','2007-04-24 00:00:00','Tel Aviv',6500);
insert into "AVIAD"."LapTopSales" values ('RJT','P36',8331,'Sony V1-4X','2007-04-24 00:00:00','Herzliya',7100);
insert into "AVIAD"."LapTopSales" values ('MTMY','P37',7900,'Acer 3800','2007-04-24 00:00:00','Jerusalem',7200);
insert into "AVIAD"."LapTopSales" values ('LOTD','P38',3212,'Acer 2400','2007-04-24 00:00:00','Herzliya',2700);
insert into "AVIAD"."LapTopSales" values ('LIXWF','P39',3733,'Toshiba L40-13G','2007-04-24 00:00:00','Natanya',3000);
insert into "AVIAD"."LapTopSales" values ('F','P40',7100,'HP NX800','2007-04-24 00:00:00','Natanya',6400);
insert into "AVIAD"."LapTopSales" values ('B','P41',4821,'Dell P500','2007-04-24 00:00:00','Natanya',4100);
insert into "AVIAD"."LapTopSales" values ('ALT','P42',3212,'Acer 2400','2007-04-24 00:00:00','Herzliya',2700);
insert into "AVIAD"."LapTopSales" values ('CMPLT','P43',3821,'Acer 2500','2007-04-24 00:00:00','Jerusalem',2900);
insert into "AVIAD"."LapTopSales" values ('YUPP','P44',3961,'HP NX7300','2007-04-24 00:00:00','Tel Aviv',3000);
insert into "AVIAD"."LapTopSales" values ('NQEQR','P45',3733,'Toshiba L40-13G','2007-04-24 00:00:00','Tel Aviv',3000);
insert into "AVIAD"."LapTopSales" values ('OPKNF','P46',3821,'Acer 2500','2007-04-24 00:00:00','Herzliya',2900);
insert into "AVIAD"."LapTopSales" values ('XQOGN','P47',3212,'Acer 2400','2007-04-24 00:00:00','Tel Aviv',2700);
insert into "AVIAD"."LapTopSales" values ('ET','P48',3733,'Toshiba L40-13G','2007-04-24 00:00:00','Tel Aviv',3000);
insert into "AVIAD"."LapTopSales" values ('A','P49',3212,'Acer 2400','2007-04-24 00:00:00','Natanya',2700);
insert into "AVIAD"."LapTopSales" values ('VEVD','P50',3733,'Toshiba L40-13G','2007-04-24 00:00:00','Haifa',3000);
insert into "AVIAD"."LapTopSales" values ('JXPRH','P51',3733,'Toshiba L40-13G','2007-04-24 00:00:00','Haifa',3000);
insert into "AVIAD"."LapTopSales" values ('QJBMI','P52',9225,'Sony V4-6X','2007-04-24 00:00:00','Natanya',8000);
insert into "AVIAD"."LapTopSales" values ('LVJJ','P53',3512,'Dell P400','2007-04-24 00:00:00','Jerusalem',3000);
insert into "AVIAD"."LapTopSales" values ('NQUEL','P54',3212,'Acer 2400','2007-04-24 00:00:00','Haifa',2700);
insert into "AVIAD"."LapTopSales" values ('MKV','P55',3212,'Acer 2400','2007-04-24 00:00:00','Herzliya',2700);
insert into "AVIAD"."LapTopSales" values ('NAHMV','P56',3733,'Toshiba L40-13G','2007-04-24 00:00:00','Natanya',3000);
insert into "AVIAD"."LapTopSales" values ('OFLW','P57',3733,'Toshiba L40-13G','2007-04-24 00:00:00','Jerusalem',3000);
insert into "AVIAD"."LapTopSales" values ('QYA','P58',9812,'HP NX7900','2007-04-24 00:00:00','Natanya',7412);
insert into "AVIAD"."LapTopSales" values ('FA','P59',3821,'Acer 2500','2007-04-24 00:00:00','Tel Aviv',2900);
insert into "AVIAD"."LapTopSales" values ('LIEQG','P60',5631,'HP NX530','2007-04-24 00:00:00','Jerusalem',4600);
insert into "AVIAD"."LapTopSales" values ('PEIUW','P61',9912,'Toshiba T50-300','2007-04-24 00:00:00','Tel Aviv',8412);
insert into "AVIAD"."LapTopSales" values ('DHK','P62',4821,'Dell P500','2007-04-24 00:00:00','Jerusalem',4100);
insert into "AVIAD"."LapTopSales" values ('C','P63',8331,'Sony V1-4X','2007-04-24 00:00:00','Natanya',7100);
insert into "AVIAD"."LapTopSales" values ('SA','P64',9812,'HP NX7900','2007-04-24 00:00:00','Tel Aviv',7412);
insert into "AVIAD"."LapTopSales" values ('YVQ','P65',5631,'HP NX530','2007-04-24 00:00:00','Haifa',4600);
insert into "AVIAD"."LapTopSales" values ('MKVRT','P66',5631,'HP NX530','2007-04-24 00:00:00','Haifa',4600);
insert into "AVIAD"."LapTopSales" values ('GLMXN','P67',3212,'Acer 2400','2007-04-24 00:00:00','Haifa',2700);
insert into "AVIAD"."LapTopSales" values ('WTIV','P68',9812,'HP NX7900','2007-04-24 00:00:00','Jerusalem',7412);
insert into "AVIAD"."LapTopSales" values ('JTIY','P69',3961,'HP NX7300','2007-04-24 00:00:00','Herzliya',3000);
insert into "AVIAD"."LapTopSales" values ('FGYW','P70',5631,'HP NX530','2007-04-24 00:00:00','Natanya',4600);
insert into "AVIAD"."LapTopSales" values ('LYMML','P71',3821,'Acer 2500','2007-04-24 00:00:00','Natanya',2900);
insert into "AVIAD"."LapTopSales" values ('SSO','P72',3821,'Acer 2500','2007-04-24 00:00:00','Natanya',2900);
insert into "AVIAD"."LapTopSales" values ('MNVQ','P73',9812,'HP NX7900','2007-04-24 00:00:00','Jerusalem',7412);
insert into "AVIAD"."LapTopSales" values ('P','P74',4821,'Dell P500','2007-04-24 00:00:00','Haifa',4100);
insert into "AVIAD"."LapTopSales" values ('WG','P75',8260,'Toshiba L30-10X','2007-04-24 00:00:00','Herzliya',7102);
insert into "AVIAD"."LapTopSales" values ('OK','P76',7900,'Acer 3800','2007-04-24 00:00:00','Tel Aviv',7200);
insert into "AVIAD"."LapTopSales" values ('V','P77',9812,'HP NX7900','2007-04-24 00:00:00','Haifa',7412);
insert into "AVIAD"."LapTopSales" values ('CIW','P78',7900,'Acer 3800','2007-04-24 00:00:00','Haifa',7200);
insert into "AVIAD"."LapTopSales" values ('EPSW','P79',3512,'Dell P400','2007-04-24 00:00:00','Tel Aviv',3000);
insert into "AVIAD"."LapTopSales" values ('T','P80',8260,'Toshiba L30-10X','2007-04-24 00:00:00','Haifa',7102);
insert into "AVIAD"."LapTopSales" values ('ALB','P81',8331,'Sony V1-4X','2007-04-24 00:00:00','Herzliya',7100);
insert into "AVIAD"."LapTopSales" values ('DA','P82',9225,'Sony V4-6X','2007-04-24 00:00:00','Haifa',8000);
insert into "AVIAD"."LapTopSales" values ('BDUX','P83',3733,'Toshiba L40-13G','2007-04-24 00:00:00','Natanya',3000);
insert into "AVIAD"."LapTopSales" values ('YCWI','P84',3733,'Toshiba L40-13G','2007-04-24 00:00:00','Natanya',3000);
insert into "AVIAD"."LapTopSales" values ('RHBT','P85',5631,'HP NX530','2007-04-24 00:00:00','Jerusalem',4600);
insert into "AVIAD"."LapTopSales" values ('WJFV','P86',5631,'HP NX530','2007-04-24 00:00:00','Jerusalem',4600);
insert into "AVIAD"."LapTopSales" values ('J','P87',7555,'Dell P600','2007-04-24 00:00:00','Jerusalem',7000);
insert into "AVIAD"."LapTopSales" values ('T','P88',5631,'HP NX530','2007-04-24 00:00:00','Natanya',4600);
insert into "AVIAD"."LapTopSales" values ('SVNP','P89',3212,'Acer 2400','2007-04-24 00:00:00','Herzliya',2700);
insert into "AVIAD"."LapTopSales" values ('UBBNQ','P90',3961,'HP NX7300','2007-04-24 00:00:00','Jerusalem',3000);
insert into "AVIAD"."LapTopSales" values ('R','P91',9812,'HP NX7900','2007-04-24 00:00:00','Jerusalem',7412);
insert into "AVIAD"."LapTopSales" values ('DQWP','P92',7100,'HP NX800','2007-04-24 00:00:00','Tel Aviv',6400);
insert into "AVIAD"."LapTopSales" values ('GA','P93',3212,'Acer 2400','2007-04-24 00:00:00','Natanya',2700);
insert into "AVIAD"."LapTopSales" values ('T','P94',4821,'Dell P500','2007-04-24 00:00:00','Herzliya',4100);
insert into "AVIAD"."LapTopSales" values ('RIOR','P95',3961,'HP NX7300','2007-04-24 00:00:00','Haifa',3000);
insert into "AVIAD"."LapTopSales" values ('H','P96',3212,'Acer 2400','2007-04-24 00:00:00','Herzliya',2700);
insert into "AVIAD"."LapTopSales" values ('JWIEE','P97',8260,'Toshiba L30-10X','2007-04-24 00:00:00','Tel Aviv',7102);
insert into "AVIAD"."LapTopSales" values ('LMANP','P98',9341,'Sony V4-8X','2007-04-24 00:00:00','Natanya',8200);
insert into "AVIAD"."LapTopSales" values ('SJQX','P99',3512,'Dell P400','2007-04-24 00:00:00','Tel Aviv',3000);
insert into "AVIAD"."LapTopSales" values ('F','P100',7555,'Dell P600','2007-04-24 00:00:00','Haifa',7000);
insert into "AVIAD"."LapTopSales" values ('XJB','P101',7555,'Acer 3600','2007-04-24 00:00:00','Natanya',7000);
insert into "AVIAD"."LapTopSales" values ('SLXCU','P102',3821,'Acer 2500','2007-04-24 00:00:00','Tel Aviv',2900);
insert into "AVIAD"."LapTopSales" values ('HD','P103',3821,'Acer 2500','2007-04-24 00:00:00','Herzliya',2900);
insert into "AVIAD"."LapTopSales" values ('T','P104',9341,'Sony V4-8X','2007-04-24 00:00:00','Jerusalem',8200);
insert into "AVIAD"."LapTopSales" values ('GFI','P105',7412,'Sony V1-2X','2007-04-24 00:00:00','Herzliya',6300);
insert into "AVIAD"."LapTopSales" values ('YUL','P106',3961,'HP NX7300','2007-04-24 00:00:00','Herzliya',3000);
insert into "AVIAD"."LapTopSales" values ('H','P107',3961,'HP NX7300','2007-04-24 00:00:00','Natanya',3000);
insert into "AVIAD"."LapTopSales" values ('JNBJ','P108',3821,'Acer 2500','2007-04-24 00:00:00','Herzliya',2900);
insert into "AVIAD"."LapTopSales" values ('J','P109',9812,'HP NX7900','2007-04-24 00:00:00','Tel Aviv',7412);
insert into "AVIAD"."LapTopSales" values ('LLJ','P110',9341,'Sony V4-8X','2007-04-24 00:00:00','Natanya',8200);
insert into "AVIAD"."LapTopSales" values ('HAPR','P111',7412,'Sony V1-2X','2007-04-24 00:00:00','Tel Aviv',6300);
insert into "AVIAD"."LapTopSales" values ('SP','P112',7412,'Sony V1-2X','2007-04-24 00:00:00','Herzliya',6300);
insert into "AVIAD"."LapTopSales" values ('S','P113',9812,'HP NX7900','2007-04-24 00:00:00','Tel Aviv',7412);
insert into "AVIAD"."LapTopSales" values ('OVE','P114',9912,'Toshiba T50-300','2007-04-24 00:00:00','Tel Aviv',8412);
insert into "AVIAD"."LapTopSales" values ('L','P115',9812,'HP NX7900','2007-04-24 00:00:00','Haifa',7412);
insert into "AVIAD"."LapTopSales" values ('OGSL','P116',3821,'Acer 2500','2007-04-24 00:00:00','Tel Aviv',2900);
insert into "AVIAD"."LapTopSales" values ('TE','P117',7100,'HP NX800','2007-04-24 00:00:00','Natanya',6400);
insert into "AVIAD"."LapTopSales" values ('XW','P118',3961,'HP NX7300','2007-04-24 00:00:00','Haifa',3000);
insert into "AVIAD"."LapTopSales" values ('TWVR','P119',3821,'Acer 2500','2007-04-25 00:00:00','Natanya',2900); -
I can't figure out how to combine a full outer join with another type of join ... is this possible?
Here's some create table and insert statements for some basic sample data:
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);And, the results I want to get:
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 4I've tried a number of different things, googled my problem, and no luck yet...
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
...So, what I want is a full outer join of t1 and t2 on workstation, and a cross-join of that with t3. I'm wondering if I can't find any examples of this online because it's not possible....
Note: I'm stuck dealing with Oracle 8i
Thanks!!Hi,
The query I posted yesterday is a little more complicated than it needs to be.
Since my_tab2.workstation is unique, there's no reason to do a separate sub-query like mt1; we can join my_tab1 to my_tab2 and get the SUM all in one sub-query.
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, as well as the very clear desired results!
user11033437 wrote:
... So, what I want is a full outer join of t1 and t2 on workstation, and a cross-join of that with t3. That it, exactly!
The tricky part is how and when to get SUM (my_value). You might approach this by figuring out exactly what my_tab3 has to be cross-joined to; that is, exactly what should the result set of the full outer join between my_tab1 and my_tab2 look like. To do that, take your desired results, remove the columns that do not come from the full outer join, and remove the duplicate rows. You'll get:
workstation sum(my_value) wkstn_name
ABCD 30 WKSTN 1
A123 35 WKSTN 2
B456 0 WKSTN 3
???? 5 NULL So the core of the problem is how to get these results from my_tab1 and my_tab2, which is done in sub-query foj above.
I tried to use self-documenting names in my code. I hope you can understand it.
I could spend hours explaining different parts of this query in more detail, but I'm sure I'd waste some of that time explaining things you already understand. If you want an explanation of somthing(s) specific, let me know. -
Hi guys!
I need to implement a CROSS JOIN (cartesian product) based on two tables. To my understanding there is no construct to implement a cross join in OPEN SQL. So the question is first is this correct? And secondly in which way would you then implement a cross join of two tables with the constructs at hand in ABAP?
I have come up with the following solution of cross joining two tables, but would like to know if there is a better (not so ugly way).
Example:
SELECT * FROM tab1 AS t1 JOIN tab2 AS t2 ON t1mandt = t2mandt INTO CORRESPONDING FIELDS OF itab.
Note that this only works if the tables tab1 and tab2 is client dependent.
Regards,
ChristianChristian,
There's no cross join construct in abap. Join statement results in a cartesin product rarely because of completely obsolete statistics missing selection or join conditions.
Try the following join to get result similar to cartesian product
select tab1location tab2matnr into itab
from tab1 join tab2 on tab1location ne tab2matnr.
if you really want to implement cross join, use native sql, try the following code,
beware of cartesian products, Basis folks doesn't like em....
data: begin of itab occurs 0,
loc like tab1-sloc
matnr like tab2-matnr,
end of itab.
exec sql performing append_itab.
select a.loc, b.matnr
into :itab
from tab1 a
cross join tab2 b
endexec.
form append_itab.
append itab.
endform.
Regards
Sridhar. -
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 - Productionblama 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. -
HI,
how we can apply cross joins on select query.plz help me .I am using tables ekko,ekpo and lfa1 .Plz help.Hi Amardeep,
as code given by one of guru's in the above joins statement is good when only if use the KEY-FIELDS in where condition if not it causes performance issue , so that you can use the FOR ALL ENTRIES IN statement which it gives good perfomance.
Table declarations
TABLES: ekko, "Purchasing Document Header
ekpo, "Purchasing Document Item
lfa1. "Vendor Master (General Section)
Declaration of types:
data: BEGIN OF tbl_ekko,
ebeln TYPE ebeln,
lifnr TYPE lifnr,
END OF tbl_ekko.
data: BEGIN OF tbl_ekpo,
ebeln TYPE ebeln,
ebelp TYPE ebelp,
END OF tbl_ekpo.
data: BEGIN OF tbl_lfa1,
lifnr TYPE lifnr
ebelp TYPE ebelp,
END OF tbl_lfa1.
*Selection screen:
PARAMETERS: p_lifnr TYPE lifnr,
p_ebeln type ebeln.
Selection (JOIN):
START-OF-SELECTION.
SELECT lifnr
FROM lfa1
INTO table tbl_lfa1
WHERE lifnr EQ p_lifnr.
if sy-subrc = 0.
sort tbl_lfa1 by lifnr.
endif.
if not tbl_lifnr is initial.
SELECT ebeln lifnr
FROM ekko
INTO table tbl_ekko
FOR ALL INTRIES IN tbl_lfa1
WHERE ebeln EQ p_ebeln
AND lifnr EQ tbl_lfa1-lifnr.
if sy-subrc = 0.
sort tbl_ ekko by ebeln.
endif.
endif.
if not tbl_ekko is initial.
SELECT ebeln ebelp
FROM ekpo
INTO table tbl_ekpo
FOR ALL INTRIES IN tbl_ekko
WHERE ebeln EQ tbl_ekko-eblen.
if sy-subrc = 0.
sort tbl_ ekpo by ebeln.
endif.
endif.
END-OF-SELECTION.
Main program logic:
LOOP AT tbl_ekpo.
read table ekko with key ebeln = tbl_ekpo-ebeln BINARY SEARCH.
if sy-subrc = 0
WRITE: / tbl_ekko-ebeln,
tbl_ekko-ebelp,
tbl_ekpo-lifnr.
endif.
ENDLOOP.
<b>NOTE : use only KEY-FIELDS in WHERE condition for better perfomance</b>
In that above code you can change a/c to ur inputs availabe.
<b>Reward with points if helpful.</b>
Regards,
Vijay -
Fetch multiple rows using cross-join technique
Hello.
Can anyone suggest a method to return 3 rows from a query when only one row would otherwise be returned?
I'm trying to achieve the Logical SQL analog to this -
SELECT x.foo, p.id, p.name FROM people p CROSS JOIN (SELECT 1 AS foo UNION ALL SELECT 2 UNION ALL SELECT 3) x;Reason: I want to force a three (n) row result and use GROUP BY with case statements to create 3-level summary.
Here is a simple Logical SQL expression that works for my OBI setup -
SELECT
"- Nx_CSDG0_Repair_Orders (Depot Repair Views)".Repair_Number saw_0,
"- Nx_CSDG0_Repair_Orders (Depot Repair Views)".SR_Operating_Unit_Name saw_1
FROM
"[Noetix-NoetixGlobalRepository] NoetixViews for Oracle Service"
WHERE
("- Nx_CSDG0_Repair_Orders (Depot Repair Views)".Repair_Number = '338246')But I think I cannot do this -
SELECT
"- Nx_CSDG0_Repair_Orders (Depot Repair Views)".Repair_Number saw_0,
"- Nx_CSDG0_Repair_Orders (Depot Repair Views)".SR_Operating_Unit_Name saw_1
FROM
"[Noetix-NoetixGlobalRepository] NoetixViews for Oracle Service"
CROSS JOIN (SELECT 1 AS foo UNION ALL SELECT 2 UNION ALL SELECT 3)
WHERE
("- Nx_CSDG0_Repair_Orders (Depot Repair Views)".Repair_Number = '338246')But what can I do?
Thank you.
-csHi CSeelig ,
The BI Server uses the ANSI SQL standard. Then all SQL that follows this specification will in OBIEE work.
I have made an example with a densification:
http://gerardnico.com/wiki/dat/obiee/logical_sql/obiee_sql_densification
You will see a cross join to make a densification.
Cheers
Nico -
Difference between Innner Join and Cross Join
Dear all,
select * from tbl1 inner join tbl2 on tbl1.id =tbl2.id
select * from tbl1 cross join tbl2
Works same what is the logical difference between this two statements??
Dilip Patil..INNER Join returns the rows from both tables which has satisfied matching condition.
In
CROSS Join, each record from tbl1 is matched with tbl2. Result would be Number Of rows in tbl1 X Number of rows in tbl2.
Note: If you provide where condition in CROSS JOIN, it will give you same result as your first INNER JOIN query
select * from tbl1 cross join tbl2
where tbl1.id =tbl2.id
-Vaibhav Chaudhari -
Hello Guys,
I have a bit of trouble understanding the MERGE I have written here.
All the code executes without errors. As far as I see,
the below MERGE SELECT is a Cartesian product/cross join and I remember that is not
good. The ON (join condition) seems to be only for the merge into table (T_CLAIMS_BB) and
the table that comes from the select (d).
merge into T_CLAIMS_BB t
using
SELECT sch_vt.SCH#,vert.CNO,vers.SubCNo,regv.ReturnNo,regv.SndReturnNo,sch_vt.MainProd,sch_vt.Prod
FROM mainschema.TCONTRACT vert, mainschema.TVERSCONTRACT vers, commonschema.VC_REGVEREINB regv, myschema.T_CLAIMS_VT sch_vt
) d
ON (
t.sch# = d.sch# AND
SUBSTR(UPPER(t.BOOKINGTEXT),1,2) = d.SndReturnNo AND d.SubCNo IS NULL
) -- Join
when matched then
update
set t.CNO = 'a',
t.ReturnNo = 'a',
t.MainProd = 'b',
t.Prod = 'c';
I wonder now, what is the advantage of using MERGE in my case - if there is one.
Finally I want to demonstrate how the whole thing would look without a MERGE:
SELECT vers.* FROM TVERSCONTRACT vers
LEFT OUTER JOIN myschema.T_CLAIMS_BB sch ON sch.SubCNo = vers.SubCNo
LEFT OUTER JOIN commonschema.VC_REGVEREINB regv ON sch.SCH# = regv.SCH# AND SUBSTR(UPPER(sch.BUCHTEXT),1,2) = regv.SndReturnNo AND sch.SubCNo IS NULL
LEFT OUTER JOIN myschema.T_CLAIMS_VT sch_vt ON sch.SCH# = sch_vt.SCH#Hi,
metalray wrote:
Hello Guys,
I have a bit of trouble understanding the MERGE I have written here.
All the code executes without errors. As far as I see,
the below MERGE SELECT is a Cartesian product/cross join and I remember that is not
good.Cross joins are good for some purposes. In practice, they're useful in only 1 or 2 queries out of every 1000.
Using the old join notation, it was very easy to get a cross join by mistake. Given how rarely cross joins are needed, the vast majority of cross joins (using old notation) were not good, but that was the fault of the programmers and the notation, not an indication that cross join itself was bad.
The ON (join condition) seems to be only for the merge into table (T_CLAIMS_BB) and
the table that comes from the select (d).Exactly!
You can have separate ON conditions inside the USING sub-query, if you need them.
>
merge into T_CLAIMS_BB t
using
SELECT sch_vt.SCH#,vert.CNO,vers.SubCNo,regv.ReturnNo,regv.SndReturnNo,sch_vt.MainProd,sch_vt.Prod
FROM mainschema.TCONTRACT vert, mainschema.TVERSCONTRACT vers, commonschema.VC_REGVEREINB regv, myschema.T_CLAIMS_VT sch_vt
) d
ON (
t.sch# = d.sch# AND
SUBSTR(UPPER(t.BOOKINGTEXT),1,2) = d.SndReturnNo AND d.SubCNo IS NULL
) -- Join
when matched then
update
set t.CNO = 'a',
t.ReturnNo = 'a',
t.MainProd = 'b',
t.Prod = 'c';
I wonder now, what is the advantage of using MERGE in my case - if there is one.I don't see any advantage, but I suspect the statement, as written, is not doing what it's supposed to. If someone made the mistake of using MERGE when UPDATE would be better, that might be the least of the mistakes in this statement.
Finally I want to demonstrate how the whole thing would look without a MERGE:It looks like the MERGE statement above is equivalent to:
UPDATE t_claims_bb
SET cno = 'a'
, returnno = 'a'
, mainprod = 'b'
, prod = 'c'
WHERE UPPER (SUBSTR (bookingtext, 1, 2)) IN
SELECT returnno
FROM commonschema.vc_regvereinb
AND EXISTS
SELECT 1
FROM mainschema.tverscontract
WHERE subcno IS NULL
AND EXISTS
SELECT 1
FROM mainschema.tcontract
AND EXISTS
SELECT 1
FROM myschema.t_claims_vt
;Again, I suspect that the MERGE state,ment above is not doing what it was meant to do, or may coinncidentally be getting the right results on a small sample set. Many of the tables named in the USING clause of the MERGE statement do'nt seem to have much of a role in this problem.
SELECT vers.* FROM TVERSCONTRACT vers
LEFT OUTER JOIN myschema.T_CLAIMS_BB sch ON sch.SubCNo = vers.SubCNo
LEFT OUTER JOIN commonschema.VC_REGVEREINB regv ON sch.SCH# = regv.SCH# AND SUBSTR(UPPER(sch.BUCHTEXT),1,2) = regv.SndReturnNo AND sch.SubCNo IS NULL
LEFT OUTER JOIN myschema.T_CLAIMS_VT sch_vt ON sch.SCH# = sch_vt.SCH#What is this query? Perhaps you meant to have something like this in the USING clause of the MERGE.
I hope this answers your question.
If not, post a little sample data (CREATE TABLE and INSERT statements, relevant columns only) for all the tables involved, and the results you want from that data.
The sample data should show what the tables are like before the MERGE (or UPDATE), and the results will be the contents of the changed table after the MERGE.
Explain, using specific examples, how you get those results from that data.
Always say what version of Oracle you're using. -
Illegal cross join within the same dimension
Hi,
When certain fields are selected within the presentation table an "illegal cross join" error is returned by the BI Server. However if a FACT is added from one of the other presentation tables the "illegal cross join" error goes away. we need to query without fact column.
We are getting following error
State: HY000. Code: 10058. [NQODBC] [SQL_STATE: HY000] [nQSError: 10058] A general error has occurred. [nQSError: 14065] Illegal cross join within the same dimension caused by incorrect subject area setup: [ CALL_CENTER.COUNSELOR_MANAGER T782130] with [ CALL_CENTER.COUNSELOR_HR T781594 On CALL_CENTER.COUNSELOR_HR.MASTER_STAFF_COUNSELOR_ID = CALL_CENTER.MASTER_STAFF_COUNSELOR.MASTER_STAFF_COUNSELOR_ID, CALL_CENTER.MASTER_STAFF_COUNSELOR T781739] (HY000)
Can anybody help me solving this issue.
Thanks,
KS.Please give us an example of what you need.
OBIEE perform a query in the dimension or through the fact table.
You can't join two dimensions in the repository without going through a fact table.
If you need to query without fact column, it's because you have design two dimensions where
normally you can do one.
You have then two solutions :
* change the design of your logical model to make only one dimension.
* use the OBIEE logical SQL in answer.
http://gerardnico.com/wiki/dat/obiee/bi_server/design/obiee_logical_sql
Success
Nico -
Cross Join Records - only want the "latest valid" records depending on Shop-Level
Hi everyone,
I have a problem with the cross join for my retail application.
Initial Situation:
There are several Shops and in also several products. Usually the products are just created on global level so that all shops can access and sell them.
BUT there is a feature, that single shops can create derivations of articles to change some settings for them (e.g. a the price of a certain handy is global 90€ but in one flagship store the price is 80€).
Sample Tables
create table shops(
id number,
name varchar2(64) not null,
hierarchy varchar2(64) not null,
parent number,
PRIMARY KEY (id));
create table articles(
id number,
name varchar2(64) not null,
price number,
shop_id number not null,
PRIMARY KEY (id));
-- create 4 shops with the hierarchy
- Global
|- Shop A
|- Shop B
|- Shop B.1
insert into shops values (0, 'Global', '.0.', null);
insert into shops values (1, 'Shop A', '.0.1.', 0);
insert into shops values (2, 'Shop B', '.0.2.', 0);
insert into shops values (3, 'Shop B.1', '.0.2.3.', 2);
-- insert some articles + derive the 'Article 2' for shop B.1
insert into articles values (0, 'Article 1', 100, 0);
insert into articles values (1, 'Article 2', 90, 0);
insert into articles values (2, 'Article 2', 80, 3); -- derive article 2 for the shop 2 and set price to 80 instead of 90
Sample Statements
-- restrict to 'Article 1' where no derivations exists
select s.*, a.*
from shops s, articles a
where s.hierarchy like '%.' || a.shop_id || '.%' -- ensures that derivations only appear at the level of the shop and not for each shop
and a.name = 'Article 1';
The result gets the one article for each shop. So I have no problem to restrict to a shop id, and getting the article even if it's not created for that shop level.
Shop ID
Shop Name
Hierarchy
Parent
Article ID
Article Name
Price
Article Shop ID
0
Global
.0.
null
0
Article 1
100
0
1
Shop A
.0.1.
0
0
Article 1
100
0
2
Shop B
.0.2.
0
0
Article 1
100
0
3
Shop B.1
.0.2.3.
2
0
Article 1
100
0
-- restrict to 'Article 2' where one derivation exists
select s.*, a.*
from shops s, articles a
where s.hierarchy like '%.' || a.shop_id || '.%' -- ensures that derivations only appear at the level of the shop and not for each shop
and a.name = 'Article 2';
The result of this statement shows, that the "Article 2" is contained two times for the ShopID 3. This is because the Article exists two times in the articles table.
Shop ID
Shop Name
Hierarchy
Parent
Article ID
Article Name
Price
Article Shop ID
0
Global
.0.
null
1
Article 2
90
0
1
Shop A
.0.1.
0
1
Article 2
90
0
2
Shop B
.0.2.
0
1
Article 2
90
0
3
Shop B.1
.0.2.3.
2
1
Article 2
90
0
3
Shop B.1
.0.2.3.
2
2
Article 2
80
3
Problem1
The last result shows my problem very well. I just want to get the highest level of article if there are any derivations.
Problem2
The solution must be very fast, because I have about
3.000 Shops and about
700.000 different Articles (on global level)
Can somebody help my to find a performant solution for my problem?Hi,
In the output for 'Article 2', do you really want prices of 100 and 65? I assume you meant 90 and 80, like this:
ARTICLE
SHOP SHOP ARTICLE ARTICLE _SHOP
_ID _NAME HIERARCHY PARENT _ID _NAME PRICE _ID
0 Global .0. 1 2 90 0
1 Shop A .0.1. 0 1 2 90 0
2 Shop B .0.2. 0 1 2 90 0
3 Shop B.1 .0.2.3. 2 2 2 80 3
Here's how I got the output above:
WITH joined_data AS
SELECT s.id AS shop_id
, s.name AS shop_name
, s.hierarchy
, s.parent
, a.id AS article_id
, a.name AS article_name
, a.price
, a.shop_id AS article_shop_id
FROM shops s
LEFT OUTER JOIN articles a ON a.shop_id = s.id
AND a.name = 'Article 2' -- or whatever
SELECT shop_id
, shop_name
, hierarchy
, parent
, REGEXP_SUBSTR ( SYS_CONNECT_BY_PATH (article_id, '/')
, '(\d+)/*$'
, 1, 1, NULL, 1
) AS article_id
, REGEXP_SUBSTR ( SYS_CONNECT_BY_PATH (article_name, '/')
, '(\d+)/*$'
, 1, 1, NULL, 1
) AS article_name
, REGEXP_SUBSTR ( SYS_CONNECT_BY_PATH (price, '/')
, '(\d+)/*$'
, 1, 1, NULL, 1
) AS price
, REGEXP_SUBSTR ( SYS_CONNECT_BY_PATH (article_shop_id, '/')
, '(\d+)/*$'
, 1, 1, NULL, 1
) AS article_shop_id
FROM joined_data
START WITH parent IS NULL
CONNECT BY parent = PRIOR shop_id
Like everything else in Oracle, it depends on your version.
I used '/' as a delimiter, assuming that character never occurs in the article_name, article_id, price or shop_id. If '/' can occur in any of those columns, you can use any other character as a delimiter. You don't have to use the same delimiter for all 4 columns, but remember to use the same delimiter in REGEXP_SUBSTR that you use in its nested SYS_CONNECT_BY_PATH.
Instead of doing 4 very similar REGEXP_SUBSTR (SYS_CONNECT_BY_PATH ... ) calls, you could do just 1, for article_id, and then join to the articles table to get the other columns. I suspect that the way I posted above is faster. -
Using offset in join statement
hi,
i wanted to use offset in join statement. but it is giving error.
select a~kunnr
a~vkorg
from knvv as inner join zcust
on knvv-kunnr+5(5) = zcust-refid.hi neha,
try this code i tested it.
types: begin of ty_knvv,
INCLUDE type knvv,
kunid type i, " For u type is zcust-refid
end of ty_knvv.
data: it_knvv type STANDARD TABLE OF ty_knvv INITIAL SIZE 0,
wa_knvv type ty_knvv.
select *
from knvv
into table it_knvv.
loop at it_knvv into wa_knvv.
kunid = wa_knvv-kunnr+5(5).
wa_knvv-kunid = kunid.
MOdify it_knvv TRANSPORTING kunid.
read table zcust into wa_zcust with key resid = wa_knvv-kunid.
endloop. -
Query based on "NATURAL JOIN" statement of Oracle9i
I have created following 4 tables
create table CUST_MASTER
(CUST_NO NUMBER(3),CUST_NAME VARCHAR2(20),CUST_CITY VARCHAR2(20));
create table ITEM_MASTER
(ITEM_NO NUMBER(2),ITEM_NAME VARCHAR2(20),
PRICE NUMBER(4));
create table ORDER_HEADER
( ORDER_NO NUMBER(4), CUST_NO NUMBER(3));
create table ORDER_ITEMS
( ORDER_NO NUMBER(4), ITEM_NO NUMBER(2), QTY NUMBER(3));
Based on the above 4 table I have executed the following query.
select c.cust_no, c.cust_name, c.cust_city, oh.order_no, i.item_no, i.item_name, i.price, oi.qty
from cust_master c, item_master i, order_header oh, order_items oi
where c.cust_no = oh.cust_no and oh.order_no = oi.order_no and oi.item_no = i.item_no;
How should I build similar query in Oracle9i making use of "NATURAL JOIN" statement?Hallo,
yes you are correct.
From SQL Reference
NATURAL JOIN The NATURAL keyword indicates that a natural join is being performed. A natural join is based on all columns in the two tables that have the same name. It selects rows from the two tables that have equal values in the relevant columns
Nothing about foreign keys.
Test:
select * from scott.emp natural join scott.dept
DEPTNO EMPNO ENAME JOB MGR HIREDATE SAL COMM DNAME LOC
20 7369 SMITH CLERK 7902 17.12.1980 800 RESEARCH DALLAS
30 7499 ALLEN SALESMAN 7698 20.02.1981 1600 300 SALES CHICAGO
30 7521 WARD SALESMAN 7698 22.02.1981 1250 500 SALES CHICAGO
20 7566 JONES MANAGER 7839 02.04.1981 2975 RESEARCH DALLAS
30 7654 MARTIN SALESMAN 7698 28.09.1981 1250 1400 SALES CHICAGO
30 7698 BLAKE MANAGER 7839 01.05.1981 2850 SALES CHICAGO
10 7782 CLARK MANAGER 7839 09.06.1981 2450 ACCOUNTING NEW YORK
20 7788 SCOTT ANALYST 7566 19.04.1987 3000 RESEARCH DALLAS
10 7839 KING PRESIDENT 17.11.1981 5000 ACCOUNTING NEW YORK
30 7844 TURNER SALESMAN 7698 08.09.1981 1500 0 SALES CHICAGO
20 7876 ADAMS CLERK 7788 23.05.1987 1100 RESEARCH DALLAS
30 7900 JAMES CLERK 7698 03.12.1981 950 SALES CHICAGO
20 7902 FORD ANALYST 7566 03.12.1981 3000 RESEARCH DALLAS
10 7934 MILLER CLERK 7782 23.01.1982 1300 ACCOUNTING NEW YORK
alter table scott.emp drop constraint fk_deptno
select * from scott.emp natural join scott.dept
DEPTNO EMPNO ENAME JOB MGR HIREDATE SAL COMM DNAME LOC
20 7369 SMITH CLERK 7902 17.12.1980 800 RESEARCH DALLAS
30 7499 ALLEN SALESMAN 7698 20.02.1981 1600 300 SALES CHICAGO
30 7521 WARD SALESMAN 7698 22.02.1981 1250 500 SALES CHICAGO
20 7566 JONES MANAGER 7839 02.04.1981 2975 RESEARCH DALLAS
30 7654 MARTIN SALESMAN 7698 28.09.1981 1250 1400 SALES CHICAGO
30 7698 BLAKE MANAGER 7839 01.05.1981 2850 SALES CHICAGO
10 7782 CLARK MANAGER 7839 09.06.1981 2450 ACCOUNTING NEW YORK
20 7788 SCOTT ANALYST 7566 19.04.1987 3000 RESEARCH DALLAS
10 7839 KING PRESIDENT 17.11.1981 5000 ACCOUNTING NEW YORK
30 7844 TURNER SALESMAN 7698 08.09.1981 1500 0 SALES CHICAGO
20 7876 ADAMS CLERK 7788 23.05.1987 1100 RESEARCH DALLAS
30 7900 JAMES CLERK 7698 03.12.1981 950 SALES CHICAGO
20 7902 FORD ANALYST 7566 03.12.1981 3000 RESEARCH DALLAS
10 7934 MILLER CLERK 7782 23.01.1982 1300 ACCOUNTING NEW YORK
ALTER TABLE scott.emp
ADD CONSTRAINT fk_deptno FOREIGN KEY (deptno)
REFERENCES SCOTT.dept (deptno)
ENABLE NOVALIDATE
/Regards
Dmytro Dekhtyaryuk -
Updateable scrollable result sets with join statement
I am writing a generic GUI fronend for any database that has a JDBC2.0 driver available.
I have been using scrollable updateable result sets. These work well for individual tables but as soon as two tables are linked either implicitly or explicitly with a join statement the result set meta data isDefinitelyWriteable is set to false thus preventing the result set from being updated.
Assuming I am using the JDBC-ODBC driver with java sdk1.4.0 and MS Access (although I have used other databases and JDBCs I assume that the one mentioned will be a common combination and needs to work) is there any way of getting linked tables to be updateable with scollable result sets.
I am using scrollable result sets since this prevents the necessity of putting the data in a secondary data store.
I am able to link tables programmatically by requerying the linked table with a new where clause each time the cursor moves in the linked table but this seems rather wasteful. This method is not vey satisfactory when attempting to display data from more than one table which have more than one linked level (i.e. cascaded links).
Is there a simple solution to this problem or do I have to do a rewrite using an update statement instead of having an updateable result set. I assume this method would also require the result set to be reloaded after the update.
Any suggestions much appreciated.I am trying to make the GUI as flexible as possible by constructing "views" which if necessary link tables on one field in each table. This is fine for two tables but when linking to several tables the information thats produced cannot be read easily because as it stands the information from each table is displayed on a separate tabbed page. This mechanism allows me to keep each record set for each table separate and updateable.
Since I could see that this was not very user friendly in the way that it displayed the data I decided to try and introduce a join on two or more tables and hence the introduction of the current problem.
I mentioned that the objective was to be flexible and therefore I also allow queries to be written by the user to facilitate for any shortfalls of the automatic query construction produced by using the "views" mechanism.
So the answer to your question is yes I do control the SQL selections with one mechanism but ultimately no I do not because I provide a fail safe which allows the user to enter arbitary SQL.
I only really want a solution for the controlled SQL construction mechanism where I create the link between two or more tables. As mentioned earlier these are linked on one field only but I wish to provide the option of displaying the result in a single table (tabbed page) rather than spread across multiple tabbed pages. -
Illegal cross join within the same dimension caused by incorrect subject ar
hi!
Imagine the following BMM:
There is one Logical Dimension Table "Service Account" with the following LTS:
- LTS "D_SERVICE"
- LTS "D_SERVICE_CLASS"
- LTS "D_SERVICE_STATUS"
This Logical Tabe "Service Account" joins (One-to-many) with several Fact Tables (other Logical Tables).
In the Physical Layer the joins for the "Service Account" LTS are:
- One-to-many between D_SERVICE_CLASS and D_SERVICE
- One-to-many between D_SERVICE_STATUS and D_SERVICE
The problem is that when I build a report in Answers using only the following columns of the Logical Table "Service Account":
- Service Class Desc (which exists in the Logical Table "Service Account" and in the Physical Table D_SERVICE_CLASS)
- Service Status Desc (which exists in the Logical Table "Service Account" and in the Physical Tabl D_SERVICE_STATUS)
- MSISDN (which existis in the Logical Table "Service Account" and in the Phsyical Table D_SERVICE)
the following error appears:
Estado: HY000. Código: 10058. [NQODBC] [SQL_STATE: HY000] [nQSError: 10058] A general error has occurred. [nQSError: 14065] Illegal cross join within the same dimension caused by incorrect subject area setup: [ (select * from prd.D_SERVICE where SOURCE_SYS in ('ARBOR','PPB') and DW_SERV_ST_ID in (100000003,100000009)) as T1836, D_SERVICE_CLASS T1916] with [ D_SERVICE_STATUS T1948] (HY000)
SQL emitido: SELECT "SERVICE ACCOUNT"."TLC MSISDN9" saw_0, "SERVICE ACCOUNT"."IWS Service Class Desc" saw_1, "SERVICE ACCOUNT"."TLC Service Status Desc" saw_2 FROM "VFPT - Upgrade Siebel" WHERE "SERVICE ACCOUNT"."TLC MSISDN9" = '917330340' ORDER BY saw_0, saw_1, saw_2
Help, please!
Thanks.Physically, only D_SERVICE is joined to the facts. Then D_SERVICE_CLASS is joined to D_SERVICE (one-to-many) and D_SERVICE_STATUS is joined also to D_SERVICE (one-to-many).
In the BMM, there is only one Logical Dimension Table for those 3 physical tables. This Logical Dimension Table is called "Service Account" and has 3 LTS: D_SERVICE, D_SERVICE_CLASS, D_SERVICE_STATUS. The Logical Dimension Table has several logical columns that are associated to those 3 LTS: SERVICE_KEY, SERVICE_CLASS_KEY, SERVICE_STATUS_KEY, SERVICE_MSISDN, SERVICE_CLASS_DESC, SERVICE_STATUS_DESC.
The Logical Dimension Table "Service Account" is then joined to a fact table (one-to-many).
I didn't understand the suggestion about the 3 LTS... Aren't we doing that already? Can you explain it better, please?
thanks.
Maybe you are looking for
-
I bought a copy of Adobe Acrobat 7.1.0 in 2001, and it's been working fine, but now I'm told I need to download a new copy. However, when I get to enter the Serial Number (of the original copy), it says it's invalid. How do I get a new Serial number?
-
System Shutdown and User Logout Freeze
Recently my Powerbook 15" G4 (FW800) compute running 10.5.7 has been having issues with both shutting down and switching to a different user from the Finder Apple menu. You can select "Shutdown" from the Apple Menu and the system appears to close all
-
PSE 9 printing problem with Epson printer
hello there, I am using PSE 9 with Windows XP and Epson 3880 printer. I have re-installed all programs/drivers a couple of times. PSE9 Printer dialogue will not let me print choosing "Let Photoshop Manage Colour". It will only let me print with "Le
-
Keep getting the message, this document too old can't be opened, save it with Pages '09 first? I recently purchased the new Pages, yellow Icon. My old Pages was '08. My new Pages doesn't say what it is except the version 5.0.1. Where do I get vers
-
Canon 1D MK2 - Every other photo is black? HELP
I recently purchased a Canon 1D Mark II. I had it serviced, picking it up last Monday. Nothing was wrong with the camera. A coworker asked to take photos in the office. He stepped away, returning a few minutes later, asking me if the camera's taking