Connect By Query - Please help
I am having some difficulty figuring out how to write this query. I have three tables that need to be joined in a heirarchial manner. So, I am assuming that I will need two or three connect by statements (haven't seen that documented anywhere). Also the values need to be returned in a single select statement so that it can be used in an insert into select... statement.
For simplicities sake, here is how the tables are laid out.
STOWAGE_PARENT
*ParentID-------------
*ParentName |
|
STOWAGE |
*ParentID-------------
*StowageID------|------
*StowagePID-----| |
*PartName |
|
STOWAGE_CHILDREN |
*ChildID |
*StowageID-------------
*Barcode
What I need is to be able to have a single query that will return the following:
ParentName1
*PartName1
**PartName2
**Partname3
***Barcode1
***Barcode2
**PartName4
***PartName5
ParentName2
*PartName6
I am not really sure how the details will work out, but this is just my rough guess at what would be required. Hopefully there is a simple way to acomplish this. Any help would be greatly appreciated.
Something to the effect of:
INSERT INTO TEMP_TABLE
(DISPLAY,KEY)
SELECT Parent_Name AS DISPLAY ,Parent_ID AS KEY
FROM STOWAGE_PARENT P, STOWAGE S
CONNECT BY PRIOR P.ParentID = S.ParentID
UNION /* Not sure how this works */
SELECT PartName AS DISPLAY, STOWAGE_ID AS KEY
FROM STOWAGE S
CONNECT BY PRIOR P.StowageID = P.StowagePID
UNION
SELECT Barcode AS DISPLAY, StowageID AS KEY
FROM STOWAGE_CHILDREN C, STOWAGE S
CONNECT BY PRIOR C.AStowageID = S.StowageID
Last thing, the reason that I am needing the single query is so that I can have the query stored in a table and have it populate a table to create a comparison report. From our setup it is one of the only solutions that will work. Let me know if this is not clear enough or if you need additional information. Thanks in advance.
1- Always include your Oracle version number (ver 9 and 10g both added new functions for use with connect by)
2- What did you get when you tried to run your query?
3- If you posted the create table statement with a few valid inserts for each table it would make it easier for someone with a few minutes of time to tack a crack at your problem.
HTH -- Mark D Powell --
Similar Messages
-
Hi there, I am trying to connect to my server at work from home using a vpn connection. It connects fine and the time ticks along, but when i click go - connect to server, it comes up with connection failed. Please help!
... when i click go - connect to server, it comes up with connection failed.
If you're trying to connect to a Bonjour server on the remote network, that won't work over a layer 3 VPN. Use something like Hamachi or one of the SSH-tunnelling Bonjour proxy apps for that. -
After the IOS7 update, i can no longer use my imessage and facetime. It says "waiting for activation" and tried to log in on my apple id but it turned out to connection error. Please help me guys! Thank you.
Have you tried to reboot your phone(hold home and lock button simutainiously)?
-
How to improve the performance of the attached query, Please help
Hi,
How to improve performance of the below query, Please help. also attached explain plan -
SELECT Camp.Id,
rCam.AccountKey,
Camp.Id,
CamBilling.Cpm,
CamBilling.Cpc,
CamBilling.FlatRate,
Camp.CampaignKey,
Camp.AccountKey,
CamBilling.billoncontractedamount,
(SUM(rCam.Impressions) * 0.001 + SUM(rCam.Clickthrus)) AS GR,
rCam.AccountKey as AccountKey
FROM Campaign Camp, rCamSit rCam, CamBilling, Site xSite
WHERE Camp.AccountKey = rCam.AccountKey
AND Camp.AvCampaignKey = rCam.AvCampaignKey
AND Camp.AccountKey = CamBilling.AccountKey
AND Camp.CampaignKey = CamBilling.CampaignKey
AND rCam.AccountKey = xSite.AccountKey
AND rCam.AvSiteKey = xSite.AvSiteKey
AND rCam.RmWhen BETWEEN to_date('01-01-2009', 'DD-MM-YYYY') and
to_date('01-01-2011', 'DD-MM-YYYY')
GROUP By rCam.AccountKey,
Camp.Id,
CamBilling.Cpm,
CamBilling.Cpc,
CamBilling.FlatRate,
Camp.CampaignKey,
Camp.AccountKey,
CamBilling.billoncontractedamount
Explain Plan :-
Description Object_owner Object_name Cost Cardinality Bytes
SELECT STATEMENT, GOAL = ALL_ROWS 14 1 13
SORT AGGREGATE 1 13
VIEW GEMINI_REPORTING 14 1 13
HASH GROUP BY 14 1 103
NESTED LOOPS 13 1 103
HASH JOIN 12 1 85
TABLE ACCESS BY INDEX ROWID GEMINI_REPORTING RCAMSIT 2 4 100
NESTED LOOPS 9 5 325
HASH JOIN 7 1 40
SORT UNIQUE 2 1 18
TABLE ACCESS BY INDEX ROWID GEMINI_PRIMARY SITE 2 1 18
INDEX RANGE SCAN GEMINI_PRIMARY SITE_I0 1 1
TABLE ACCESS FULL GEMINI_PRIMARY SITE 3 27 594
INDEX RANGE SCAN GEMINI_REPORTING RCAMSIT_I 1 1 5
TABLE ACCESS FULL GEMINI_PRIMARY CAMPAIGN 3 127 2540
TABLE ACCESS BY INDEX ROWID GEMINI_PRIMARY CAMBILLING 1 1 18
INDEX UNIQUE SCAN GEMINI_PRIMARY CAMBILLING_U1 0 1Hello,
This has really nothing to do with the Oracle Forms product.
Please, send the SQL or/and PL/SQL questions in the corresponding forums.
Francois -
When I try using FaceTime it doesn't seem to work. When someone face times me all I get is a missed notification. An when I try to FaceTime someone it tells me to connect to wifi please help.
Alright, when you are attempting to FaceTime someone, are you connected to WiFi? With the iPhone 4, it does not support using FaceTime over the cellular network, you will need to be connected to Wi-fi.
-
I have a MacBookPro with OSX 10.9, and my Tata Photon plus is not working on it. When I try to connect, Its not connecting.. Please Help
<Email Edited by Host>Current Firefox versions require a Mac with an Intel processor and OS X 10.6 (Firefox 16 runs on Intel Mac OS X 10.5).
*http://www.mozilla.org/firefox/25.0/system-requirements/
For an unofficial Firefox 17.0.10 ESR compatible version that runs on a PowerPC Mac with OS X 10.4.11 or OS X 10.5.8 you can look at TenFourFox.
*http://www.floodgap.com/software/tenfourfox/
*http://www.macupdate.com/app/mac/37761/tenfourfox
*http://code.google.com/p/tenfourfox/wiki/ReleaseNotes1710
See also:
*http://code.google.com/p/tenfourfox/wiki/PluginsNoLongerSupported
*http://code.google.com/p/tenfourfox/wiki/QuickTimeEnabler
*http://code.google.com/p/tenfourfox/wiki/AAATheFAQ -
I have just bought iPhone 3gs in Sept.11. I was trying to update the software using itunes but it is showing Error "-3259" saying connection timeout. Please help.
Did you already check your securit software settings? iTunes has to contact Apple during the update process.
See this article: iTunes for Windows: Troubleshooting security software issues -
hi, i just try to update my 3g in itunes unfortunatly it got error while updating it asked me to restore update but unable to restore it , now my 3g i locked and on screen it displying usb symbol connect to itunes ,please help me regarding this
I suspect your error was 1015, not 1051. This usually involves a jailbroken iPhone, use Google to find your solution.
-
When I am on line and click on another link, it won't connect...PLEASE HELP!
See:
iOS: Device not recognized in iTunes for Windows
You need iTunes version 10.7 -
My iPad/iPhone wont connect to iTunes please help
My iPad/iPhone wont connect to iTunes please help...im trying to sync both but its not connecting to iTunes and id like to update my music library
Hello there, gretchenkemp95.
The following Knowledge Base articles offer up some great, in-depth steps for troubleshooting your iOS device not being recognized:
iOS: Device not recognized in iTunes for Windows
http://support.apple.com/kb/ts1538
or
iOS: Device not recognized in iTunes for Mac OS X
http://support.apple.com/kb/ts1591
Thanks for reaching out to Apple Support Communities.
Cheers,
Pedro. -
While trying to import pictures from iPhone to iTunes, iTunes request to make software update and then to restore iPhone. I have cancelled the restore to rpotect pictures. The pictures have not been imported yet, but the iPhone display freezed at ITune connection page. Please help me save pictures and use the iPhone as usual. Restarting of the phone did not work so far.
RingomonIf the device is in recovery mode there is no date on the device to salvage.
Restore the device. -
PROBLEM WITH HIERARCHICAL QUERY - PLEASE HELP
I have got three tables :
CREATE TABLE FIRM
(FID INTEGER NOT NULL PRIMARY KEY,
FNAME VARCHAR(40),
FTYPE VARCHAR(3),
MASTERID INTEGER );
CREATE TABLE FACULTY
(FAID INTEGER NOT NULL PRIMARY KEY,
FANAME VARCHAR(40),
FATYPE VARCHAR(3),
MASTERID INTEGER );
CREATE TABLE EMPLOYEE
(EID INTEGER NOT NULL PRIMARY KEY,
ENAME VARCHAR(20),
ESURNAME VARCHAR(20),
EJOB VARCHAR(3),
MASTERID INTEGER );
This is a hierarchical tree(or is ment to be, I,m complete rookie ) . Firm can be the root or can be slave to another firm. Faculty can be slave to firm, or to another faculty. Employee can be slave to faculty or to another employee(e.g. boss). This connections are specified by MASTERIDs.
I need to write a procedure, which parameter would be node ID. It is meant to create a VIEW from this node as if it was a root (view of a subtree).
I tried CONNECT BY clause but it works only on one table at a time and I have here three tables.
I completely don,t know how to write it. Please help.create view hierarchy as
select id, master_id, name from table1
union all
select id, master_id, name from table2
union all
select id, master_id, name from table3
Then do your connect by query against hierarchy.
It will not work in 8i (connect by on views not allowed), so you will need to materialize the view.
Kirill -
How to make recursive query.Please help
Dear Experts:
I want to retrieve all employees located in a department in addition to all other employees located in the child's nodes of this department too.
Problem Details:
I have "Employees" table and "Departments" Table
The structure of Dept Table is:
ID primary key
parent_dept foreign key(id)
deptname varchar2
deptType varchar2
The Employee table structure is
ID primary key
dept_id foreign key(Department.id)
empName varchar2Sample data for departments
ID : 1
parent_dept : null
deptname: General Manager office
deptType : 'GM'
ID :=2
parent_dept : 1
deptname: Information tech.
deptType : 'DPT'
ID :=3
parent_dept : 2
deptname: Software Development
deptType : 'SECTION'Sample Data for employees
ID : 101
dept_id :1
empName King
ID : 102
dept_id :2
empName ALAN
ID : 103
dept_id :2
empName SAM
ID : 104
dept_id :3
empName JANEI want to create a query that accepts a parameter "p_department_id" and returns All employees on the following conditions
1- In case the parameter value is null , then retrieve All Employees "king - alan- sam-jane"
2- In Case the parameter value is 1 , then retrieve all the employees under department id =1 in addition to all the employees located under the children departments.
in this case it will be "king - alan- sam-jane"
3- In case parameter value is 2 , then return all the employees under department id =2 in addition to all the employees located under the children departments.
In this case it will be " alan- sam-jane"
4- In case parameter value is 3 , then return all the employees under department id =3 in addition to all the employees located under the children departments.
in this case it will be only "JANE"
In brief , If I pass any value to the parameter :p_department_id , I want to retrieve all employees located in this department in addition to other employees located in the child's nodes of this department id
I use oracle database 11g release 2
Please help me
Thanks
Edited by: ta**** on Apr 3, 2013 5:56 PM
Edited by: ta**** on Apr 3, 2013 5:58 PMSQL> variable p_department_id number
SQL> exec :p_department_id := null
PL/SQL procedure successfully completed.
SQL> with employees as (
2 select 101 id,1 dept_id,'King' empName from dual union all
3 select 102,2,'ALAN' from dual union all
4 select 103,2,'SAM' from dual union all
5 select 104,3,'JANE' from dual
6 ),
7 departments as (
8 select 1 id,null parent_dept,'General Manager office' deptname,'GM' deptType from dual union all
9 select 2,1,'Information tech.','DPT' from dual union all
10 select 3,2,'Software Development','SECTION' from dual
11 )
12 select *
13 from employees
14 where dept_id in (
15 select id
16 from departments
17 start with (
18 (
19 :p_department_id is null
20 and
21 parent_dept is null
22 )
23 or
24 id = :p_department_id
25 )
26 connect by parent_dept = prior id
27 )
28 /
ID DEPT_ID EMPN
101 1 King
102 2 ALAN
103 2 SAM
104 3 JANE
SQL> exec :p_department_id := 1
PL/SQL procedure successfully completed.
SQL> /
ID DEPT_ID EMPN
101 1 King
102 2 ALAN
103 2 SAM
104 3 JANE
SQL> exec :p_department_id := 2
PL/SQL procedure successfully completed.
SQL> /
ID DEPT_ID EMPN
102 2 ALAN
103 2 SAM
104 3 JANE
SQL> exec :p_department_id := 3
PL/SQL procedure successfully completed.
SQL> /
ID DEPT_ID EMPN
104 3 JANE
SQL> SY. -
Hello Forum Members,
Can you please help me out:
SQL> select * from quarter_test4;
QUARTER CONFIG REP_DATE
Q1-2007 10 12-JAN-07
Q2-2007 10 21-APR-07
Q3-2007 870 14-AUG-07
Q4-2007 50 15-NOV-07
Q1-2008 60 02-JAN-09
Q4-2006 160 02-DEC-06
I want the following out put:
Please note that the future quarters should have current quarter sum(config).Please note that The current table
does not hold future quarters.I have to genarate query on which a report is based.
My Query:
SELECT quarter,
CASE
WHEN qtr > TRUNC(SYSDATE, 'q')
THEN LAST_VALUE(sum_config IGNORE NULLS) OVER(ORDER BY qtr)
ELSE sum_config
END sum_config
FROM (SELECT qtr, q.qtrstr quarter, SUM(qt.config) sum_config
FROM (SELECT 'Q' || TO_CHAR(qtr, 'q-yyyy') qtrstr, qtr
FROM (SELECT ADD_MONTHS(ADD_MONTHS(TRUNC(SYSDATE, 'q'), -13), 3 *(LEVEL - 1)) qtr
FROM DUAL
CONNECT BY LEVEL <= 9)
ORDER BY qtr) q,
quarter_test4 qt
WHERE qt.quarter(+) = q.qtrstr
GROUP BY qtr, q.qtrstr)
ORDER BY qtr;
Correct Output Generated:
QUARTER SUM_CONFIG
Q4-2006 160
Q1-2007 10
Q2-2007 10
Q3-2007 870
Q4-2007 50
Q1-2008 60
Q2-2008 60
Q3-2008 60
Q4-2008 60
====================================================================================================================================
New Requirement:Product column has been added.
SQL> select * from quarter_test3;
QUARTER CONFIG REP_DATE PRODUCT
Q1-2007 10 12-JAN-07 P1
Q2-2007 10 21-APR-07 P1
Q3-2007 870 14-AUG-07 P1
Q4-2007 50 15-NOV-07 P1
Q1-2008 60 02-JAN-09 P1
Q4-2006 160 02-DEC-06 P1
Q4-2006 997 02-DEC-06 P2
Q4-2007 60 14-NOV-07 P2
Q3-2007 970 14-NOV-07 P2
Q2-2007 20 21-APR-07 P2
Q1-2007 20 12-JAN-07 P2
QUARTER CONFIG REP_DATE PRODUCT
Q1-2008 70 12-JAN-08 P2
Expected Output:
Q4-2006 160 P1
Q1-2007 10 P1
Q2-2007 10 P1
Q3-2007 870 P1
Q4-2007 50 P1
Q1-2008 60 P1
Q2-2008 60 P1
Q3-2008 60 P1
Q4-2008 60 P1
Q4-2006 260 P2
Q1-2007 20 P2
Q2-2007 20 P2
Q3-2007 970 P2
Q4-2007 60 P2
Q1-2008 70 P2
Q2-2008 70 P2
Q3-2008 70 P2
Q4-2008 70 P2
My Query:
SELECT quarter,product,
CASE
WHEN qtr > TRUNC(SYSDATE, 'q')
THEN LAST_VALUE(sum_config IGNORE NULLS) OVER(ORDER BY qtr)
ELSE sum_config
END sum_config
FROM (SELECT qtr, q.qtrstr quarter,product, SUM(qt.config) sum_config
FROM (SELECT 'Q' || TO_CHAR(qtr, 'q-yyyy') qtrstr, qtr
FROM (SELECT ADD_MONTHS(ADD_MONTHS(TRUNC(SYSDATE, 'q'), -13), 3 *(LEVEL - 1)) qtr
FROM DUAL
CONNECT BY LEVEL <= 9)
ORDER BY qtr) q,
quarter_test3 qt
WHERE qt.quarter(+) = q.qtrstr
GROUP BY qtr,product, q.qtrstr)
ORDER BY substr(qtr,-4),substr(QTR,2,1)
Output:
QUARTER PRODUCT SUM_CONFIG
Q4-2006 P1 160
Q4-2006 P2 997
Q4-2007 P1 50
Q4-2007 P2 60
Q4-2008 70
Q2-2007 P1 10
Q2-2007 P2 20
Q2-2008 70
Q3-2007 P1 870
Q3-2007 P2 970
Q3-2008 70
QUARTER PRODUCT SUM_CONFIG
Q1-2007 P1 10
Q1-2007 P2 20
Q1-2008 P1 70
Q1-2008 P2 70
The query had not generated q2-2008,q3-2008,q4-2008 values [60]for P1...it had only generated q2-2008,q3-2008,q4-2008 values[70] for product P2.
Can you please advise me.You can make up the data using the model clause:
SQL> create table quarter_test3 (quarter, config, product)
2 as
3 select 'Q1-2007', 10, 'P1' from dual union all
4 select 'Q2-2007', 10, 'P1' from dual union all
5 select 'Q3-2007', 870, 'P1' from dual union all
6 select 'Q4-2007', 50, 'P1' from dual union all
7 select 'Q1-2008', 60, 'P1' from dual union all
8 select 'Q4-2006', 160, 'P1' from dual union all
9 select 'Q4-2006', 997, 'P2' from dual union all
10 select 'Q1-2007', 60, 'P2' from dual union all
11 select 'Q2-2007', 970, 'P2' from dual union all
12 select 'Q3-2007', 20, 'P2' from dual union all
13 select 'Q4-2007', 20, 'P2' from dual union all
14 select 'Q1-2008', 70, 'P2' from dual
15 /
Tabel is aangemaakt.
SQL> select 'Q' || to_char(mod(q,4) + 1) || '-' || to_char(trunc(q/4)) quarter
2 , config
3 , product
4 from quarter_test3
5 model
6 partition by (product)
7 dimension by (to_number(substr(quarter,4))*4 + to_number(substr(quarter,2,1)) - 1 q)
8 measures (config)
9 rules
10 ( config[for q from 2006*4 + 3 to 2008*4 + 3 increment 1]
11 = nvl(config[cv()],config[cv()-1])
12 )
13 order by product
14 , q
15 /
QUARTER CONFIG PR
Q4-2006 160 P1
Q1-2007 10 P1
Q2-2007 10 P1
Q3-2007 870 P1
Q4-2007 50 P1
Q1-2008 60 P1
Q2-2008 60 P1
Q3-2008 60 P1
Q4-2008 60 P1
Q4-2006 997 P2
Q1-2007 60 P2
Q2-2007 970 P2
Q3-2007 20 P2
Q4-2007 20 P2
Q1-2008 70 P2
Q2-2008 70 P2
Q3-2008 70 P2
Q4-2008 70 P2
18 rijen zijn geselecteerd.Regards,
Rob. -
Very Odd Problem connecting to network please help
Ok so I have had my Macbook Pro for a while and I have both an Airport Extreme and an Airport Express in my room. So until recently I could turn on my computer and my Airport would automatically connect to the internet. Now recently I turn on or open my computer and I can still see my network but I cannot connect to it. I have restarted all the devices and my computer, but the only thing that eventually logs me on (after anywhere between 5 minutes - an hour) is waiting. But the second I close my laptop I will get booted off the Internet and I cannot connect again.
However I can still see the network I just cannot connect to it.
Also another problem I have noticed is that when in Network Setup Assistant it asks me for the password for the network, and I have entered this password many times in my life for my iPhone and for my other devices. And yet recently when I input the correct password (ive tried over 100 times) I get a message saying that the password is incorrect, when I know for a fact that I am putting the right password in.
If anyone could please help me I would be very grateful.The Airport Extreme base station has 2 passwords, one for logging into the router, the other for your network access (assuming you have security switched on). Just make sure you are trying to enter the correct password (I know this sounds obvious and no offense is meant).
If you added the Extreme to your other router, make sure in Airport utility the Extreme is set to Bridge Mode, this will remove any incompatibility issues with 2 devices trying to obtain IP addresses from your ISP. Only one router should connect to your ISP, using password, username and relevant settings, the other is a bridge for your internal network allowing faster transfers between devices connected to say for example your extreme.
I have a Netgear DG834PN modem/router which is assigned control to connect to my ISP (as it is a modem, the Extreme Base Station isn't a modem). The Apple Extreme is connected through ethernet to the Netgear. I have all my 802.11g/b/a devices connected through the Netgear wireless network (2.4Ghz) and all my 802.11n devices connected through the Apple Extreme Base Station wireless network ('n' only @5Ghz). I also have my Mac Pro and my AppleTV connected through gigabit ethernet (through the Extreme ethernet). Everything works well. AppleTV and Mac Pro sync very quickly, my MacBook Pro connects to other computers or devices (AppleTV for streaming content) within the Apple Extreme network, wired or wireless, and allows fast transfer speeds, especially with no g/b/a devices slowing things up.
I also have a USB hub connected to the Extreme with USB printer attached and additional external storage connected, both available throughout the Extreme network to either wired or wireless devices.
It sounds a bit complicated but it is really easy to do.
Maybe you are looking for
-
Spark.effects.Fade and effectEnd (Gumbo)
Hello all, I'm sure this is going to be a really daft question and I'll slap my head when someone points me in the right direction, but I can't seem to figure it out... Basically I'm trying to use the spark.effects.Fade class on a sprite that I have
-
I always get the "subscribe screen". I have a Dell Laptop with Windows 7 and I use Chrome as my browser.
-
Exchange 2003 to 2010 Migration and Certificate Issue
Good Day All - This is my first post on here, so if I post to the wrong spot or something is incorrect, please forgive and redirect me. I have a small working knowledge of Exchange and even less about Certificates. I did an Exchange 2003 to Exchange
-
Hr Fi Payroll Comperision Report
Hi all, I want to generate on report for payroll which show given field. can anybody help me with it. i want to know is there any standerd report available? if NO then which table or cluster i should use?? GL Acnt Wage type Hr Doc no FI doc no
-
Having problems with exporting i movie. I had no problems before. I wonder if Maverick which I downloaded recently has anything to do.