Tricky query with multiple hierarchial sub queries
Here's a pussle that I cannot solve. Who can help me?
Given table F (records form a binary tree with levels 0, 1, and
2):
Id IdParent
F1 null
F2 F1
F3 F2
F4 F2
F5 F1
F6 F5
F7 F5
and given table D (records form a similar binary tree with
levels 0, 1, and 2):
Id IdParent
D1 null
D2 D1
D3 D2
D4 D2
D5 D1
D6 D5
D7 D5
and given table P (cross referencing tables F and D):
IdF IdD
F2 D6
F3 D2
F5 D7
and given table S (which holds the seed to the query):
IdF
F3
and given table I (just any collection of records that reference
table D which we want to select records from):
Id IdD
I1 D1
I2 D2
I3 D3
I4 D4
I5 D5
I6 D6
I7 D7
I8 D1
I9 D5
all together being related like in figure 1:
S.IdF =>> F.Id
F.Id <- P.IdF
P.IdD -> D.Id
D.Id <<= I.IdD
where =>> denotes 'is or is a descenden of'
and -> denotes 'is'
I want to build a query that lets me select all records from
table I, which reference table D, such that the referenced
records in table D are hierarchial descendents of any record
that is referenced by records in table P, for which they
reference records in table F, which are ancestors to records
referenced by records in table S.
If it wasn't for the hierarchial approach on both sides of the
cross referencing table, matters would have been easy. Then the
releational map would have been like in figure 2:
S.IdF <- P.IdF
P.IdD -> I.IdD
and the query would have been:
SELECT I.Id
FROM I, P, S
WHERE I.IdD = P.IdD
AND P.IdF = S.IdF
So in what I am looking for, you may say that the '='-signs in
this select statement should denote 'is or is a descenden of'
going towards the side of table P.
Given the tables listed above and given the query I am seeking,
I expect to retrieve the following result set:
I.Id
I2
I3
I4
I6
Tricky, eh? I belive the figures are the best angles to
understand this problem.
You do this with subqueries and hierarchical queries...
First the hierarchal subquery on F...
SQL> SELECT f.id
2 FROM f
3 CONNECT BY PRIOR f.idp = f.id
4 START WITH f.id IN ( SELECT idf FROM s )
5 ;
ID
F3
F2
F1
Then join with the cross reference table...
SQL> SELECT p.idd
2 FROM p
3 , ( SELECT f.id
4 FROM f
5 START WITH f.id IN ( SELECT idf FROM s )
6 CONNECT BY PRIOR f.idp = f.id
7 ) s
8 WHERE s.id = p.idf
9 ;
ID
D6
D2
Use this as a subquery in a hierarchial query for the
descendents in D...
SQL> SELECT d.id
2 FROM d
3 START WITH d.idd IN ( SELECT p.idd
4 FROM p
5 , ( SELECT f.id
6 FROM f
7 START WITH f.id IN ( SELECT
idf FROM s )
8 CONNECT BY PRIOR f.idp = f.id
9 ) s
10 WHERE s.id = p.idf
11 )
12 CONNECT BY PRIOR d.id = d.idp
13 ;
ID
D2
D3
D4
D6
Then use that as a subquery to return the I result set...
SQL> SELECT i.id
2 FROM i
3 WHERE i.idd IN ( SELECT d.id
4 FROM d
5 START WITH d.id IN ( SELECT p.idd
6 FROM p
7 , ( SELECT
f.id
8 FROM f
9 START
WITH f.id IN ( SELECT idf FROM s )
10 CONNECT
BY PRIOR f.idp = f.id
11 ) s
12 WHERE s.id = p.idf
13 )
14 CONNECT BY PRIOR d.id = d.idp
15 )
16 ;
ID
I2
I3
I4
I6Good Luck...
Similar Messages
-
A Single query with out the sub-queries
I am using My-SQL as my back-end and it doesnot support the
Sub-Queries. i have my table given below
UserID..UserName..ParentUserID
1........Admin...........0
2........Sales...........1
3........Sourcing........1
4........SalesHead.......2
5........SourcingHead....3
6........SalesExec.......4
7........SourExec........5
The table contains heirarchy of users. The top most users
has the ParentUserID as 0. and the remaining has their own ParentUserID
I want to get the complete heirarchy of a given user in single ResultSet.
It should be done without using sub-queries. but all joins can be used.
e.g.
if i say userid is 2 i should get following output:
Sales - > SalesHead -> SalesExec->......
Can any body please help me out!
Sridhar.Hi Sridhar,
You can use recursive method. Make a method as follows :
public String getChildren(int UserID)
String temp = "";
Connection con = DriverManager.getConnection("","","");
Statement st = con.createStatement();
ResultSet rs = statement.executeQuery("select UserID from MyUsers where ParentUserID = " + UserID);
while(rs.next())
temp += " [ ";
if(temp.equals(""))
temp += getChildren(rs(0));
else
temp += " -> " + getChildren(rs(0));
temp += " ] ";
return temp;
then call his method by providing any UserID to it and it will return you a string containing complete hierarchy in the following format :
AAA -> BBB -> CCC -> DDD
I hope it will help you.
regards,
Humayun -
db and dev 10g rel2 , hi all,
i am trying to learn the "WITH CLAUSE" , and i do not see any difference between using it and using sub-queries .
when i searched for this , i found that the with clause is used when You need to reference the subquery block multiple places in the query by specifying the query name , but i can not imagine an example for doing so .
if you could provide me with an example please ? and telling me about another situations in which i could need using the "with clause" if any ?
thanks>
db and dev 10g rel2 , hi all,
i am trying to learn the "WITH CLAUSE" , and i do not see any difference between using it and using sub-queries .
when i searched for this , i found that the with clause is used when You need to reference the subquery block multiple places in the query by specifying the query name , but i can not imagine an example for doing so .
if you could provide me with an example please ? and telling me about another situations in which i could need using the "with clause" if any ?
>
It isn't just about referencing a subquery multiple times. There are other advantages to using 'common table expressions'/'subquery factoring' also.
Take a look at the example below. It first defines 'dept_costs' as a query block, then defines 'avg_cost' as a new query block and it references the first query block.
Then the actual query references both query blocks just as if they are tables. And, in fact, in some circumstances Oracle will actually materialize them AS temporary tables.
Look at how easy it is to understand the entire statement. You can focus first on the 'dept_costs' query block WITHOUT having to look at anything else. That is because the query block is self-contained; you are defining a result set. There is no 'join' or connection to any other part of the statement.
It is easy for a developer, and for Oracle, to understand what is needed for that one piece.
Next you can focus entirely on the 'avg_cost' query block. Since it uses the first query block just as if it were a table you can treat it as a table. That means you do NOT even need to look at the first query block to understand what the second query block is doing.
Same with the actual query. You can analyze it by treating the two query blocks just as if they were other tables.
Even better you can test the first query block by itself in sql*plus or other tool to confirm that it works and you can create an execution plan for it to make sure it will use an appropriate index. You can also then test the first and second query blocks together to make sure THEY have a proper execution plan.
Then when you test then entire statement you already know that the query blocks work correctly.
Try to do THAT with a query that uses nested sub-queries.
Sure - you could write a set of nested sub-queries to accomplish the same thing (Oracle will sometimes rewrite your query that way itself) but it becomes one big query and the individual pieces are not nearly as easy to see, analyze or understand.
It can be difficult if not impossible to extract a nested query in order to test it even to just try to get the syntax working. And when you do extract it you will often be testing something that isn't quite exactly the same as when i t was nested.
So: easier to understand, easier to write and test (especially for new developers) as well as easier to use multiple times without having to duplicate it.
>
subquery_factoring_clause
The WITH query_name clause lets you assign a name to a subquery block. You can then reference the subquery block multiple places in the query by specifying the query name. Oracle Database optimizes the query by treating the query name as either an inline view or as a temporary table.
>
The SQL Language doc has an example.
http://docs.oracle.com/cd/B28359_01/server.111/b28286/statements_10002.htm#i2129904
>
Subquery Factoring: Example The following statement creates the query names dept_costs and avg_cost for the initial query block containing a join, and then uses the query names in the body of the main query.
WITH
dept_costs AS (
SELECT department_name, SUM(salary) dept_total
FROM employees e, departments d
WHERE e.department_id = d.department_id
GROUP BY department_name),
avg_cost AS (
SELECT SUM(dept_total)/COUNT(*) avg
FROM dept_costs)
SELECT * FROM dept_costs
WHERE dept_total >
(SELECT avg FROM avg_cost)
ORDER BY department_name;
DEPARTMENT_NAME DEPT_TOTAL
Sales 313800
Shipping 156400 -
Doubt in Firing Query with multiple opportunities UUID/IDs
HI Folks!
I might have simple doubt but please help me on this!
1. I have a custom BO with association to opportunities.
[DeploymentUnit(CustomerRelationshipManagement)] businessobject Sy_Trade {
[AlternativeKey] [Label("Trade Id")] element tradeid : BusinessTransactionDocumentID;
node RelatedOpportunities [0,n]{
element BusinessTransactionDocumentReference : BusinessTransactionDocumentReference;
element BusinessTransactionDocumentRelationshipRoleCode : BusinessTransactionDocumentRelationshipRoleCode;
association RelatedOpportunity[0,1] to Opportunity;
2. I have success fully used association and i am able to view create all the opportunities related to my custom Bo.
ISSUE : I want a facet where i just want DISPLAY the activities and sales document assigned in the RELATED OPPORTUNITIES ( N opportunities )
How do i query with Multiple opportunities ID and fetch the activities against it?
Btw I want to use query in UI Designer... I have created an advanced list pane and there i want the result list
I hope i am clear!
Thanks in adavance...
Regards
DhruvinHi Ludger,
I have successfully displayed Related Opportunities associated with trade.( i am able to create , delete also )
Issue : I am not able to "Display" ( i don't need to edit or create ) all the activities created against all the opportunities in a different tab.
I tried to approaches :
1: Query : Created a Query on Activity BO and tried to pass multiple related opportunities ( but seems not possible , please tell me any possibility to pass range of opportunity via transformation or anything? )
2 : binding : I have a Node Related Opportunity so just tried to bind it with BO model but problem is it is displaying all the activities of first opportunity of the list...
i think why because :
In Data model I have created a table bind with Related Opportunities...
now that node is 1 to N , association to opportunity 0 to 1 , hence i think it fetches only 1 opportunities activity
should i create like below ( Or is it possible)
Node Reltdoppts[0,1]
association [0,N] to opportunity BO ?
Although i strongly feel SAP should provied us two things :
1. We need to pass range of opportunities in a query.
2. We need to just write some absl code where i can fill the table and display it
and also is there any possibility to create a report or something to display activities as we just want to display the activities!
P.S : I have been getting a lot of bashing from client because some of the product restriction in cloud! i hope and wish SAP give developers free hand to develop right now its like our hands are tied to many things -
BaseTableName blank when calling GetSchema on a query with multiple tables
I am using ODP.NET 11.2.0.3.0 and when calling GetSchemaTable on a DataReader that contains a join the returned SchemaTable has the BaseTableName and BaseColumnName fields blank - this is different than what I see with the Oracle OLE DB Provider and with how SQL Server's native provider works. I can't find any discussion of this - is this on purpose or is it a bug? why does the available schema information vary so drastically between a single table query and a query with multiple tables joined?
Thanks,
Bryan HintonHi Bryan,
I am also facing the same issue. Did u find any work around or any suggestions will be well appreciated.
Thanks,
Naresh. -
Oracle hangs on query with multiple joins
To test the sotftware from the LMS-vendor that are out partners we use virtual machines where we install Windows 2003 servers and Oracle XE
While we were testing the software I've found that a particular query with multiple unions causes the CPU of the virtual machine totally claimed by oracle
The query causes oracle to hang.
I've found that the subcomponents of the query all return 0 rows (and response all immediately) combined into a query with at least 2 unions the query hangs the system
I'm not familiar with with Database Management at all
I've read something about SGA and PGA that could be the issue and tried to increase the target for both but it doesn't seem to do anything
Some characterics
Target Current
Maximum System Global Area (SGA) Size: 380 MB 380 MB
Program Global Area (PGA) Aggregate Target: 360 MB 38 MB
Current Configuration: (SGA + PGA): 740 MB 418 MB
Tablespaces Percent Used Allocated (MB) Used (MB) Datafiles
SYSAUX 98.21% 460.00 451.75 1
SYSTEM 73.09% 510.00 372.75 1
DATA 99.13% 440.00 436.19 1
UNDO 6.48% 160.00 10.38 1
USERS 1.63% 100.00 1.63 1
sort_area_size 65536
shared_pool_reserved_size 5452595 TRUE size in bytes of reserved area of shared pool
shared_pool_size 0 TRUE size in bytes of shared pool
What other parameters are important? How could I get a good picture to see what's really going on?
Some pointers, help would be appreciated.
Regards,
RemcoBelow is the base-query that is causing the problems
SELECT /* Public - Internal learner */ r.id reg_id, i.id order_item_id, o.id order_id, o.order_no order_number, e.id person_id, format_name(e.fname , e.lname , @@005) learner_name , c.id company_id, c.name2 , ent.id entid, ctype.id ctypeid, ctype.name , i.status , items.description item_desc, substr ( i.flags , 1 , 1 ) is_conf , r.status status1, rs.description description1 , r.wlist_priority , r.reg_no , r.flags , o.status status2, o.split, null learnerViewOnly, null statusViewOnly, i.approved_status, decode(substr(r.flags,2,1),'1','true','false') isWalkIn, oa.id offering_action_id, oa.status profile_status ,c.name2 org_name ,ctype.name audience_sub_type ,items.description description ,o.order_no order_no ,orderList.description order_status ,approvalList.description approval_status ,e.fname learner_first_name ,e.lname learner_last_name FROM tpt_registration r INNER JOIN tpt_oe_order_items i ON i.reg_id = r.id INNER JOIN tpt_oe_order o ON i.order_id = o.id INNER JOIN cmt_person e ON r.student_id = e.id INNER JOIN tpt_company c ON e.company_id = c.id INNER JOIN tpt_offering_action oa on r.offering_action_id = oa.id LEFT OUTER JOIN tpt_roster_template_entry ent ON r.ros_temp_ent_id = ent.id LEFT OUTER JOIN tpt_customer_type ctype ON ent.customer_type_id = ctype.id INNER JOIN fgt_ext_sys_list_of_val rs ON to_char ( r.status ) = rs.name INNER JOIN fgt_ext_sys_list_of_val items ON to_char ( i.status ) = items.name INNER JOIN fgt_ext_sys_list_of_val orderList ON to_char ( o.status ) = orderList.name INNER JOIN fgt_ext_sys_list_of_val approvalList ON to_char(i.approved_status) = approvalList.name WHERE e.type = 100 AND r.class_id = @@001 AND r.status = nvl ( to_number(@@002) , r.status ) AND rs.locale_id = @@005 AND rs.list_id = 'sysli000000000000100' AND items.locale_id = @@005 AND items.list_id = 'sysli000000000000131' AND orderList.list_id = 'sysli000000000000129' AND orderList.locale_id = @@005 AND approvalList.list_id = 'sysli000000000000165' AND approvalList.locale_id = @@005 AND ((@@003 is null) or (@@003 is not null and r.student_id = @@003))
UNION
SELECT /* Public - External learner */ r.id reg_id, i.id order_item_id, o.id order_id, o.order_no , e.id person_id, format_name(e.fname , e.lname , @@005) , c.id company_id, c.name2 , ent.id entid, ctype.id ctypeid, ctype.name , i.status , items.description , substr ( i.flags , 1 , 1 ) is_conf , r.status status1, rs.description description1, r.wlist_priority , r.reg_no , r.flags , o.status status2, o.split, null learnerViewOnly, null statusViewOnly, i.approved_status, decode(substr(r.flags,2,1),'1','true','false') isWalkIn, oa.id offering_action_id, oa.status profile_status ,c.name2 org_name ,ctype.name audience_sub_type ,items.description description ,o.order_no order_no ,orderList.description order_status ,approvalList.description approval_status ,e.fname learner_first_name ,e.lname learner_last_name FROM tpt_registration r INNER JOIN tpt_oe_order_items i ON i.reg_id = r.id INNER JOIN tpt_oe_order o ON i.order_id = o.id INNER JOIN cmt_person e ON r.student_id = e.id INNER JOIN tpt_offering_action oa on r.offering_action_id = oa.id LEFT OUTER JOIN tpt_company c ON e.company_id = c.id LEFT OUTER JOIN tpt_roster_template_entry ent ON r.ros_temp_ent_id = ent.id LEFT OUTER JOIN tpt_customer_type ctype ON ent.customer_type_id = ctype.id INNER JOIN fgt_ext_sys_list_of_val rs ON to_char ( r.status ) = rs.name INNER JOIN fgt_ext_sys_list_of_val items ON to_char ( i.status ) = items.name INNER JOIN fgt_ext_sys_list_of_val orderList ON to_char ( o.status ) = orderList.name INNER JOIN fgt_ext_sys_list_of_val approvalList ON to_char(i.approved_status) = approvalList.name WHERE e.type = 200 AND r.class_id = @@001 AND r.status = nvl ( to_number(@@002) , r.status ) AND rs.locale_id = @@005 AND rs.list_id = 'sysli000000000000100' AND items.locale_id = @@005 AND items.list_id = 'sysli000000000000131' AND orderList.list_id = 'sysli000000000000129' AND orderList.locale_id = @@005 AND approvalList.list_id = 'sysli000000000000165' AND approvalList.locale_id = @@005 AND ((@@003 is null) or (@@003 is not null and r.student_id = @@003))
UNION
SELECT /* Public - Unassigned learner */ r.id reg_id, i.id order_item_id, o.id order_id, o.order_no , null person_id, null , null company_id, null , ent.id entidd, ctype.id ctypeid, ctype.name , i.status , items.description , substr ( i.flags , 1 , 1 ) is_conf , r.status status1, rs.description description1, r.wlist_priority , r.reg_no , r.flags , o.status status2, o.split, null learnerViewOnly, null statusViewOnly, i.approved_status, decode(substr(r.flags,2,1),'1','true','false') isWalkIn, oa.id offering_action_id, oa.status profile_status ,'' org_name ,ctype.name audience_sub_type ,items.description description ,o.order_no order_no ,orderList.description order_status ,approvalList.description approval_status ,'' learner_first_name ,'' learner_last_name FROM tpt_registration r INNER JOIN tpt_oe_order_items i ON i.reg_id = r.id INNER JOIN tpt_oe_order o ON i.order_id = o.id INNER JOIN tpt_offering_action oa on oa.id = r.offering_action_id LEFT OUTER JOIN tpt_roster_template_entry ent ON r.ros_temp_ent_id = ent.id LEFT OUTER JOIN tpt_customer_type ctype ON ent.customer_type_id = ctype.id INNER JOIN fgt_ext_sys_list_of_val rs ON to_char ( r.status ) = rs.name INNER JOIN fgt_ext_sys_list_of_val items ON to_char ( i.status ) = items.name INNER JOIN fgt_ext_sys_list_of_val orderList ON to_char ( o.status ) = orderList.name INNER JOIN fgt_ext_sys_list_of_val approvalList ON to_char(i.approved_status) = approvalList.name WHERE r.class_id = @@001 AND r.status = nvl ( to_number(@@002) , r.status ) AND r.student_id is null AND rs.locale_id = @@005 AND rs.list_id = 'sysli000000000000100' AND items.locale_id = @@005 AND items.list_id = 'sysli000000000000131' AND orderList.list_id = 'sysli000000000000129' AND orderList.locale_id = @@005 AND approvalList.list_id = 'sysli000000000000165' AND approvalList.locale_id = @@005 AND @@003 is null
UNION
SELECT /* Private - Internal learner */ r.id reg_id, i.id order_item_id, o.id order_id, o.order_no , e.id person_id, format_name(e.fname , e.lname , @@005) , c.id company_id, c.name2 , ent.id entid, ctype.id ctypeid, ctype.name , i.status , items.description , substr ( i.flags , 1 , 1 ) is_conf , r.status status1, rs.description description1 , r.wlist_priority , r.reg_no , r.flags , o.status status2, o.split, null learnerViewOnly, null statusViewOnly, i.approved_status, decode(substr(r.flags,2,1),'1','true','false') isWalkIn, oa.id offering_action_id, oa.status profile_status ,c.name2 org_name ,ctype.name audience_sub_type ,items.description description ,o.order_no order_no ,orderList.description order_status ,approvalList.description approval_status ,e.fname learner_first_name ,e.lname learner_last_name FROM tpt_registration r INNER JOIN let_pvt_offering_request pvt_offreq ON pvt_offreq.class_id = r.class_id INNER JOIN tpt_offering_action oa on oa.id = r.offering_action_id LEFT OUTER JOIN tpt_oe_order_items i ON i.part_id = pvt_offreq.id LEFT OUTER JOIN tpt_oe_order o ON i.order_id = o.id INNER JOIN cmt_person e ON r.student_id = e.id LEFT OUTER JOIN tpt_company c ON e.company_id = c.id LEFT OUTER JOIN tpt_roster_template_entry ent ON r.ros_temp_ent_id = ent.id LEFT OUTER JOIN tpt_customer_type ctype ON ent.customer_type_id = ctype.id INNER JOIN fgt_ext_sys_list_of_val rs ON to_char ( r.status ) = rs.name LEFT OUTER JOIN fgt_ext_sys_list_of_val items ON to_char ( i.status ) = items.name AND items.locale_id = @@005 AND items.list_id = 'sysli000000000000131' LEFT OUTER JOIN fgt_ext_sys_list_of_val orderList ON to_char ( o.status ) = orderList.name AND orderList.list_id = 'sysli000000000000129' AND orderList.locale_id = @@005 LEFT OUTER JOIN fgt_ext_sys_list_of_val approvalList ON to_char(i.approved_status) = approvalList.name AND approvalList.list_id = 'sysli000000000000165' AND approvalList.locale_id = @@005 WHERE e.type = 100 AND r.class_id = @@001 AND r.status = nvl ( to_number(@@002) , r.status ) AND rs.locale_id = @@005 AND rs.list_id = 'sysli000000000000100' AND ((@@003 is null) or (@@003 is not null and r.student_id = @@003))
UNION
SELECT /* Private - External learner */ r.id reg_id, i.id order_item_id, o.id order_id, o.order_no , e.id person_id, format_name(e.fname , e.lname , @@005) , c.id company_id, c.name2 , ent.id entid, ctype.id ctypeid, ctype.name , i.status , items.description , substr ( i.flags , 1 , 1 ) is_conf , r.status status1, rs.description description1 , r.wlist_priority , r.reg_no , r.flags , o.status status2, o.split, null learnerViewOnly, null statusViewOnly, i.approved_status, decode(substr(r.flags,2,1),'1','true','false') isWalkIn, oa.id offering_action_id, oa.status profile_status ,c.name2 org_name ,ctype.name audience_sub_type ,items.description description ,o.order_no order_no ,orderList.description order_status ,approvalList.description approval_status ,e.fname learner_first_name ,e.lname learner_last_name FROM tpt_registration r INNER JOIN let_pvt_offering_request pvt_offreq ON pvt_offreq.class_id = r.class_id INNER JOIN tpt_offering_action oa on r.offering_action_id = oa.id LEFT OUTER JOIN tpt_oe_order_items i ON i.part_id = pvt_offreq.id LEFT OUTER JOIN tpt_oe_order o ON i.order_id = o.id INNER JOIN cmt_person e ON r.student_id = e.id LEFT OUTER JOIN tpt_company c ON e.company_id = c.id LEFT OUTER JOIN tpt_roster_template_entry ent ON r.ros_temp_ent_id = ent.id LEFT OUTER JOIN tpt_customer_type ctype ON ent.customer_type_id = ctype.id INNER JOIN fgt_ext_sys_list_of_val rs ON to_char ( r.status ) = rs.name LEFT OUTER JOIN fgt_ext_sys_list_of_val items ON to_char ( i.status ) = items.name AND items.locale_id = @@005 AND items.list_id = 'sysli000000000000131' LEFT OUTER JOIN fgt_ext_sys_list_of_val orderList ON to_char ( o.status ) = orderList.name AND orderList.locale_id = @@005 AND orderList.list_id = 'sysli000000000000129' LEFT OUTER JOIN fgt_ext_sys_list_of_val approvalList ON to_char(i.approved_status) = approvalList.name AND approvalList.locale_id = @@005 AND approvalList.list_id = 'sysli000000000000165' WHERE e.type = 200 AND r.class_id = @@001 AND r.status = nvl ( to_number(@@002) , r.status ) AND rs.locale_id = @@005 AND rs.list_id = 'sysli000000000000100' AND ((@@003 is null) or (@@003 is not null and r.student_id = @@003)) ORDER BY 34,35,28,29,31,30,33,32 -
APD using Query with multiple structures as a data source
All,
I want to set up an automatic process which executes a query and exports it to a shared drive as a csv file. I have tried various options , when I try to use APD to set up the extract, I get an error and this is because the query that I am trying to use has Strucutres in both rows and columns. Hence, I am unable to use this option. I tried RSCRM_BAPI, It works well, but there is an issue with scheduling this in Process chain. I created an event and scheduled this as a job to trigger after "event" as per SAP instructions, but the job does not exist and it is not possible to trigger it through the Process chain unless the variables are hard coded in the query which I do not want to do.
Can any one tell me if there is a way to deal with APD using Query with multiple structures?
Would really appreciate if some one can give me the right solution...
ThanksHi Tanu ,
APD is an option but its not very good with large amount of data or hiearachies or if you have attributes in you query structure .
One more option for this requirement is use of report program using function module RRW3_GET_QUERY_VIEW_DATA .
This will work fine with multiple structure etc .
There are some overheads with this FM ex: if amount of data is too much then program will give dump .Solution for that is we call the FM in LOOP by diving amount of data need to be fetched .ex: we can read data quarter wise.
For using this function module what you can do is write an ABAP program (At SE38 ) .which will call this FM and then write the output into a flat file which you can save at application server (AL11) .From there other system can read it .
To automate this whole process you can further add all the report programs into a process chain (RSPC) which can be schedule as per requirement .
To pass input parameters you can use variants that will pass the values to the report .
Check thi link for sample code :
[http://www.tricktresor.de/content/index.php?navID=696&aID=496]
Hope this will be helpful .
Regards,
Jaya Tiwari -
Spatial Query with multiple geometries from 2 tables
Hi,
I'm using Oracle 8.1.7. I am trying to do a spatial query on two tables with multiple geometries. There are two spatial tables. One made up of points and one made up of polygons. There are 829551 rows in the table of points and 1817795 rows in the table with polygons...
I want to find all polygons where one of this points is within it...
This query is pretty intensive querying two large spatial tables against each other and so I need to find the most efficient way of running this query. I've been running variations of my query for the last two week and every time it's bombed out with various errors after 12-24 hrs processing like out of memory, out of tablespace, out of processing, invalid index etc etc etc. I need to get this query run asap... Any tips would be gratefully appreciated..
For the session running the query I've allocated 16M sort area with
ALTER SESSION SET SORT_AREA_SIZE=16777216;
Below is the query I'm running... How can I improve this please? BTW PARCEL_OVERLAPS contains the points and TP$_PARCEL_AREAS the polygons.
SELECT lu.LNU_PARCEL_ID
FROM
seventy.PARCEL_OVERLAPS po,
imap_topol.TP$_PARCEL_AREAS pa,
TP$_PARCEL_CENTROID_AREA pca,
TDCR_LAND_UNIT lu
WHERE
SDO_FILTER(po.geometry, pa.area,
'querytype=WINDOW') = TRUE and
sdo_within_distance(po.geometry,pa.area,'distance=0')='TRUE' and
pa.delete_date is null and
Lu.LNU_LAND_UNIT_UNIQUE_NUM = pca.CENTROID_ID and
pa.AREA_ID = pca.AREA_ID and
pca.DELETE_DATE IS NULL and
pa.DELETE_DATE IS NULL;Albert,
Thanks for your reply and the tips you've given. The tp$_parcel_areas table will always be bigger so I've changed the order to sdo_within_distance(pa.area,po.geometry,'distance=0')='TRUE'. The requested counts for those queries are
12:26:29 [email protected]:SQL> select count(*)
13:46:22 2 from seventy.PARCEL_OVERLAPS;
COUNT(*)
612
13:48:12 [email protected]:SQL> select count(*)
13:48:17 2 from imap_topol.TP$_PARCEL_AREAS pa,
13:48:21 3 TP$_PARCEL_CENTROID_AREA pca
13:48:21 4 where pca.DELETE_DATE IS NULL
13:48:21 5 and pa.DELETE_DATE IS NULL
13:48:21 6 and pa.AREA_ID = pca.AREA_ID;
COUNT(*)
1310665
There was no reason for both filter and within_distance. I did try use the anyinteract but for some reason that does not return the desired results(I've added one id row as a test to make sure it returns desired results). Plus Oracle have recomended using the within distance for better performance..
so the explan plan for
14:38:37 [email protected]:SQL> EXPLAIN PLAN FOR
14:38:50 2 SELECT lu.LNU_PARCEL_ID
14:38:50 3 FROM
14:38:50 4 seventy.PARCEL_OVERLAPS po,
14:38:50 5 imap_topol.TP$_PARCEL_AREAS pa,
14:38:50 6 TP$_PARCEL_CENTROID_AREA pca,
14:38:50 7 TDCR_LAND_UNIT lu
14:38:50 8 WHERE
14:38:50 9 sdo_within_distance(pa.area,po.geometry,'distance=0')='TRUE' and
14:38:50 10 pa.delete_date is null and
14:38:50 11 Lu.LNU_LAND_UNIT_UNIQUE_NUM = pca.CENTROID_ID and
14:38:50 12 pa.AREA_ID = pca.AREA_ID and
14:38:50 13 pca.DELETE_DATE IS NULL and
14:38:50 14 pa.DELETE_DATE IS NULL;
is
Plan Table
| Operation | Name | Rows | Bytes| Cost | Pstart| Pstop |
| SELECT STATEMENT | | 4G|32920G| 547M| | |
| NESTED LOOPS | | 4G|32920G| 547M| | |
| MERGE JOIN | | 547M| 2029G| 230124 | | |
| SORT JOIN | | 1M| 36M| 85014 | | |
| MERGE JOIN | | 1M| 36M| 50019 | | |
| SORT JOIN | | 1M| 17M| 21650 | | |
| TABLE ACCESS FULL |TP$_PARCE | 1M| 17M| 485 | | |
| SORT JOIN | | 1M| 22M| 28369 | | |
| TABLE ACCESS FULL |TDCR_LAND | 1M| 22M| 2127 | | |
| SORT JOIN | | 42K| 160M| 145111 | | |
| TABLE ACCESS FULL |TP$_PARCE | 42K| 160M| 12697 | | |
| TABLE ACCESS FULL |PARCEL_OV | 817 | 3M| 1 | | |
14:43:14 [email protected]:SQL> explain plan for
14:43:23 2 SELECT pa.AREA_ID
14:43:23 3 FROM seventy.PARCEL_OVERLAPS po,
14:43:23 4 imap_topol.TP$_PARCEL_AREAS pa
14:43:23 5 WHERE SDO_RELATE(po.geometry, pa.area,'mask=ANTINTERACT querytype=WINDOW') = 'TRUE'
14:43:23 6 and pa.DELETE_DATE IS NULL;
Plan Table
| Operation | Name | Rows | Bytes| Cost | Pstart| Pstop |
| SELECT STATEMENT | | 6M| 50G| 10M| | |
| NESTED LOOPS | | 6M| 50G| 10M| | |
| TABLE ACCESS FULL |PARCEL_OV | 817 | 3M| 1 | | |
| TABLE ACCESS FULL |TP$_PARCE | 850K| 3G| 12697 | | |
14:45:03 [email protected]:SQL> explain plan for
14:45:04 2 SELECT pa.AREA_ID
14:45:05 3 FROM seventy.PARCEL_OVERLAPS po,
14:45:05 4 imap_topol.TP$_PARCEL_AREAS pa
14:45:05 5 WHERE SDO_RELATE(pa.area, po.geometry,'mask=ANTINTERACT querytype=WINDOW') = 'TRUE'
14:45:05 6 and pa.DELETE_DATE IS NULL;
Plan Table
| Operation | Name | Rows | Bytes| Cost | Pstart| Pstop |
| SELECT STATEMENT | | 6M| 50G| 863554 | | |
| NESTED LOOPS | | 6M| 50G| 863554 | | |
| TABLE ACCESS FULL |TP$_PARCE | 850K| 3G| 12697 | | |
| TABLE ACCESS FULL |PARCEL_OV | 817 | 3M| 1 | | |
-------------------------------------------------------------------------------- -
Auth Error in BW while executing a query with Company hierarchy
Hi All,
I have an issue in BW Reporting auth objects.. Hope to get resolved here.
We are using BI 7.0. However We are still using the Reporting auth objects for fiield level security. We are having a problem while executing a query with company code hierarchy ,which is built on a multiprovider.
The Background is as below
Multiprovider: ZM_CD01 with 5 infocubes
Query: Has 0COMP_CODE as free characteristics with display hierarchy for Japan (Node APSC_012 is fixed value)
Node APSC_012 has 4070,4076,407A,408A,9830 company code values under it.
Reporting Auth Objects:
Z0COMPCODE: (for flat values)
4070,4076,407A,408A,407M,407P,8236, :
ZHCOMPCODE: (For tree structure)
4070,4076,407A,408A,407M,407P,8080, :
APSC_MGMT_HIER (Nodes: APSC_012,APSC019)
Both the reporting authorization objects are checked for multi provider ZM_CD01 in RSSM
While executing the query the following Auth error is received.
You do not have authorization to read object "Z0COMPCODE" authorization on '0COMP_CODE'
When I change the values for Z0COMPCODE to * it works fine. No Auth error.
Please help me resolve this issue. It is very critical now as the user needs to execute some important reports.
Thanks in Advance.
Ramkumar CHi Chandra,
Try the following:
1. Go to tcode RSSM
2. Enter the cube ZM_CD01 (all the other cubes) then click change.
3. Afterwards, u201Cunchecku201D ALL Authorization Objects under this cube. (Repeate the same for all the cubes)
4. Click Save.
This will resolve the issue.
Rgds,
Raghu -
Query with multiple outer joins
I had a doubt with whether the following kind of query is valid with multiple outer-joins. The format of the query is something like this:-
select A.col1, B.col2
from table1 A, table2 B, table3 C where
A.col3=B.col4(+) and B.col5=C.col6(+)
This would mean the follwoing with regard to outer-joins in the query.
1) fetch records with col3 in table A matching or not matching col4 in table B
2) fetch records with col5 in table B matching or not matching col6 in table C
So, this query is valid?
I hope, my question is clear.
Please, help in solving the doubt.
regardsThis is valid and it works fine
-
How to create the query with multiple node types
Hi,
I am having an issue in creating a query to search multiple node types.
The requirement is to query documents/pages of the type dam:Asset and cq:Page present under a path.
I tried the following code snippet with no luck .
path=/content
1_type=cq:Page
2_type=dam:Asset
property=jcr:content/metadata/@cq:tags
property.1_value=<tag Name>
I was able to write a query with single type. However i could not find any documents/ materials with multipe types as shown above.
Thanks in advance.
Regards
SudhiI don't think multiple type is possible. Instead use super type like nt:base that will cover both page and asset.
Yogesh
www.wemblog.com -
Decode with multiple column sub query
Dear's
What is the wrong with the query
select * from common_master
where
(company_code,lpad(rtrim(ltrim(bu_code)),12,' ')) IN
decode ('ADMIN','ADMIN',(select company_code ,lpad(rtrim(ltrim(bu_code)),12,' ') from common_master )
,(select company_code ,lpad(rtrim(ltrim(bu_code)),12,' ') from user_system_privs) )
The error message as
Error starting at line 16 in command:
select * from common_master
where
(company_code,lpad(rtrim(ltrim(bu_code)),12,' ')) IN
decode ('ADMIN','ADMIN',(select company_code ,lpad(rtrim(ltrim(bu_code)),12,' ') from common_master )
,(select company_code ,lpad(rtrim(ltrim(bu_code)),12,' ') from user_system_privs) )
Error at Command Line:18 Column:53
Error report:
SQL Error: ORA-00920: invalid relational operator
00920. 00000 - "invalid relational operator"
*Cause:
*Action:
DennisYou can club the columns in where clause and in decode
like
select * from common_master
where
(company_code || lpad(rtrim(ltrim(bu_code)) || to_char(12) ||' ') IN
( select decode ('ADMIN','ADMIN',company_code || lpad(rtrim(ltrim(bu_code)) || to_char(12) || ' ') from common_master ),
,company_code || lpad(rtrim(ltrim(bu_code)) || to_char(12) ||' ') from user_system_privs) )
HTH,
~Yogesh -
Hi,
I am facing some problems in teaching Multiple column subqueries and also ig u'll could with some example show me how to use sub-query using from clause??Essentially you are using subqueries within the FROM clause.
Here is an example of an embedded view (i.e. view-on-the-fly):
select a.person_id, a.fname, a.lname,
c.job_id
from person a,
(select b.person_id, b.fname,
b.lname, b.job_id
from jobs b) c
where a.person_id = c.person_id -
HI Team,
Can we create multiple lines in an SAP Query? If yes, how (pls explain the steps)?
Like can we have a line for the employee, next for spouse & then the next for child, so on...and then the next employee details.
Also, there might be fields which will repeat in most of these lines for each employee.
Thanks
RLHi RL:
HR module have PA0021 table (HR Master Record: Infotype 0021 (Family), with this table into TCODE: SQ02 is naturally obtain the result that you ask, or Do you are customizing "Z" program with ALV?
Regards
José Luis -
Hierarchical query with multiple roots
Hi,
I'm trying to write a sql query to find blocking lock in database. The idea is to get the blocker in 1st column, comma separated list of waiters in 2nd column and number of waiters in 3rd column.
As of now i use below query to get a tree structure
WITH lk AS
(SELECT blocking_session||' (Inst-'||blocking_instance || ')' blocker,
SID||' (Inst-'||inst_id || ')' waiter
FROM gv$session
WHERE blocking_instance IS NOT NULL AND blocking_session IS NOT NULL)
SELECT LPAD (' ', 2 * (LEVEL - 1)) || waiter lock_tree
FROM (SELECT *
FROM lk
UNION ALL
SELECT DISTINCT 'root', blocker
FROM lk
WHERE blocker NOT IN (SELECT waiter
FROM lk))
CONNECT BY PRIOR waiter = blocker
START WITH blocker = 'root';
Result:-
===========
LOCK_TREE
1966 (Inst-1)
908 (Inst-1)
1906 (Inst-1)
1900 (Inst-1)
981 (Inst-1)
921 (Inst-1)
937 (Inst-1)
962 (Inst-1)
1889 (Inst-1)
1904 (Inst-1)
974 (Inst-1) But what i expect is like below. My below query works when there is only one root blocker, but fails when there are multiple root node.
WITH lk AS
(SELECT blocking_session || '(Inst-' || blocking_instance || ')' blocker,
SID || '(Inst-' || inst_id || ')' waiter
FROM gv$session
WHERE blocking_instance IS NOT NULL AND blocking_session IS NOT NULL)
SELECT blocker, SUBSTR (SYS_CONNECT_BY_PATH (waiter, ';'), 2) waiters
FROM (SELECT blocker, waiter, ROW_NUMBER () OVER (ORDER BY waiter)
val
FROM lk
GROUP BY blocker, waiter)
WHERE CONNECT_BY_ISLEAF = 1
START WITH val = 1
CONNECT BY PRIOR val = val - 1
Result:-
===========
WAITERS# BLOCKER WAITERS
3 981(Inst-1) 1904(Inst-1);921(Inst-1);937(Inst-1)
....lot of duplicates
expected result:-
===========
WAITERS# BLOCKER WAITERS
4 981(Inst-1) 1904(Inst-1);921(Inst-1);937(Inst-1);974(Inst-1)
3 1966(Inst-1) 908 (Inst-1);1906 (Inst-1);1900 (Inst-1) can you please help me correct above query or suggest other ways to archive this result.
Thanks in advance
MidhunGTHi All,
Thank you all for your support. I never knew these many ways to see blocking lock in database :)
Somehow i was able get the desired result for my specific requirement with below query
sql> WITH lk AS
2 (SELECT blocking_session || ' (Inst-' || blocking_instance
3 || ')' blocker,
4 SID || ' (Inst-' || inst_id || ')' waiter
5 FROM gv$session
6 WHERE blocking_instance IS NOT NULL AND blocking_session IS NOT NULL)
7 SELECT blocker,
8 LTRIM
9 (MAX (SYS_CONNECT_BY_PATH (waiter, ','))KEEP (DENSE_RANK LAST ORDER BY cnt),
10 ','
11 ) AS waiters,
12 MAX (cnt) waiters#
13 FROM (SELECT blocker, waiter,
14 ROW_NUMBER () OVER (PARTITION BY blocker ORDER BY waiter)
15 AS cnt
16 FROM lk)
17 GROUP BY blocker
18 CONNECT BY cnt - 1 = PRIOR cnt AND blocker = PRIOR blocker
19 START WITH cnt = 1;
BLOCKER WAITERS WAITERS#
1946 (Inst-1) 1987 (Inst-1),879 (Inst-1),910 (Inst-1) 3
930 (Inst-1) 1919 (Inst-1),1945 (Inst-1),1953 (Inst-1),1983 (Inst-1) 4please advice, if any scope for improvement
Thanks and Regards,
MidhunGT
Maybe you are looking for
-
Web Gallery not Opening Webpage Editor?
when selecting my images for a web gallery and then choosing new web gallery from selection the new folder appears in projects, but doesn't open up the webpage editor like the manual says that it should. i've been working on this for 2 hours and am u
-
How do i get my mp3 file to open in garageband?
how do i get my mp3 file to open in garageband?
-
Why did Apple drop support on Windows XP 64-bit, but not on 32-bit?
I have Windows XP 64-bit and do not feel the need to get a new computer or upgrade the operating system. What I wonder is why Apple still makes iTunes for 32-bit XP and not 64-bit XP?
-
HT201364 I have a Mac Pro that was purchased 8/06. How can I upgrade to Mavericks?
Is there any way to upgrade tp Mavericks on a Mac Pro built in the summer of 2006?
-
Mountain Lion Upgrade crashes my macbook
I upgrade my 2008 macbook. periodically my computer automatically reboots. What is causing the problem? Is there anything I can do about it? I ran the utility disk, but it did not help. This is information my macbook is displaying: Interval Since Las