Complex Query - Joins vs Multiple Views
I am trying to run a query that joins a main table representing people with 7 others that contain demographic and status information. Some of the other tables don't have records or have more than one record per person. For the instances of more than one phone number for a person, I need to filter out all but the active home number record. If the person doesn't have a phone number, I still need a record returned, just without a phone number listed. I have tried joining all the tables in a single query, but can't get every person to show up in the results. If the person doesn't have a phone number, or has a phone number that isn't both active and "Home" then they don't show up... I got around this by using multiple views to make sure everyone was pulled, but the multi level view runs slow as heck... Here are the two approaches. Any ideas?
Here are the views that work:
CREATE OR REPLACE VIEW pinnacle_address AS SELECT p.person_id, a.line1 | | ' ' | | a.line2 | | ' ' | | a.line3 AS StreetAddress, a.city, a.state, a.zip FROM cmn_people p, cmn_people_addresses a WHERE p.person_id=a.person_id(+) and a.Active_Address = 'Y' and a.Address_Type = 'Home';
CREATE OR REPLACE VIEW pinnacle_phone AS SELECT p.person_id, ph.phone_number, ph.phone_number_type FROM cmn_people p, cmn_phone_nos ph WHERE p.person_id=ph.person_id(+) and ph.active_phone_number = 'Y' and ph.primary_flag = 'Y';
CREATE OR REPLACE VIEW pinnacle_people AS SELECT p.person_identifier01, p.last_name, p.first_name, p.middle_name, p.date_of_birth, p.gender, a.StreetAddress, a.city, a.state, a.zip, ph.phone_number, ph.phone_number_type, p.email, p.ssn, p.ethnic, p.fulltime, p.person_id FROM cmn_people p, pinnacle_address a, pinnacle_phone ph WHERE p.person_id=a.person_id(+) and a.person_id = ph.person_id(+);
CREATE OR REPLACE VIEW pinnacle_student AS SELECT DISTINCT p.person_identifier01, p.last_name, p.first_name, p.middle_name, p.date_of_birth, p.gender, p.streetaddress, p.city, p.state, p.zip, p.phone_number, p.email, p.ssn, p.ethnic, p.fulltime, i.student_instance_id, e.comb_id FROM sss_student_enrollments e, sss_student_instance i, pinnacle_people p, cmn_statuses s WHERE e.person_id=i.person_id and i.person_id=p.person_id and i.status_id=s.status_id and s.status in('Active', 'Accepted');
Here's the single sql that doesn't:
CREATE OR REPLACE VIEW pinnacle_test AS SELECT DISTINCT cp.PERSON_IDENTIFIER01, cp.LAST_NAME, cp.FIRST_NAME, cp.MIDDLE_NAME, cp.DATE_OF_BIRTH, cp.GENDER, cpa.LINE1 | | ' ' | | cpa.LINE2 | | ' ' | | cpa.LINE3 AS StreetAddress, cpa.CITY, cpa.STATE, cpa.ZIP, cph.PHONE_NUMBER, cp.EMAIL, cp.SSN, cp.ETHNIC, cp.FULLTIME, si.STUDENT_INSTANCE_ID, se.COMB_ID FROM SSS_STUDENT_ENROLLMENTS se, SSS_STUDENT_INSTANCE si, CMN_STATUSES cs, CMN_PEOPLE cp, (SELECT * FROM CMN_PEOPLE_ADDRESSES WHERE Active_Address = 'Y' and Address_Type = 'Home') cpa, (SELECT * FROM CMN_PHONE_NOS WHERE active_phone_number = 'Y' and primary_flag = 'Y') cph WHERE se.PERSON_ID = si.PERSON_ID and si.STATUS_ID = cs.STATUS_ID and si.PERSON_ID = cp.PERSON_ID and cp.PERSON_ID(+) = cpa.PERSON_ID and cpa.PERSON_ID(+) = cph.PERSON_ID and cs.status in ('Active', 'Accepted');
Thanks in advance,
Erik Marin
[email protected]
CREATE OR REPLACE VIEW pinnacle_student
AS
SELECT DISTINCT p.person_identifier01,
p.last_name,
p.first_name,
p.middle_name,
p.date_of_birth,
p.gender,
a.line1 | | ' ' | | a.line2 | | ' ' | | a.line3 AS StreetAddress,
a.city,
a.state,
a.zip,
ph.phone_number,
p.email,
p.ssn,
p.ethnic,
p.fulltime,
i.student_instance_id,
e.comb_id
FROM sss_student_enrollments e,
sss_student_instance i,
cmn_people p,
cmn_people_addresses a,
cmn_phone_nos ph,
cmn_statuses s
WHERE e.person_id = i.person_id
and i.person_id = p.person_id
and i.status_id = s.status_id
and p.person_id = a.person_id(+)
and p.person_id = ph.person_id(+)
and s.status in ('Active', 'Accepted')
and a.Active_Address(+) = 'Y'
and a.Address_Type(+) = 'Home'
and ph.active_phone_number(+) = 'Y'
and ph.primary_flag(+) = 'Y';
null
Similar Messages
-
1. How to create an explain plan with rowsource statistics for a complex query that include multiple table joins ?
When multiple tables are involved , and the actual number of rows returned is more than what the explain plan tells. How can I find out what change is needed in the stat plan ?
2. Does rowsource statistics gives some kind of understanding of Extended stats ?You can get Row Source Statistics only *after* the SQL has been executed. An Explain Plan midway cannot give you row source statistics.
To get row source statistics either set STATISTICS_LEVEL='ALL' in the session that executes theSQL OR use the Hint "gather_plan_statistics" in the SQL being executed.
Then use dbms_xplan.display_cursor
Hemant K Chitale -
Complex query/join question
Not sure if this goes here, but I thought I'd try anyway.
I'm using Oracle 8i for a legacy app and the RDBMS won't be updated anytime soon. I'm trying to write a fairly complex sum and join query. I have two different tables with hours worked type information. I need to be able to sum the hours for a work day on each table and put, in a web table like a GridView, all rows, even if there isn't a match in the opposite table. So, for example
Table 1
ID SHOP WORKDATE SHOPHOURS
1 AM1 1/1/2008 4
1 AM1 1/1/2008 4
2 AM1 1/1/2008 8
3 AM1 1/1/2008 8
Table 2
ID WORKDATE PAYHOURS
2 1/1/2008 7
3 1/1/2008 8
4 1/1/2008 9
What I need to see is
ID SHOP WORKDATE SHOPHOURS PAYHOURS
1 AM1 1/1/2008 8 0
2 AM1 1/1/2008 8 7
3 AM1 1/1/2008 8 8
4 1/1/2008 8 9
Since i'm on 8i, I can't use a FULL OUTER Join, so i'm kind of stumped. Any suggestions would be greatly appreciated.You might want to post this to question to [SQL Forum|http://forums.oracle.com/forums/forum.jspa?forumID=75] instead for better result, but i can give you a solution. This is definitely not the best solution, but it works.
select nvl(table1.id,table2.id) id, shop,
nvl(table1.workdate,table2.workdate) workdate,
sum(nvl(shophours,0)) shophours, sum(nvl(payhours,0)) payhours
from table1, table2 where table1.id(+) = table2.id
group by nvl(table1.id,table2.id), shop,
nvl(table1.workdate,table2.workdate)
union
select nvl(table1.id,table2.id) id, shop,
nvl(table1.workdate,table2.workdate) workdate,
sum(nvl(shophours,0)) shophours, sum(nvl(payhours,0)) payhours
from table1, table2 where table1.id = table2.id(+)
group by nvl(table1.id,table2.id), shop,
nvl(table1.workdate,table2.workdate) Cheers,
[Nur Hidayat|http://nur-hidayat.net] -
Make several views of a single query to a multiple views of workbook
Hi,
we have a report which would display info of developer activities over a period of time.
now the requiremnet is to make a workbook of several views of the same query!
each view should display number of requests handled by developer per project over a time, per customer over a time, per region over a time etc and so on--
now the original query has several selection options which are completly different from what i said above! ( like priority of the request ,caller , status of the request etc--- )
in this case such as this, what i need to do ?
shall i change the definition of the query for each view and save it in workbook?
or is there any different way of doing this?
also shall i directly make the changes in production itself or make the chnages in dev and transport it to production?
Many thanks in advance
RaviIf you can fulfill your requirement with views, go ahead.
We do not transport views (except in rare occasions), so I'd do it straight in prod. -
How to store data from a complex query and only fresh hourly or daily?
We have a report which runs quite slow (1-2 minutes) because the query is quite complicate, so we would like to run this query daily only and store in a table so for those procedures that need to use this complex query as a subquery, can just join to this table directly to get results.
However, I am not sure what kind of object I should use to store data for this complex query. Is data in global temp table only persist within transaction? I need something that can persist the data and be access by procedures.
Any suggestions are welcome,
CheersThank you for your reply. I looked at the materialized view earlier on, but have some difficulties to use it. So I have some questions here:
1.The complex query is not a sum or aggregate functions, it just need to get data from different tables based on different conditions, in this case is it still appropriate to use meterialized view?
2.If it is, I created one, but how to use it in my procedure? From the articles I read, it seems I can't just query from this view directly. So do I need to keep the complex query in my procedure and how the procedure will use the meterialized view instead?
3. I also put the complex query in a normal view, then create a materialized view for this normal view (I expect the data from the complex query will be cache here), then in the procedure I just select * from my_NormalView, but it takes the same time to run even when I set the QUERY_REWRITE_ENABLED to true in the alter session. So I am not sure what else I need to do to make sure the procedure use the materialized view instead of the normal view. Can I query from the Materialized View directly?
Below in the code I copied from one of the article to create the materialized view based on my normal view:
CREATE MATERIALIZED VIEW HK3ControlDB.MW_RIRating
PCTFREE 5 PCTUSED 60
TABLESPACE "USERS"
STORAGE (INITIAL 50K NEXT 50K)
USING INDEX STORAGE (INITIAL 25K NEXT 25K)
REFRESH START WITH ROUND(SYSDATE + 1) + 11/24
NEXT NEXT_DAY(TRUNC(SYSDATE), 'MONDAY') + 15/24
enable query rewrite
AS SELECT * FROM HK3ControlDB.VW_RIRating;
Cheers -
Possible to execute complex query in ExecuteSQL method in DI Server??
Hi All,
Is it Possible to execute complex query in ExecuteSQL Method in DI Server?
Regards,
G.SureshHello Guru,
It is possible. Mostly if it can be done in DI, it will also can be done in DI Server except metadata operaiton, transation management etc.
I try the following complex query (join, nexted):
The SOAP Request
<?xml version="1.0" encoding="UTF-16"?>
<env:Envelope xmlns:env="http://schemas.xmlsoap.org/soap/envelope/">
<env:Header>
<SessionID>4FFCFAA3-5493-456A-BC89-410B35AF096C</SessionID>
</env:Header>
<env:Body>
<dis:ExecuteSQL xmlns:dis="http://www.sap.com/SBO/DIS">
<DoQuery>SELECT OCRD.CardCode, OCRD.CardName, OCPR.Name FROM OCRD JOIN OCPR ON OCRD.CardCode = OCPR.CardCode WHERE OCRD.CardCode IN
(SELECT DISTINCT ORDN.CardCode FROM ORDN)</DoQuery>
</dis:ExecuteSQL>
</env:Body>
</env:Envelope>
The SOAP Response:
<?xml version="1.0"?><env:Envelope xmlns:env="http://www.w3.org/2003/05/soap-envelope">
<env:Body><ExecuteSQLResponse xmlns="http://www.sap.com/SBO/DIS">
<BOM><BO><AdmInfo><Object>oRecordset</Object></AdmInfo><OCRD><row><CardCode>C002</CardCode><CardName>SAP</CardName>
<Name>2</Name></row><row><CardCode>C002</CardCode><CardName>SAP</CardName><Name>l</Name></row><row><CardCode>C002</CardCode>
<CardName>SAP</CardName><Name>Z</Name></row></OCRD></BO></BOM></ExecuteSQLResponse></env:Body></env:Envelope>
I think you can easily parse the result...
Kind Regards
-Yatseas -
Need complex query with joins and AGGREGATE functions.
Hello Everyone ;
Good Morning to all ;
I have 3 tables with 2 lakhs record. I need to check query performance.. How CBO rewrites my query in materialized view ?
I want to make complex join with AGGREGATE FUNCTION.
my table details
SQL> select from tab;*
TNAME TABTYPE CLUSTERID
DEPT TABLE
PAYROLL TABLE
EMP TABLE
SQL> desc emp
Name
EID
ENAME
EDOB
EGENDER
EQUAL
EGRADUATION
EDESIGNATION
ELEVEL
EDOMAIN_ID
EMOB_NO
SQL> desc dept
Name
EID
DNAME
DMANAGER
DCONTACT_NO
DPROJ_NAME
SQL> desc payroll
Name
EID
PF_NO
SAL_ACC_NO
SALARY
BONUS
I want to make complex query with joins and AGGREGATE functions.
Dept names are : IT , ITES , Accounts , Mgmt , Hr
GRADUATIONS are : Engineering , Arts , Accounts , business_applications
I want to select records who are working in IT and ITES and graduation should be "Engineering"
salary > 20000 and < = 22800 and bonus > 1000 and <= 1999 with count for males and females Separately ;
Please help me to make a such complex query with joins ..
Thanks in advance ..
Edited by: 969352 on May 25, 2013 11:34 AM969352 wrote:
why do you avoid providing requested & NEEDED details?I do NOT understand what do you expect ?
My Goal is :
1. When executing my own query i need to check expalin plan.please proceed to do so
http://docs.oracle.com/cd/E11882_01/server.112/e26088/statements_9010.htm#SQLRF01601
2. IF i enable query rewrite option .. i want to check explain plan ( how optimizer rewrites my query ) ? please proceed to do so
http://docs.oracle.com/cd/E11882_01/server.112/e16638/ex_plan.htm#PFGRF009
3. My only aim is QUERY PERFORMANCE with QUERY REWRITE clause in materialized view.It is an admirable goal.
Best Wishes on your quest for performance improvements. -
Hi,
I want to query on multiple views, how do I do that?
I have a view (foto_main) with primary key foto_id and 6 other attributes.
I have 2 other views (foto_link_feat and foto_link_pict) that are linked with foto_main.
Foto_link_feat has 2 attributes (foto_id and feat_id) and foto_link_pict has also 2 attributes (foto_id and pict_id).
I want to create a query on all the attributes in foto_main and on feat_id and foto_id.
You can create a new view with al the attributes you want to search but that is not a good solution.
Does anyone know how to solve this problem??I believe that there was a suggestion/feature request which involves defining ViewObjects which do not work on database tables/views, but on other ViewObjects. I guess this is what you would want.
However, that still would mean defining yet another ViewObject. So I guess, that wouldn't be much different to creating a new ViewObject in your current situation.
Or.. in case I misunderstood you, you can alter an existing ViewObject in a way that it queries multiple tables/views. In order to do that, just set the query to expert mode and enter a simple join or whatever.
HTH -
Working with multiple results of a complex query
Hi all!
As I "advance" in learning PL/SQL with oracle, I now get stuck in handling multiple results of a complex query. As far as I know, I cannot use a cursor here, as there is no table where the cursor could point to.
Here is the concept of what I want to do (pseudocode):
foreach result in SELECT * FROM table_1, table_n WHERE key_1 = foreign_key_in_n;
-- do someting with the resultHere is my attemt, that freezes the browser gui and throws an internal database error:
declare
type t_stock is record(
baggage_id baggage.baggage_id%type,
section_id sections.section_id%type,
shelf_id shelves.shelf_id%type
v_stock t_stock;
rcnt number(2);
begin
dbms_output.put_line(TO_CHAR(rcnt));
loop
SELECT COUNT(*) INTO rcnt FROM (
SELECT baggage.baggage_id, sections.section_id, shelves.shelf_id
FROM baggage, sections, shelves
WHERE baggage.baggage_id = sections.contained_baggage_id
AND shelves.is_connex_to_section_id = sections.section_id);
IF rcnt <= 0 THEN
exit;
END IF;
SELECT baggage.baggage_id, sections.section_id, shelves.shelf_id INTO v_stock
FROM baggage, sections, shelves
WHERE baggage.baggage_id = sections.contained_baggage_id
AND shelves.is_connex_to_section_id = sections.section_id
AND ROWNUM < 2;
UPDATE sections SET contained_baggage_id = NULL WHERE section_id = v_stock.baggage_id;
commit; -- do I need that?
end loop;
END;
/So, is there a way to traverse a list of results from a complex query? Maybe without creating a temporary table (or is that the better way?).
regards, Alex
I reformatted the code
pktmOk, here are the details:
The tables are used to model kind of a transport system. There are terminals connected with sections that may contain 1 piece of baggage. The baggage is moved by a procedure through a transport system. After each of these "moving steps", I check if the baggage is in front of the shelf it should be in.
[To be honest, the give statement doesn't contain the info, in which shelf the baggage wil bee inserted. That was spared out because of the lack of a working piece of code :)]
But: if we consider the fact, that a baggage is in front of such a shelf in the way, that it should be put in this shelf, then all this makes some sense.
- move baggae through a transport system
- see if you can put baggage into a shelf
In order to "put baggage in a shelf", I need to remove it from the transport section. As the transport system is not normalized, I need to update the section where the baggage was in.
Uhm... yes it's a task that doesn't make too much sense. It seems to be some kind of general spirit in university homework :)
But: the FOR r IN (Statement) lloks good. I'll use that.
And, the ROWNUM < 2 is used to limit the size of the result to 1, there is no need to have a specific ordering. It's just because - afaik - oracle doesn't have a limit clause. I would appreciate your help if you know a better way to do limit resultsets.
best regards, Alex -
Complex Query which needs tuning
Hello :
I have a complex query that needs to be tuned. I have little experience in tuning the sql and hence taking the help of your guys.
The Query is as given below:
Database version 11g
SELECT DISTINCT P.RESPONSIBILITY, P.PRODUCT_MAJOR, P.PRODUCT_MINOR,
P.PRODUCT_SERIES, P.PRODUCT_CATEGORY AS Category1, SO.REGION_CODE,
SO.STORE_CODE, S.Store_Name, SOL.PRODUCT_CODE, PRI.REPLENISHMENT_TYPE,
PRI.SUPPLIER_CODE,
SOL.SOLD_WITH_NIC, SOL.SUGGESTED_PRICE,
PRI.INVOICE_COST, SOL.FIFO_COST,
SO.ORDER_TYPE_CODE, SOL.DOCUMENT_NUM,
SOS.SLSP_CD, '' AS FNAME, '' AS LNAME,
SOL.PRICE_EXCEPTION_CODE, SOL.AS_IS,
SOL.STATUS_DATE,
Sum(SOL.QUANTITY) AS SumOfQUANTITY,
Sum(SOL.EXTENDED_PRICE) AS SumOfEXTENDED_PRICE
--Format([SALES_ORDER].[STATUS_DATE],"mmm-yy") AS [Month]
FROM PRODUCT P,
PRODUCT_MAJORS PM,
SALES_ORDER_LINE SOL,
STORE S,
SALES_ORDER SO,
SALES_ORDER_SPLITS SOS,
PRODUCT_REGIONAL_INFO PRI,
REGION_MAP R
WHERE P.product_major = PM.PRODUCT_MAJOR
and SOL.PRODUCT_CODE = P.PRODUCT_CODE
and SO.STORE_CODE = S.STORE_CODE
AND SO.REGION_CODE = S.REGION_CODE
AND SOL.REGION_CODE = SO.REGION_CODE
AND SOL.DOCUMENT_NUM = SO.DOCUMENT_NUM
AND SOL.DELIVERY_SEQUENCE_NUM = SO.DELIVERY_SEQUENCE_NUM
AND SOL.STATUS_CODE = SO.STATUS_CODE
AND SOL.STATUS_DATE = SO.STATUS_DATE
AND SO.REGION_CODE = SOS.REGION_CODE
AND SO.DOCUMENT_NUM = SOS.DOCUMENT_NUM
AND SOL.PRODUCT_CODE = PRI.PRODUCT_CODE
AND PRI.REGION_CODE = R.CORP_REGION_CODE
AND SO.REGION_CODE = R.DS_REGION_CODE
AND P.PRODUCT_MAJOR In ('STEREO','TELEVISION','VIDEO')
AND SOL.STATUS_CODE = 'D'
AND SOL.STATUS_DATE BETWEEN '01-JUN-09' AND '30-JUN-09'
AND SO.STORE_CODE NOT IN
('10','20','30','40','70','91','95','93','94','96','97','98','99',
'9V','9W','9X','9Y','9Z','8Z',
'8Y','92','CZ','FR','FS','FT','FZ','FY','FX','FW','FV','GZ','GY','GU','GW','GV','GX')
GROUP BY
P.RESPONSIBILITY, P.PRODUCT_MAJOR, P.PRODUCT_MINOR, P.PRODUCT_SERIES, P.PRODUCT_CATEGORY,
SO.REGION_CODE, SO.STORE_CODE, /*S.Short Name, */
S.Store_Name, SOL.PRODUCT_CODE,
PRI.REPLENISHMENT_TYPE, PRI.SUPPLIER_CODE,
SOL.SOLD_WITH_NIC, SOL.SUGGESTED_PRICE, PRI.INVOICE_COST,
SOL.FIFO_COST, SO.ORDER_TYPE_CODE, SOL.DOCUMENT_NUM,
SOS.SLSP_CD, '', '', SOL.PRICE_EXCEPTION_CODE,
SOL.AS_IS, SOL.STATUS_DATE
Explain Plan:
SELECT STATEMENT, GOAL = ALL_ROWS Cost=583 Cardinality=1 Bytes=253
HASH GROUP BY Cost=583 Cardinality=1 Bytes=253
FILTER
NESTED LOOPS Cost=583 Cardinality=1 Bytes=253
HASH JOIN OUTER Cost=582 Cardinality=1 Bytes=234
NESTED LOOPS
NESTED LOOPS Cost=571 Cardinality=1 Bytes=229
NESTED LOOPS Cost=571 Cardinality=1 Bytes=207
NESTED LOOPS Cost=569 Cardinality=2 Bytes=368
NESTED LOOPS Cost=568 Cardinality=2 Bytes=360
NESTED LOOPS Cost=556 Cardinality=3 Bytes=435
NESTED LOOPS Cost=178 Cardinality=4 Bytes=336
NESTED LOOPS Cost=7 Cardinality=1 Bytes=49
HASH JOIN Cost=7 Cardinality=1 Bytes=39
VIEW Object owner=CORP Object name=index$_join$_015 Cost=2 Cardinality=3 Bytes=57
HASH JOIN
INLIST ITERATOR
INDEX UNIQUE SCAN Object owner=CORP Object name=PRODMJR_PK Cost=0 Cardinality=3 Bytes=57
INDEX FAST FULL SCAN Object owner=CORP Object name=PRDMJR_PR_FK_I Cost=1 Cardinality=3 Bytes=57
VIEW Object owner=CORP Object name=index$_join$_016 Cost=4 Cardinality=37 Bytes=740
HASH JOIN
INLIST ITERATOR
INDEX RANGE SCAN Object owner=CORP Object name=PRDMNR1 Cost=3 Cardinality=37 Bytes=740
INDEX FAST FULL SCAN Object owner=CORP Object name=PRDMNR_PK Cost=4 Cardinality=37 Bytes=740
INDEX UNIQUE SCAN Object owner=CORP Object name=PRODMJR_PK Cost=0 Cardinality=1 Bytes=10
MAT_VIEW ACCESS BY INDEX ROWID Object owner=CORP Object name=PRODUCTS Cost=171 Cardinality=480 Bytes=16800
INDEX RANGE SCAN Object owner=CORP Object name=PRD2 Cost=3 Cardinality=681
TABLE ACCESS BY INDEX ROWID Object owner=DS Object name=SALES_ORDER_LINE Cost=556 Cardinality=1 Bytes=145
BITMAP CONVERSION TO ROWIDS
BITMAP INDEX SINGLE VALUE Object owner=DS Object name=SOL2
TABLE ACCESS BY INDEX ROWID Object owner=DS Object name=SALES_ORDER Cost=4 Cardinality=1 Bytes=35
INDEX RANGE SCAN Object owner=DS Object name=SO1 Cost=3 Cardinality=1
TABLE ACCESS BY INDEX ROWID Object owner=DS Object name=REGION_MAP Cost=1 Cardinality=1 Bytes=4
INDEX RANGE SCAN Object owner=DS Object name=REGCD Cost=0 Cardinality=1
MAT_VIEW ACCESS BY INDEX ROWID Object owner=CORP Object name=PRODUCT_REGIONAL_INFO Cost=2 Cardinality=1 Bytes=23
INDEX UNIQUE SCAN Object owner=CORP Object name=PRDRI_PK Cost=1 Cardinality=1
INDEX UNIQUE SCAN Object owner=CORP Object name=BI_STORE_INFO_PK Cost=0 Cardinality=1
MAT_VIEW ACCESS BY INDEX ROWID Object owner=CORP Object name=BI_STORE_INFO Cost=1 Cardinality=1 Bytes=22
VIEW Object owner=DS cost=11 Cardinality=342 Bytes=1710
HASH JOIN Cost=11 Cardinality=342 Bytes=7866
MAT_VIEW ACCESS FULL Object owner=CORP Object name=STORE_CORP Cost=5 Cardinality=429 Bytes=3003
NESTED LOOPS Cost=5 Cardinality=478 Bytes=7648
MAT_VIEW ACCESS FULL Object owner=CORP Object name=STORE_GROUP Cost=5 Cardinality=478 Bytes=5258
INDEX UNIQUE SCAN Object owner=CORP Object name=STORE_REGIONAL_INFO_PK Cost=0 Cardinality=1 Bytes=5
INDEX RANGE SCAN Object owner=DS Object name=SOS_PK Cost=2 Cardinality=1 Bytes=19
Regards,
BMPFirst thing that i notice in this query is you are Using Distinct as well as Group by.
Your group by will always give you distinct results ,then again why do you need the Distinct?
For example
WITH t AS
(SELECT 'clm1' col1, 'contract1' col2,10 value
FROM DUAL
UNION ALL
SELECT 'clm1' , 'contract1' ,10 value
FROM DUAL
UNION ALL
SELECT 'clm1', 'contract2',10
FROM DUAL
UNION ALL
SELECT 'clm2', 'contract1',10
FROM DUAL
UNION ALL
SELECT 'clm3', 'contract1',10
FROM DUAL
UNION ALL
SELECT 'clm4', 'contract2',10
FROM DUAL)
SELECT distinct col1,col2,sum(value) from t
group by col1,col2Is always same as
WITH t AS
(SELECT 'clm1' col1, 'contract1' col2,10 value
FROM DUAL
UNION ALL
SELECT 'clm1' , 'contract1' ,10 value
FROM DUAL
UNION ALL
SELECT 'clm1', 'contract2',10
FROM DUAL
UNION ALL
SELECT 'clm2', 'contract1',10
FROM DUAL
UNION ALL
SELECT 'clm3', 'contract1',10
FROM DUAL
UNION ALL
SELECT 'clm4', 'contract2',10
FROM DUAL)
SELECT col1,col2,sum(value) from t
group by col1,col2And also
AND SOL.STATUS_DATE BETWEEN '01-JUN-09' AND '30-JUN-09'It would be best to use a to_date when hard coding your dates.
Edited by: user5495111 on Aug 6, 2009 1:32 PM -
Is it impossible at all to create a materialized view using a complex query (i.e. joins + union)?
Thanks in advance
FabioOkay, childishness aside, it is possible to create materialized views using joins, unions and sub-queries. However, these sorts of complex materialized views have limited refresh options.
Cheers, APC -
I'm using a left join in a view object but I get ORA-00942 Table or View does not exist.
When I run the SQL Query in SQLDeveloper, it works fine. But when I use it in my ViewObject, I get the error. The Query looks like this (It is more difficult than this, but this is the part that I get the error in)
SELECT LocationHistory.LOCATION_HISTORY_ID,
LocationHistory.CONFIG_ITEM_ID,
LocationHistory.EMPLOYEE_ID,
LocationHistory.STD_LOCATION_ID,
LocationHistory.FROM_DATE,
LocationHistory.DESCRIPTION,
StandardLocation.STANDARD_LOCATION_ID AS STANDARD_LOCATION_ID1,
StandardLocation.NAME,
StandardLocation.DESCRIPTION AS DESCRIPTION1
FROM HSR_LOC_HISTORY LocationHistory
LEFT JOIN HSR_STD_LOCATION StandardLocation
ON LocationHistory.STD_LOCATION_ID = StandardLocation.STANDARD_LOCATION_ID
WHERE STD_LOCATION_ID = 20
Does anyone know what the problem could be? Thanks for the help in advanceHi,
It looks like the VO validation thinks LEFT is a table (table or view does not exist)
try
FROM HSR_LOC_HISTORY LocationHistory,
HSR_STD_LOCATION StandardLocation
WHERE LocationHistory.STD_LOCATION_ID = StandardLocation.STANDARD_LOCATION_ID(+)
AND STD_LOCATION_ID = 20much easier to read and understand particularly if you have multiple outer joins.
Brenden -
One big report, multiple views
is it ok (as a good practice) in OBIEE Answers, when dealing with a complex BM, to build a big report with lots of dimensions and measures involved , and then create many views for that report, each using a limited number of dimensions / measures available in the report ?
I have experienced a few cases when a complex report with multiple views displays incorrect results , while if creating simpler reports for each of the views the results are correct.
and that seems to me because, on each of the small simple reports a correct sql query is generated, while on the big report OBIEE tries to achieve the requirements using just one or two much more complex (and with lower granularity) queries ( the result of which are are used by presentation layer to further compute -sometimes incorrectly- the values for each of the report views).
sometimes even when I exclude a dimension column from all views (while is still present in the report) the sql query generated still use it.
is this a normal behavior ? have anyone experienced similar issues ? I'm having some hard time explaining these to the users that create reports.
thank you.Couldn't find anything in the documentation to support that , though. How to explain this to the report writers ? many times it is more convenient to them to just create a big report with lots of views...instead of many reports.
-
How to create a Service based on complex query
Hi,
I'm using JDev 11.1.2.2.0 for developing fusion based application based on EJB3.0 and JPA. I search on net and got a link for sample application as shown below:
http://www.oracle.com/webfolder/technetwork/tutorials/obe/jdev/obe11jdev/ps1/ejb/ejb.html#t2s1
But above application is based on "Entities based on Tables" but my requirement to build a service based on query which contains multiple tables which means I want to create a generic one...
please let me know what I need to change or please provide any link for docs.Hi Desmukh,
I want to create a wsdl for complex queries based on ADF fusion applicaiton using EJB3.0 and JPA...!
the link which you provided 'entity with tables' which is restricting for my requirement but I want similar implementation for complex queries :( -
Passing one parameter to multiple views
Is this possible? I would like to pass one parameter, a date field, to multiple views. I cannot use it in the record selection, because my views do a mathematical computation which returns a single value, but I only want to select the data for a single day.
The problem is that there are several views and I do not want to have to enter the date parameter a dozen times.Try to use add command and write the query like this
select * from view where datefield={?date}
also create another add command for the other view
select * from view2 where datefield2={?date}
for all the queries create the same parameter with the name {?date}
Regards,
Raghavendra
Maybe you are looking for
-
Verizon Upgrade has messed up Slacker Radio for Blackberry Tour 9630
About a week or two ago I got an upgrade Icon on my phone for I think a 5. something version. I upgraded my phone and it took quite a long time. Since the upgrade I had to add back some of my apps. I didn't have to add Slacker Radio back, but now
-
Why did my Acrobat 9 stop being able to create PDFs from files?
Howdy folks- my first foray here. I have a copy of acrobat pro 9 which I installed and used uneventfully for the last few years (windows 7). I hadn't used it in the last few months. Yesterday when I tried to create a new PDF from file (word doc, per
-
Hello SAP Guru's, Need information about Share Master Data(SMD) tool. 1) What is SMD tool? 2) What for SMD toll used? 3) How to use SMD tool,
-
Revision: 4321 Author: [email protected] Date: 2008-12-15 18:22:07 -0800 (Mon, 15 Dec 2008) Log Message: Fixing name of strokes directory in the directory skeleton for fxgutils. QE: No Doc: No Added Paths: flex/sdk/trunk/modules/fxgutils/src/java/fla
-
Some reports need to be recompiled to work!
Hi All, I've created a lot of reports some of it is still working till this moment without recompiling and no problems, Some of it is working successfully for some times but the form gives me an error when calling it: REP-1247: Report contains uncomp