Outer joins don't return expected results in Oracle 10g
I don't know where to report oracle bugs. So I'm writing here for someone to verify it again and report is a bug to oracle.
--Creating two table and inserting records in each tables
create table table1 ( pk_id number(6) primary key, name_tx varchar2(20) );
create table table1_nls (pk_id number(6) primary key, parent_id number(6), heading varchar2(20), lang_code varchar2(3) );
insert into table1 values( 1, 'test1' );
insert into table1_nls values( 1, 1, 'test heading', 'enu' );
--problem is with the following query.
select * from table1, (select parent_id, heading from table1_nls where lang_code = '' ) table1_nls
where table1.PK_ID = table1_nls.PARENT_ID(+) and pk_id = 1
This returns back one row in Oracle 9i, but none in oracle 10g. If I substitute " lang_code = '' " with lang_code='something' or lang_code is null it works fine. The problem is with comparing the empty value ('').
Logically lang_code is null is the right way of writing the query, but empty ('') works in Oracle 9i,
Is this a valid bug?
If not migration steps should account for this in programs.
drop table table1;
drop table table1_nls;
You want to go to metalink.oracle.com and create a "TAR".
Similar Messages
-
LEFT OUTER JOIN not working as expected
I'm testing a query from the portal. I've got two inputs:
products
{"ProductKey":1,"ProductAlternateKey":"abc","Color":"Red"},
{"ProductKey":2,"ProductAlternateKey":"def","Color":"Blue"},
{"ProductKey":3,"ProductAlternateKey":"ghi","Color":"Blue"}
And temperatures:
{"DeviceId":1,"Temperature":99},
{"DeviceId":2,"Temperature":90},
{"DeviceId":2,"Temperature":99},
{"DeviceId":3,"Temperature":50},
{"DeviceId":4,"Temperature":32}
When I test a query with an (inner) join, I get two rows, one for Red and one for Blue as expected. However, when I change to a LEFT OUTER JOIN, I would expect to get three rows... one for Red, one for Blue, and one for NULL color. However, I only get one
row with a NULL color. Here's the query. Is this a bug or am I misunderstanding?
SELECT DateAdd(second,-5,System.TimeStamp) as WinStartTime
, system.TimeStamp as WinEndTime
, b.Color
, Avg(r.Temperature) as AvgTemperature
, Count(*) as EventCount
FROM temperatures r
LEFT OUTER JOIN products b ON r.DeviceId = b.ProductKey and DATEDIFF(hour,r,b) BETWEEN -6 AND 6
GROUP BY TumblingWindow(second, 5), b.Color
(Please excuse the contrived example, the lack of timestamps, and the 12 hour window... just testing.)
http://artisconsulting.com/Blogs/GregGallowayHi Greg,
Thank you for raising this issue.
We have deployed a fix today that corrects LEFT OUTER JOIN behavior on the in-browser query testing experience.
Can you please confirm that the above query and input sources work for you?
Thanks!
Ziv. -
SQL Server 2005 (64 bit) returns truncated text from Oracle 10g (64 bit)
Hi all,
I'm no expert in Oracle so I desperately need your advice.
I'm using SQL Server 2005 (64 bit) and trying to pull data from a Oracle 10g (64 bit) server. I am able to connect to the Oracle server with no problems.
The problem came when I was trying to pull a text column (I think it's BLOB in Oracle) from the Oracle server. The results came back BUT truncated to only 100 characters. (This is a column containing event logs so the text is really really long...)
As you may already know, Microsoft is not providing the driver for this case (which is insanely ridiculous!!!). There is no standard “Microsoft OLE DB Provider for Oracle” which we would normally use to establish a linked server connection to Oracle. Instead, we had to install the provider given by Oracle (Oracle Provider for OLE DB).
I have tried to Google for solutions but didn't find much. Please help! :(
Thanks in advance,
EleniIf this is a one time activity, you need to find a migration utility which will do the job for you. SQL Developer is available had your case been the other way round (migrate from SQL Server to Oracle).
Check out tools from SwisSQL
http://www.swissql.com/products/oracle-to-sqlserver/oracle-to-sql-server.html
Microsoft's own SSMA (I think this is what you are using already)
http://www.microsoft.com/sqlserver/2005/en/us/migration-oracle.aspx
Apart from this, if there are any issues with the tools themselves, you need to get in touch with the respective vendors. -
Executing Procedure in SQL SERVER and Storing the results in Oracle 10g
Hello,
I am trying execute SQL SERVER procedure from Oracle 10g and store the results in a oracle table. When I tried executing the procedure i am getting errors.
I am using Oracle Heteroeneous Services.
Steps I followed.
1. Created ODBC DSN on Oracle Server connecting to SQL SERVER database.
2. Created Listner entry and TNSNAMES entries.
3. Created Database link and able to select the data from the SQL SERVER tables.
Here is the code i tried to execute the procedure.
BEGIN
"META"."extract"@abc;
END;
"META"."extract"@abc;
ERROR at line 2:
ORA-06550: line 2, column 1:
PLS-00201: identifier 'META.extract@ABC' must be declared
ORA-06550: line 2, column 1:
PL/SQL: Statement ignored
Please help me.
Thank You,
Seshadri ThopeHi thopevs,
Can you please tell me the right syntax of calling procedures(on sql server) from oracle?
I am getting following error:
SQL> execute "GetdateSys"@oratosql;
begin "GetdateSys"@oratosql; end;
ORA-06550: line 2, column 7:
PLS-00201: identifier 'GetdateSys@ORATOSQL' must be declared
ORA-06550: line 2, column 7:
PL/SQL: Statement ignored
SQL>
Your help will be highly appreciated.
Thanks & Regards,
M.U.N.A -
11g outer join with case statement - strange results.
Hello All,
I am experiencing a strange issues in 11g while using case statement.
I am not able to reproduce this using sample data. Not sure what is wrong.
I am not narrowing it to say the usage of case statemnt is giving wrong results, but that is my observation when I am doing trail and error testing.
Here are the details.
My Version
SQL> select * from v$version;
BANNER
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 Linux: Version 11.2.0.2.0 - Production
NLSRTL Version 11.2.0.2.0 - Production
SQL> My Query
SELECT *
FROM (SELECT DISTINCT mf.schedule,
mf.cptcode,
NVL (mf.modifier, '00') modifier2,
CASE
WHEN mf.feetype = 'H'
AND mf.multiplier IS NOT NULL THEN
' 0.00'
WHEN (mf.feetype != 'H'
OR mf.feetype IS NULL)
AND mf.rbrvsvalue IS NOT NULL
AND mf.multiplier IS NOT NULL THEN
LPAD ( TRIM (TO_CHAR ( (mf.rbrvsvalue * mf.multiplier) / 100, 9999999.99)), 10)
ELSE
NULL
END
fee
FROM provider.mpifee mf, mpi_udffee.udffeeactivecptcodes vld
WHERE mf.schedule = 'SAPG1'
AND mf.cptcode = vld.cptcode
AND NVL (mf.modifier, 'NULL') = NVL (vld.modifier, 'NULL')) inline_fee,
(SELECT arc.schedule col1, arc.procedurecode col2, NVL (arc.modifier, '00') AS col3
FROM mpi_udffee.udffeeancfeedata arc
WHERE monthofextract = '201202'
AND arc.schedule = 'SAPG1'
AND TRUNC (SYSDATE - 10) BETWEEN arc.recordeffectivedate AND arc.recordterminationdate) inline_data
WHERE inline_fee.schedule = inline_data.col1(+)
AND inline_fee.cptcode = inline_data.col2(+)
AND inline_fee.modifier2 = inline_data.col3(+);
In the above query the inline view inline_data returns zero rows. but NVL is still getting applied for col3 and I am getting 00 in the results( strange ).
Results:
SCHEDULE CPTCO MODIFIER2 FEE COL1 COL2 COL3
SAPG1 49590 00 667.32 00
SAPG1 49611 00 781.03 00
SAPG1 49905 00 443.79 00
SAPG1 50205 00 883.56 00
SAPG1 50220 00 1315.15 00
SAPG1 50230 00 1638.74 00
SAPG1 50234 00 1666.16 00
SAPG1 50250 00 1566.14 00
SAPG1 50327 00 262.04 00
SAPG1 50541 00 1183.31 00
SAPG1 50620 00 1156.88 00
SAPG1 50650 00 1321.96 00
497 rows selected.
Just the inline view inline_data,
SQL> SELECT arc.schedule col1, arc.procedurecode col2, NVL (arc.modifier, '00') AS col3
2 FROM mpi_udffee.udffeeancfeedata arc
3 WHERE monthofextract = '201202'
4 AND arc.schedule = 'SAPG1'
5 AND TRUNC (SYSDATE - 10) BETWEEN arc.recordeffectivedate AND arc.recordterminationdate;
no rows selectedMuch unusual thing is when I just remove the case statement from the inline view "inline_fee", I am getting right results,
SELECT *
FROM (SELECT DISTINCT mf.schedule,
mf.cptcode,
NVL (mf.modifier, '00') modifier2 <-- Removed Case statement here
FROM provider.mpifee mf, mpi_udffee.udffeeactivecptcodes vld
WHERE mf.schedule = 'SAPG1'
AND mf.cptcode = vld.cptcode
AND NVL (mf.modifier, 'NULL') = NVL (vld.modifier, 'NULL')) inline_fee,
(SELECT arc.schedule col1, arc.procedurecode col2, NVL (arc.modifier, '00') AS col3
FROM mpi_udffee.udffeeancfeedata arc
WHERE monthofextract = '201202'
AND arc.schedule = 'SAPG1'
AND TRUNC (SYSDATE - 10) BETWEEN arc.recordeffectivedate AND arc.recordterminationdate) inline_data
WHERE inline_fee.schedule = inline_data.col1(+)
AND inline_fee.cptcode = inline_data.col2(+)
AND inline_fee.modifier2 = inline_data.col3(+);
SCHEDULE CPTCO MODIFIER2 COL1 COL2 COL3
SAPG1 46730 00
SAPG1 46735 00
SAPG1 46748 00
SAPG1 46760 00
SAPG1 46942 00
SAPG1 46945 00
SAPG1 47015 00
SAPG1 47125 00
SAPG1 47350 00
SAPG1 47505 00
SAPG1 47553 00interestingly explain plan for both the statements are exactly same,
SELECT STATEMENT ALL_ROWSCost: 138 Bytes: 1,078,274 Cardinality: 11,471
9 HASH JOIN RIGHT OUTER Cost: 138 Bytes: 1,078,274 Cardinality: 11,471
2 PARTITION RANGE EMPTY Cost: 2 Bytes: 150 Cardinality: 3
1 TABLE ACCESS FULL TABLE MPI_UDFFEE.UDFFEEANCFEEDATA Cost: 2 Bytes: 150 Cardinality: 3
8 VIEW MPI_UDFFEE. Cost: 135 Bytes: 504,724 Cardinality: 11,471
7 HASH UNIQUE Cost: 135 Bytes: 539,137 Cardinality: 11,471
6 HASH JOIN Cost: 134 Bytes: 539,137 Cardinality: 11,471
3 TABLE ACCESS FULL TABLE MPI_UDFFEE.UDFFEEACTIVECPTCODES Cost: 13 Bytes: 177,345 Cardinality: 25,335
5 PARTITION LIST SINGLE Cost: 120 Bytes: 600,600 Cardinality: 15,015 Partition #: 8
4 INDEX RANGE SCAN INDEX (UNIQUE) REPRICE.PK_MPIFEE Cost: 120 Bytes: 600,600 Cardinality: 15,015 Partition #: 9 Partitions accessed #11Is there anything wrong with the query? If not have anyone come across this issue or posted it as a bug or is there a patch?
Update:
when I set the parameter "_complex_view_merging"=false I am getting the right results even with case statement. But I don want to do some thing unsupported.
Are there any other viable solutions?
I appreciate the help.
Thanks,
G.
Edited by: Ganesh Srivatsav on Apr 10, 2012 12:37 PMHi Tubby,
Right, the query transformation is going wrong. Following is from trace,
SELECT "INLINE_FEE"."SCHEDULE" "SCHEDULE",
"INLINE_FEE"."CPTCODE" "CPTCODE",
"INLINE_FEE"."MODIFIER2" "MODIFIER2",
"INLINE_FEE"."FEE" "FEE",
"ARC"."SCHEDULE" "COL1",
"ARC"."PROCEDURECODE" "COL2",
CASE
WHEN "ARC".ROWID IS NOT NULL THEN NVL ("ARC"."MODIFIER", '00')
ELSE NULL
END
"COL3"
FROM (SELECT DISTINCT "MF"."SCHEDULE" "SCHEDULE",
"MF"."CPTCODE" "CPTCODE",
NVL ("MF"."MODIFIER", :B2) "MODIFIER2",
CASE
WHEN ("MF"."FEETYPE" = :B3
AND "MF"."MULTIPLIER" IS NOT NULL) THEN
:B4
WHEN ( ("MF"."FEETYPE" <> :B5
OR "MF"."FEETYPE" IS NULL)
AND "MF"."RBRVSVALUE" IS NOT NULL
AND "MF"."MULTIPLIER" IS NOT NULL) THEN
LPAD ( TRIM (TO_CHAR ( "MF"."RBRVSVALUE" * "MF"."MULTIPLIER" / :B6, :B7)), :B8)
ELSE
NULL
END
"FEE"
FROM "PROVIDER"."MPIFEE" "MF", "MPI_UDFFEE"."UDFFEEACTIVECPTCODES" "VLD"
WHERE "MF"."SCHEDULE" = 'SAPG1'
AND "MF"."CPTCODE" = "VLD"."CPTCODE"
AND NVL ("MF"."MODIFIER", 'NULL') = NVL ("VLD"."MODIFIER", 'NULL')) "INLINE_FEE",
"MPI_UDFFEE"."UDFFEEANCFEEDATA" "ARC"
WHERE "INLINE_FEE"."SCHEDULE" = "ARC"."SCHEDULE"(+)
AND "INLINE_FEE"."CPTCODE" = "ARC"."PROCEDURECODE"(+)
AND "INLINE_FEE"."MODIFIER2" = CASE
WHEN ("ARC".ROWID(+) IS NOT NULL) THEN NVL ("ARC"."MODIFIER"(+), '00')
ELSE NULL
END
AND "ARC"."MONTHOFEXTRACT"(+) = '201202'
AND "ARC"."SCHEDULE"(+) = 'SAPG1'
AND TRUNC (SYSDATE-10) >= "ARC"."RECORDEFFECTIVEDATE"(+)
AND TRUNC (SYSDATE-10) <= "ARC"."RECORDTERMINATIONDATE"(+)Does this refer to a specific bug?
Thanks,
G. -
Query with outer join not dispalying the correct results
Hi All,
I am having a table which has a column called status it can either be null or has the code which comes from the lookup b.When I use this query
select b.menaing from a
where a.status=b'lookup_code(+)
AND b.lookup_type='MTH_BUSINESS_FUNCTION'
AND b.LANGUAGE = USERENV('LANG')
then I don't get the rows from table a, where status is null
and if I use the condition:
select b.menaing from a
where ((a.status IS NULL) OR
(a.status=b.lookup_code
AND b.lookup_type='MTH_BUSINESS_FUNCTION'
AND b.LANGUAGE = USERENV('LANG') ))
then I get many extra rows.Can soemone please tell me hwo to achieve this(My query should display the menaing if status column is blank then it should dispaly blank otherwise after joining iwth the lookup table it should display meaning)Hi Prazy,
using nvl also didn't solve my problem.Actually my problem is I am having a table a in which I have a column called satus, status has the values like A or I .I have one lookup called MTH_BUYSINESS_FUNCTION in which for lookup_code A I have menaing as Active and for lookup_code I meaning is Inactive.Now in table a for sttaus I have two values one A and one null Now I want to write sql which displayes the meaning for column staus.Result should be Active and null .If I am uisng 1 query which I gave u I am not able to get the 2nd row in my output.If I use 2nd query then I get duplicate rows.
Thanks ,
Amrit -
Refresh using alias table not returning expected results
I am getting some unexpected results in SmartView and can't figure out the cause. I have an Essbase cube that has two alias tables: the "default" and one that I call "Short Descr". I can consistently bring back data using "none" and "default", but not "Short Descr". When I use "Short Descr" data will come back for some of the members, but not for others.
Here is an example of a query using "none" as the alias table:
Net Income
RD10078
Y-T-D(MAR)
PRJG939306 20,372.05
PRJLG921508 (26.42)
Project (1,179,752.36)
If I change the alias table to "Short Descr", I get the following results:
Net Income
ITA (RD10078)
Y-T-D(MAR)
PRJG939306 (PRJG939306) 20,372.05
PRJLG921508 (PRJLG921508) (26.42)
Project (1,179,752.36)
But then if I just clear the amounts, and do a refresh, I get the following:
Net Income
ITA (RD10078)
Y-T-D(MAR)
PRJG939306 (PRJG939306)
PRJLG921508 (PRJLG921508) (26.42)
Project (1,179,752.36)
And if I pivot Net Income, I get a message that "Any comments/ functions/ formulas on the sheet will be lost.", and the PRJG939306 member is lost.
ITA (RD10078)
Y-T-D(MAR)
Net Income PRJLG921508 (PRJLG921508) (26.42)
Net Income Project (1,179,752.36)
I can't figure out why it would start treating it as a comment. It looks to be a valid member name and I don't see anything strange if I look at the member properties in EAS. And what I really don't understand is why it would bring back the member name (with alias) and a data value when I change the alias table from "none" to "Short Descr", but not bring back a value when I just clear the amounts and do a Refresh. And why is it only doing it for some of the members and not all of them?
What could cause this type of behavior?lets see if I can say this clearly. Smartview will noit convert from one alias to another. Before switching alias tables, try changing back to no alias and do a retrieve, then switch to the new alias table and retrieve. I think the problem is Smartview is not interpeting what is on the one line so it leave it blank as an unknown member.
-
Hi,
I am trying to retrieve an Order I have manually created on an ECC6.0 system with Order ID 816149.
I can retrive the order fine using BAPI_ALM_ORDER_GET_DETAIL passig in the Order ID.
However, if I use BAPI_ALM_ORDERHEAD_GET_LIST with IT_RANGE set on the ENTER_DATE criteria, I get a bunch of Orders back from the search but not mine. However, the creation date of my Order is within the search range. I suspect the problem might be the System Status of my order (but I am just guessing) which is CRTD MANC NMAT NTUP. The User Status is CRTD though, so I am a bit puzzled as to why my order is not in the returned result set. For instance Order 816148 (created by someone else) is returned and it looks very similar to mine (except for the status).
If any help from SAP people, I am using an ICC Test system so maybe you can have a look for yourself. My system is CF5 / cpcf501 / 05 client 800.
Cheers.
JRPlease pass
Exporting
DISPLAY_PARAMETERS
CALL FUNCTION 'BAPI_ALM_ORDERHEAD_GET_LIST'
EXPORTING
DISPLAY_PARAMETERS =
" IMPORTING
" NAVIGATION_DATA =
TABLES
IT_RANGES =
ET_RESULT =
" ET_TEMPLATE =
RETURN =
Regards,
Lalit Mohan Gupta. -
REGEXP_LIKE not returning expected results
My first attempt at REGEXP_LIKE and I'm obviously missing something. I've tried several suggestions I found in the forum but cannot get the correct results. I need the following query to return only those rows containing only alphabetic characters (no numbers). What I get are rows containing letters and numbers.
Any help will be greatly appreciated!
Randy
SELECT order_number
FROM order_table
where REGEXP_LIKE(order_number,'[a-z A-Z]')check below the various options which you can use to search different elements
Character Class Syntax Meaning
[:alnum:] All alphanumeric characters
[:alpha:] All alphabetic characters
[:blank:] All blank space characters
[:cntrl:] All control characters (nonprinting)
[:digit:] All numeric digits
[:graph:] All [:punct:], [:upper:], [:lower:], and [:digit:] characters
[:lower:] All lowercase alphabetic characters
[:print:] All printable characters
[:punct:] All punctuation characters
[:space:] All space characters (nonprinting)
[:upper:] All uppercase alphabetic characters
[:xdigit:] All valid hexadecimal characters -
Search with multiple words not returning expected results
I am using RoboHelp 9 and was performing my search on published WebHelp.
In the Help there is a topic named "Port and Path Connection States" which references a status of "port not started".
When I search for "port not started" (with quotes) the topic is returned.
When I search for "port not started" (without quotes), I get this message: "The words you typed is not a valid expression.".
I thought this search would be treated as an OR search, and I would get results for all topics that contained the word "port" or "not" or "started", but instead the expression is not valid. Can anyone tell me why?Check your list of Stop words. It may include NOT.
See www.grainge.org for RoboHelp and Authoring tips
@petergrainge -
Ctxrule - match does not return expected result
v.11.1.07 - I have created a ctxrule index as detailed below. However, although a query should match on the given document, it does not return. Any ideas?
begin
ctx_ddl.create_preference('ot_lexer', 'basic_lexer');
ctx_ddl.set_attribute('ot_lexer', 'index_stems', 'ENGLOSH');
end;
begin
ctx_ddl.create_section_group('ot_sec_group', 'auto_section_group');
end;
create table ot_profile_test
(profile_id number,
query clob);
create index ot_profile_rule_ndx on ot_profile_test(query)
indextype is ctxsys.ctxrule parameters
('stoplist ctxsys.empty_stoplist
section group ot_sec_group
lexer ot_lexer');
insert into ot_profile_test values(1, '($apple and $pear) and (1 within food)');
commit;
exec ctxsys.ctx_adm.set_parameter('log_directory', '/yourdir');
exec ctx_output.start_log('ot');
exec ctx_output.add_event(ctx_output.event_index_print_rowid);
exec ctx_output.add_event(ctx_output.event_index_print_token);
exec ctx_ddl.sync_index('ot_profile_rule_ndx', '2040M', null, 1, null, ctx_ddl.lock_nowait_error);
exec ctx_output.end_log;Then, run a query:
declare
a clob := 'apple orange pears banana
<metadata>
<indicators>
<food>1</food>
</indicators>
</metadata>
vn_profile_id number;
begin
select profile_id into vn_profile_id
from ot_profile_test
where matches(query, a) > 0;
dbms_output.put_line(vn_profile_id);
end;
ERROR at line 1:
ORA-01403: no data found
ORA-06512: at line 8Shouldn't profile_id = 1 be returned?
Also, shouldn't the logfile have 2 rows written to $I?
WRITING TOKEN APPLE:((PEAR) = (PEARS)) * ((1) WITHIN FOOD),0
WRITING TOKEN APPLES:((PEAR) = (PEARS)) * ((1) WITHIN FOOD),0You need to use a basic_wordlist instead of a basic_lexer and ENGLISH instead of ENGLOSH in order to use stemming and your clob (variable a) must be valid html or xml in order to search within sections. Please see the simplified demonstration below.
SCOTT@orcl_11gR2> begin
2 ctx_ddl.create_preference ('ot_wordlist', 'basic_wordlist');
3 ctx_ddl.set_attribute ('ot_wordlist', 'stemmer', 'ENGLISH');
4 ctx_ddl.create_section_group ('ot_sec_group', 'auto_section_group');
5 end;
6 /
PL/SQL procedure successfully completed.
SCOTT@orcl_11gR2> create table ot_profile_test
2 (profile_id number,
3 query clob)
4 /
Table created.
SCOTT@orcl_11gR2> create index ot_profile_rule_ndx
2 on ot_profile_test (query)
3 indextype is ctxsys.ctxrule
4 parameters
5 ('stoplist ctxsys.empty_stoplist
6 wordlist ot_wordlist
7 section group ot_sec_group')
8 /
Index created.
SCOTT@orcl_11gR2> insert into ot_profile_test values
2 (1, '($apple and $pear) and (1 within food)')
3 /
1 row created.
SCOTT@orcl_11gR2> commit
2 /
Commit complete.
SCOTT@orcl_11gR2> exec ctx_ddl.sync_index ('ot_profile_rule_ndx')
PL/SQL procedure successfully completed.
SCOTT@orcl_11gR2> declare
2 a clob :=
3 '<table>
4 <fruits>apple orange pears banana</fruits>
5 <metadata>
6 <indicators>
7 <food>1</food>
8 </indicators>
9 </metadata>
10 </table>';
11 begin
12 for r in
13 (select profile_id
14 from ot_profile_test
15 where matches (query, a) > 0
16 order by profile_id)
17 loop
18 dbms_output.put_line (r.profile_id);
19 end loop;
20 end;
21 /
1
PL/SQL procedure successfully completed.
SCOTT@orcl_11gR2> -
Old outer join syntax produces different results from new syntax!
I have inherited a query that uses the old outer join syntax but that is yielding correct results. When I translate it to the new outer join syntax, I get the results I expect, but they are not correct! And I don't understand why the old syntax produces the results it produces. Bottom line: I want the results I'm getting from the old syntax, but I need it in the new syntax (I'm putting it into Reporting Services, and RS automatically converts old syntax to new).
Here's the query with the old outer join syntax that is working correctly:
Code Snippet
SELECT TE = COUNT(DISTINCT T1.ID),
UE = COUNT(DISTINCT T2.ID),
PE = CONVERT(MONEY, COUNT(DISTINCT T2.ID)) /
CONVERT(MONEY,COUNT(DISTINCT T1.ID))
FROM TABLE T1, TABLE T2
WHERE T1 *= T2
In this query, much to my surprise, TE <> UE and PE <> 1. However, TE, UE, and PE seem to be accurate!
Here's the query with the new outer join syntax that is working but not producing the results I need:
Code Snippet
SELECT TE = COUNT(DISTINCT T1.ID),
UE = COUNT(DISTINCT T2.ID),
PE = CONVERT(MONEY, COUNT(DISTINCT T2.ID)) /
CONVERT(MONEY,COUNT(DISTINCT T1.ID))
FROM TABLE T1 LEFT OUTER JOIN TABLE T2 ON T1.ID = T2.ID
Though not producing the results I need, it is producing what would be expected: TE = UE and PE = 1.
My questions:
1) Can someone who is familiar enough with the old syntax please help me understand why TE <> UE and PE <> 1 in the first query?
2) Can someone please tell me how to properly translate the first query to the new syntax so that it continues to produce the results in the first query?
Thank you very much.How can we reproduce the issue?
Code Snippet
USE [master]
GO
EXEC sp_dbcmptlevel Northwind, 80
GO
USE [Northwind]
GO
SELECT
TE
= COUNT(DISTINCT T1.OrderID),
UE = COUNT(DISTINCT T2.OrderID),
PE = CONVERT(MONEY, COUNT(DISTINCT T2.OrderID)) /
CONVERT(MONEY,COUNT(DISTINCT T1.OrderID))
FROM
dbo
.Orders T1, dbo.Orders T2
WHERE
T1
.OrderID *= T2.OrderID
SELECT
TE
= COUNT(DISTINCT T1.OrderID),
UE = COUNT(DISTINCT T2.OrderID),
PE = CONVERT(MONEY, COUNT(DISTINCT T2.OrderID)) /
CONVERT(MONEY,COUNT(DISTINCT T1.OrderID))
FROM
dbo
.Orders T1
LEFT OUTER JOIN
dbo.Orders T2
ON T1.OrderID = T2.OrderID
GO
EXEC sp_dbcmptlevel Northwind, 90
GO
Result:
TE
UE
PE
830
830
1.00
TE
UE
PE
830
830
1.00
As you can see, I am getting same results.
AMB -
Problem with XMLTABLE and LEFT OUTER JOIN
Hi all.
I have one problem with XMLTABLE and LEFT OUTER JOIN, in 11g it returns correct result but in 10g it doesn't, it is trated as INNER JOIN.
SELECT * FROM v$version;
Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 - Production
PL/SQL Release 11.2.0.1.0 - Production
"CORE 11.2.0.1.0 Production"
TNS for Linux: Version 11.2.0.1.0 - Production
NLSRTL Version 11.2.0.1.0 - Production
--test for 11g
CREATE TABLE XML_TEST(
ID NUMBER(2,0),
XML XMLTYPE
INSERT INTO XML_TEST
VALUES
1,
XMLTYPE
<msg>
<data>
<fields>
<id>g1</id>
<dat>data1</dat>
</fields>
</data>
</msg>
INSERT INTO XML_TEST
VALUES
2,
XMLTYPE
<msg>
<data>
<fields>
<id>g2</id>
<dat>data2</dat>
</fields>
</data>
</msg>
INSERT INTO XML_TEST
VALUES
3,
XMLTYPE
<msg>
<data>
<fields>
<id>g3</id>
<dat>data3</dat>
</fields>
<fields>
<id>g4</id>
<dat>data4</dat>
</fields>
<fields>
<dat>data5</dat>
</fields>
</data>
</msg>
SELECT
t.id,
x.dat,
y.seqno,
y.id_real
FROM
xml_test t,
XMLTABLE
'/msg/data/fields'
passing t.xml
columns
dat VARCHAR2(10) path 'dat',
id XMLTYPE path 'id'
)x LEFT OUTER JOIN
XMLTABLE
'id'
passing x.id
columns
seqno FOR ORDINALITY,
id_real VARCHAR2(30) PATH '.'
)y ON 1=1
ID DAT SEQNO ID_REAL
1 data1 1 g1
2 data2 1 g2
3 data3 1 g3
3 data4 1 g4
3 data5 Here's everything fine, now the problem:
Oracle Database 10g Enterprise Edition Release 10.2.0.1.0 - 64bi
PL/SQL Release 10.2.0.1.0 - Production
"CORE 10.2.0.1.0 Production"
TNS for HPUX: Version 10.2.0.1.0 - Production
NLSRTL Version 10.2.0.1.0 - Production
--exactly the same environment as 11g (tables and rows)
SELECT
t.id,
x.dat,
y.seqno,
y.id_real
FROM
xml_test t,
XMLTABLE
'/msg/data/fields'
passing t.xml
columns
dat VARCHAR2(10) path 'dat',
id XMLTYPE path 'id'
)x LEFT OUTER JOIN
XMLTABLE
'id'
passing x.id
columns
seqno FOR ORDINALITY,
id_real VARCHAR2(30) PATH '.'
)y ON 1=1
ID DAT SEQNO ID_REAL
1 data1 1 g1
2 data2 1 g2
3 data3 1 g3
3 data4 1 g4As you can see in 10g I don't have the last row, it seems that Oracle 10g doesn't recognize the LEFT OUTER JOIN.
Is this a bug?, Metalink says that sometimes we can have an ORA-0600 but in this case there is no error returned, just incorrect results.
Please help.
Regards.Hi A_Non.
Thanks a lot, I tried with this:
SELECT
t.id,
x.dat,
y.seqno,
y.id_real
FROM
xml_test t,
XMLTABLE
'/msg/data/fields'
passing t.xml
columns
dat VARCHAR2(10) path 'dat',
id XMLTYPE path 'id'
)x,
XMLTABLE
'id'
passing x.id
columns
seqno FOR ORDINALITY,
id_real VARCHAR2(30) PATH '.'
)(+) y ;And is giving me the complete output.
Thanks again.
Regards. -
Left Outer Join on same table clarification
HI,
I have a table that gets populated from 3<sup>rd</sup> party system. We don’t have control over it. So, the table has master record (master) and children. Master type is 78 and children’s type is 64. So, it looks like this. In the 3<sup>rd</sup>
party system, if Master transaction gets cancelled, it is recorded as type 178. If child is cancelled, then it is 164. Once the child is cancelled and created again using one process then newly created transaction will have 65 as type. Same thing with Master
cancelled transaction also. It will be 79. So, to summarize:
Master:
Brand New Transaction type = 78
Cancelled Transaction type = 178
Cancelled with creation transaction type = 79
Child:
Brand New Transaction type = 64
Cancelled Transaction type = 164
Cancelled with creation transaction type = 65
I don’t have to bother about master records. I need to focus on only children for my query.
ID
TxnID
Master
Type
TDate
Location
193075
211554
211543
64
20140805
ABC
193076
211555
211543
64
20140805
NBC
193077
211556
211543
64
20140805
ABC
193080
211559
211558
64
20140805
ABC
193081
211562
211561
64
20140805
ABC
193082
211565
211564
64
20140805
CBC
193083
211565
211564
164
20140805
CBC
193084
211566
211564
65
20140805
AZC
--drop
table #Transactions
CREATE
TABLE #Transactions
ID
int,
TxnID
int,
mstTicket
int,
Typecode
int,
Tdate
datetime,
Location
varchar(10)
select
* from
#Transactions
Insert
into #Transactions
(ID,
TxnID,
mstTicket,Typecode,Tdate,Location)
Select 193075, 211554,211543,64,'2014-08-05','ABC'
UNION ALL
Select 193076, 211555,211543, 64,
'2014-08-05',
'NBC' UNION ALL
Select 193077, 211556, 211543, 64,
'2014-08-05',
'ABC' UNION
ALL
Select 193080, 211559, 211558, 64,
'2014-08-05',
'ABC' UNION
ALL
Select 193081, 211562, 211561, 64,
'2014-08-05',
'ABC' UNION
ALL
Select 193082, 211565, 211564, 64,
'2014-08-05',
'CBC' UNION
ALL
Select 193083, 211565, 211564, 164,
'2014-08-05',
'CBC' UNION
ALL
Select 193084, 211566, 211564, 65,
'2014-08-05',
'AZC'
select
T.TxnID,
T.TypeCode,
T.Location,
TL.TxnID
From
#Transactions T
Left Outer
JOIN #Transactions
TL ON
TL.TxnID
= T.TxnID
and TL.TypeCode
= 164
select
T.TxnID,
T.TypeCode,
T.Location,
TL.TxnID
From
#Transactions T
Left Outer
JOIN #Transactions
TL ON
TL.TxnID
= T.TxnID
and TL.TypeCode
= 164
Where
T.typecode
in (64, 65)
I need a clarification regarding left Outer Join.
In the first left outer join query both 64 and 164 both have TL.TxnID populated. Why is that?. What I understand from
left outer join is that ‘Returns all the rows’ from left table and only matching data from right table.
Here, matching row from right table is 211565 and 164 record (id 193083). So, only it should have TxnID populated. But row 211565 and 64 has TL.txnID getting populated (ID 193082).
Why is it? Am I not understanding left out join properly?
Thanks,Thank you Shailesh. I understood what join does in left outer join. I was thinking
Left Outer JOIN #Transactions TL ON TL.TxnID = T.TxnID and TL.TypeCode = 164 is same as
Left Outer JOIN #Transactions TL ON TL.TxnID = T.TxnID and TL.TypeCode = T.TypeCode
and TL.TypeCode = 164
#Transactions
T
Left
Outer
JOIN
#Transactions
TL
ON
TL.TxnID
=
T.TxnID
and
TL.TypeCode
= 164
Where
T.typecode
in
(64,
65) -
Hi all,
I have a question regarding to Outer joins. This is my situation:
Sales (fact table)
id_company
id_product
yearmonth
units
dollars
Products (dimension table)
id_company
id_product
The 2 tables joins by id_company and id_product.
For a month, I need to get the units and dollars of all the products, if a product is not sold in that month the units and dollars will be zero.
The following query doesn't retrieve the correct results, because a product that is not sold in a month could be in another.
select
p.id_company, p.id_product, sum(s.units), sum(dollars)
from
products p, sales s
where
p.id_company = s.id_company(+)
and p.id_product = s.id_product(+)
and s.yearmonth = 200805
group by p.id_company, p.id_product
So this query gives the correct results:
select
p.id_company, p.id_product, sum(s.units), sum(dollars)
from
products p,
(select * from sales where yearmonth = 200805) s
where
p.id_company = s.id_company(+)
and p.id_product = s.id_product(+)
group by p.id_company, p.id_product
My question is, how can I implement the 2nd query in OBI? Is there an easier way to perform the select without sub-select?
Thanks in advance.You need to bring in the yearmonth from the product table itself for this to work.
e.g. if you product has 100 rows and you have 10 yearmonths, then your new product table will have 100*10 = 1000 rows. You can achieve this by snowflaking in physical layer (time --> product on 1=1 complex join) . keep the time-fact join in physical layer.
(If you don't want above, then create a view in db or physical layer with time full outer join product and joinng the resultant view to fact on yearmonth, id_companyand id_product )
Then bring the yearmonth column in product logical table in the same LTS with outer join specified.
In answers, use p.id_company, p.id_product, sum(s.units), sum(dollars)where p.yearmonth is filtered.
Maybe you are looking for
-
How-to add a custom Web Dynpro iView to the MSS Employee Profile
Hello everybody, i have created a small How-to guide of how to add a custom iView/Web Dynpro application to the standard MSS Employee Profile for ECC 6.0. The How-to guide can be found <a href="https://wiki.sdn.sap.com/wiki/display/profile/2007/04/15
-
AddADOCommand open an additional connection??
Post Author: StrongWare CA Forum: Data Connectivity and SQL Hi! All, I used the ADORecordSet to fetch data from tables, and pass it to ther report at runtime using AddADOCommand. I got the ActiveConnection and ActiveCommand from ADORecordSet and pass
-
Example in Data Modeler Tutorial does not work as described
Using Oracle Data Developer 4, I cannot get the example on https://docs.oracle.com/cd/E57998_01/doc.41/e57984/tut_data_modeling.htm#DMDUG36173 to work as described. The Foreign Key fields in the logical model are not generated. They are only generate
-
Status is red for request in monitor
Hai all I am getting status as red for the request in the manage screen of data source after scheduling info package( for the request) but I can see data in psa can any one help thanks chaithanya
-
Platform: Sun Solaris 8 Software: iMS 5.2 I would like to configure our server to use a specific relay for all out bound mail. Is there a simple way to do that?