Need help: CONNECT by PRIOR query in ora10g
Hi All,
Recently we have migrated the DB from 9i to 10g.
we used to have many rule based queries in 9i
and all are changed based on 10g.
All the queries that have CONNECT BY PRIOR
conditions seems to behave in wrong manner.
( same query in 9i,fetches less number of records where as 10g there were many
rows displayed eventhough it was not selected in where clause.- as per business logic )
After changing the below parameter setting , the problem was solved.
can you tell wts the below setting would do? by doing so , ur again making 10g
to behave like 9i so that full benefit of 10g is not used ?
Alter session set “_optimizer_connect_by_cost_based”=false
Hi, try this:
WITH t AS (
SELECT 100 AS node_id, cast(NULL AS NUMBER) AS parent_node_id FROM dual UNION ALL
SELECT 101 AS node_id, 100 AS parent_node_id FROM dual UNION ALL
SELECT 102 AS node_id, 100 AS parent_node_id FROM dual UNION ALL
SELECT 1021 AS node_id, 102 AS parent_node_id FROM dual UNION ALL
SELECT 1022 AS node_id, 102 AS parent_node_id FROM dual UNION ALL
SELECT 10221 AS node_id, 1022 AS parent_node_id FROM dual UNION ALL
SELECT 10222 AS node_id, 1022 AS parent_node_id FROM dual
SELECT DISTINCT CONNECT_BY_ROOT parent_node_id AS ID, node_id AS id1
FROM t
CONNECT BY t.node_id = PRIOR parent_node_id
START WITH parent_node_id = 1022
ORDER BY 1, 2;
Similar Messages
-
I want to help connect by prior query
table structure
node_id parent_node_id
=======================
100
101 100
102 100
1021 102
1022 102
10221 1022
10222 1022
above example tree like-
100
101
102
1021
1022
10221
10222
i want to output like(if input 1022)
id id1
1022 100
1022 102
1022 1022
1022 10221
1022 10222
create table node_temp(node_id number,parent_node_id number)
insert into node_temp(node_id) values(100);
insert into node_temp(node_id,parent_node_id) values(101,100);
insert into node_temp(node_id,parent_node_id) values(102,100);
insert into node_temp(node_id,parent_node_id) values(1021,102);
insert into node_temp(node_id,parent_node_id) values(1022,102);
insert into node_temp(node_id,parent_node_id) values(10221,1022);
insert into node_temp(node_id,parent_node_id) values(10222,1022);
Edited by: 855516 on Feb 1, 2013 1:46 PMHi, try this:
WITH t AS (
SELECT 100 AS node_id, cast(NULL AS NUMBER) AS parent_node_id FROM dual UNION ALL
SELECT 101 AS node_id, 100 AS parent_node_id FROM dual UNION ALL
SELECT 102 AS node_id, 100 AS parent_node_id FROM dual UNION ALL
SELECT 1021 AS node_id, 102 AS parent_node_id FROM dual UNION ALL
SELECT 1022 AS node_id, 102 AS parent_node_id FROM dual UNION ALL
SELECT 10221 AS node_id, 1022 AS parent_node_id FROM dual UNION ALL
SELECT 10222 AS node_id, 1022 AS parent_node_id FROM dual
SELECT DISTINCT CONNECT_BY_ROOT parent_node_id AS ID, node_id AS id1
FROM t
CONNECT BY t.node_id = PRIOR parent_node_id
START WITH parent_node_id = 1022
ORDER BY 1, 2; -
Complex connect by prior query
I need SQL(for hierarchical tree) for a function which accepts node as input parameter and returns ref cursor.
Following is a sample tree:
1
--2.1
----3.1
------4.1
--------5.1
----------6.1
----------6.2
----3.2
------4.2
--------5.2
--2.2
----3.2
------4.2
--------5.2
----3.3
----3.4
------4.1
--------5.1
----------6.1
----------6.2
1 is at the root level and 2.1 & 2.2 are immediate children and so on.
The output tree should be all related parents and children of the passed node.
e.g:
If the input is 4.1, the output tree will be:
1
--2.1
----3.1
------4.1
--------5.1
----------6.1
----------6.2
--2.2
----3.4
------4.1
--------5.1
----------6.1
----------6.2
If the input is 4.2, the output tree will be:
1
--2.1
----3.2
------4.2
--------5.2
--2.2
----3.2
------4.2
--------5.2
The complex part, I guess, is to remove unwanted(not related) branches from the tree.
Following is the representation of the table RELATIONSHIP
ID PARENT CHILD
1-------1-------2.1
2-------1-------2.2
3-------2.1-----3.1
4-------2.1-----3.2
5-------2.2-----3.2
6-------2.2-----3.3
7-------2.2-----3.4
8-------3.1-----4.1
9-------3.2-----4.2
10------3.4-----4.1
11------4.1-----5.1
12------4.2-----5.2
13------5.1-----6.1
14------5.1-----6.2
Pls. help me out to form this CONNECT BY PRIOR query.
Thanks in advance.make sure you include 2 things in your queries.
# the row number
# the level
for traversing up the tree set
level = 0 - level and
row_number = 0 - row_number.
you than can then do an order by row_number if you union the two queries
for example:
============
select tbl.child,
tbl.parent,
level lvl,
rownum rn
from some_table tbl
start with tbl.parent = 4.1
connect by prior tbl.child = tbl.parent
union
select tbl.child,
tbl.parent,
0 - level lvl,
0 - rownum rn
from some_table tbl
start with tbl.child = 4.1
connect by prior tbl.parent = tbl.child
order by rn asc -
Strange Behaviour of Connect By Prior query
Has anybody faced a problem like your query returns alternative record like suppose you have 10 records in a table and your connect by prior query gives you 1st, 3rd, 5th and so on. My query was working fine few days back but suddenly its giving me different result. I don't know whether there was some settings changed by someone or not.
Can't guess anything from here. You need to post the query, sample data and the result.
-
Need help connecting a windows network printer to my Mac (Xerox Phaser 3600) over a windows home network.
My Mac runs lion and the windows desktop runs Windows XP
I have tried for a few hours or so to connect my mac to this printer over a home network.
For your information it does work when connected directly to my mac using a USB Cable.
If there is no soultion could I have help getting the drivers for a Dell All-in-One Photo 926In most cases you can connect to the Windows shared printer from the Mac. But there is a dependence on the Mac driver being compatible. For many consumer inkjets, the vendor created driver cannot be used for this type of connection so you need to look at alternative drivers, such as Gutenprint or PrintFab. If you can tell us which brand and model of printer you have shared from Windows then we can answer your question with the preferred procedure on the Mac.
-
Issue with the below query. The query is not getting filtered for the condition hier_typ_c in('BS') with the connect by prior
query. query is fetching all the hier_type_c in the table like 'BS', 'CO', 'EC' etc....
Just wondering how do i restrict the query just to fetch the type_c ='BS' alone? why is it giving all the records??
Select
Level as LEVEL_CODE,
h.HIER_PRNT_NODE_I as PARENT,
h.HIER_CHLD_NODE_I as CHILD,
h.HIER_CHLD_NODE_X || ' (' || h.HIER_CHLD_NODE_I || ')' as ALIAS
From (Select Distinct HIER_CHLD_NODE_I, HIER_PRNT_NODE_I,
HIER_CHLD_NODE_X from .HIER_DIMN
where hier_typ_c in('BS') and CURR_VER_C = 'Y') h
Start with h.HIER_PRNT_NODE_I = 'ROOT'
Connect by prior
h.HIER_CHLD_NODE_I = h.HIER_PRNT_NODE_I
Order by LEVEL_CODE, parent, childHi
It loks like you're doing it right.
By basing the CONNECT BY query on a sub-query that has this WHERE clasue:
where hier_typ_c in('BS') and CURR_VER_C = 'Y') hyou should exclude not only nodes whose hier_typ_c is not 'BS', but also their descendants.
Post some sample data (CREATE TABLE and INSERT statements) and the results you want from that data.
Are you sure the query you posted is what you're actually running?
I would expect the sub-query FROM clause to cause an error because of the '.'.
from .HIER_DIMNEdited by: Frank Kulash on Sep 29, 2009 11:16 AM -
Need help connecting my iPhone 6 to my MacBook Pro to stream the internet
Need help connecting my iPhone 6 to my MacBook Pro to stream the internet
Turn on Personal Hotspot on your iPhone, select WiFi, set a password. Then select your hotspot on your MacBook Pro and sign in.
-
I need help connecting to my WiFi. I purchased a new router and am having trouble connecting.
your gonna want to contact your internet service provider for the best info on setting that router up. but for connecting to wifi on the iphone, ipad, and ipod
go to
settings > wifi
then choose your connection and enter the password -
Need help connecting to my home Wireless Network
I need help connecting my LaserJer M1212nf MFP to my home wirless network. I would like to use Apple's AirPrint, and be able to print from my iPad.
I've spent a few hours following the directions I found on the manuals through hp.com and I've had no luck. I've already unistalled and reinstalled the printer. I've also updated the firmware. If anyone can provide assistance I would greatly appreciate it. Thank you!This is NOT a wireless printer (see product spec: http://www.shopping.hp.com/shopping/pdf/ce841a.pdf), you can NOT add the printer to the wireless network. This printer do support LAN connection, so if your wireless router has LAN ports, you can added it to your home network by connecting a network cable from the printer to a LAN port on the router. You need then reinstall the printer as a network printer, to use airprint.
======================================================================================
* I am an HP employee. *
** Make it easier for other people to find solutions, by marking my answer with "Accept as Solution" if it solves your issue. **
***Click on White “Kudos” STAR to say thanks!*** -
I need help connecting my iPhone and computer together.
I need help connecting my iPhone to computer
Howdy sprinklemk,
Welcome to Apple Support Communities.
Take a look at the iPhone User Guide, it answers your question about how to connect your iPhone to your computer and provides additional information that you may find helpful.
http://manuals.info.apple.com/MANUALS/1000/MA1565/en_US/iphone_user_guide.pdf
You may need to connect iPhone to your computer in order to complete activation. Connecting iPhone to your computer also lets you sync photos and other content to iPhone from your computer, using iTunes. See Sync with iTunes on page 18.
To use iPhone with your computer, you need:
An Internet connection for your computer (broadband is recommended)
A Mac or a PC with a USB 2.0 or 3.0 port, and one of the following operating systems:
OS X version 10.6.8 or later
Windows 8, Windows 7, Windows Vista, or Windows XP Home or Professional with Service Pack 3 or later
Connect iPhone to your computer. Use the Lightning to USB Cable (iPhone 5 or later) or 30-pin the other device.
Cheers,
-Jason -
Need help Connecting Crystal Reports 8.5 with GBS Agency Expert 6.7.6c
Need help Connecting Crystal Reports 8.5 with GBS Agency Expert 6.7.6c. I need assistance on connecting these together so I can run a report. I am not an IT person so if someone could dumb it down it would be great.
Thanks,
NBGHealthHello,
I assume GBS Agency Expert 6.7.6c is some sort of database or data source? If you have an ODBC driver then create or use a System DSN to the database. Then you can create a report using that DSN.
Otherwise I suggest you contact the makers of GBS Agency Expert 6.7.6c and ask them how to connect to the database.
Let them know CR is ANSII 92 ODBC 3 compliant.
Thank you
Don -
Help needed with CONNECT BY PRIOR
I need to display salesrep-manager hierarchy. I'm using the following SQL and am sure I'm doing something wrong somewhere, but just can't pinpoint. Any help is greatly appreciated.
<pre>
SELECT sf.source_name salesrep
,mgr.full_name manager
,level
FROM as_salesforce_v sf
,per_all_assignments_f pass
,per_all_people_f mgr
WHERE sf.role_name = 'Sales Representative'
AND SYSDATE BETWEEN nvl(sf.start_date_active, SYSDATE) AND
nvl(sf.end_date_active, SYSDATE)
AND SYSDATE BETWEEN nvl(pass.effective_start_date, SYSDATE) AND
nvl(pass.effective_end_date, SYSDATE)
AND SYSDATE BETWEEN nvl(mgr.effective_start_date, SYSDATE) AND
nvl(mgr.effective_end_date, SYSDATE)
CONNECT BY PRIOR mgr.person_id = pass.supervisor_id
START WITH pass.person_id = sf.employee_person_id;
</pre>
TIA
Alka.
Forgot to mention, the SQL takes forever to run.
Message was edited by:
user498444as_salesforce_v view stores the salesrep name (as specified by the condition sf.role_name = 'Sales Representative'). This view also has rows for managers of salesreps as that's how Oracle Sales app allows the users to access the app. This table stores employee id in column employee_person_id.
per_all_assignments_f table stores the assignments for all the employees (including salesreps and that's why condition START WITH pass.person_id = sf.employee_person_id). It also stores the employee id for the manager (column supervisor_id).
per_all_people_f has all the employee records (including manager records) and the column person_id is the employee id (condition pass.supervisor_id = mgr.person_id).
Hope this explanation is helpful. -
Hi Friends,
I am trying to load Employees and their Assignments using APIs.
I have various columns in my staging table like Last Name, First Name, etc., but I need help in writing query in the cursor especially for columns Emp Number and Supervisor Number.
I have data as below
Emp_Number Supervisor_Number
GE0002 GE0064
GE0064 EG0009
EG0009 EG0001
100009 EG0001
EG0001 TU0001
Cursor I write will process the data in the same order as above, but here the problem is...
When it processes first row, it checks for supervisor GE0064 which do not exist and so it errors out.
Similarly for second row, it checks for supervisor EG0009 which again do not exist and so it errors out.
So in order to prevent this, the cursor should process the rows as below
Emp_Number Supervisor_Number
EG0001 TU0001
EG0009 EG0001
GE0064 EG0009
GE0002 GE0064
100009 EG0001
By this way, Supervisor should be defined first as an employee and then it can be used as a supervisor for other employees
is there a way that I can get the output as above(second set of data), when the table has records randomly as above(first set of data)
Appreciate your help!
Thanks,
SrikanthSrikanth wrote:
... but the number of records returned by above query are lot more than number of records in the table.
Why did the number go up?
It's something only you can find out
Maybe some Emp have several Supervisor(s) like
with
t as
(select 'GE0002' Emp,'GE0064' Supervisor from dual union all
select 'GE0064','EG0009' from dual union all
select 'EG0009','EG0001' from dual union all
select 'GE0064','100009' from dual union all
select '100009','EG0001' from dual union all
select 'EG0001','TU0001' from dual
select Emp,Supervisor,lpad('_',3 * (level - 1),'_')||Emp indent
from (select Emp,Supervisor
from t
union all
select supervisor,null
from t tt
where not exists(select null
from t
where emp = tt.supervisor
start with Supervisor is null
connect by prior Emp = Supervisor
EMP
SUPERVISOR
INDENT
TU0001
TU0001
EG0001
TU0001
___EG0001
100009
EG0001
______100009
GE0064
100009
_________GE0064
GE0002
GE0064
____________GE0002
EG0009
EG0001
______EG0009
GE0064
EG0009
_________GE0064
GE0002
GE0064
____________GE0002
Regards
Etbin -
Need help in writing the query
The initial data is as follows:
ID PARENT_ID
=============
1 NULL
2 NULL
3 2
4 6
5 3
6 7
7 4
8 NULL
but output is as follows in such way that Parent_Id should be displayed in ID place
ID PARENT_ID
=============
1 NULL
2 NULL
3 2
8 NULL
6 8
4 6
5 3
7 4
Can any one help how resolve this query?
Thanks in advanceYour output is inconsistent with initial data :) But
select * from t start with parent_id is null connect by parent_id = prior id; -
Need help connecting Audigy 2 ZS Platinum Pro to ATI All-in-wonder 9600XT to get sound from tv tu
Recently purchased an Audigy 2 ZS?Platinum?Pro sound card. I need help figuring out how to get sound when I us the tv tuner for my?All-In-Wonder?9600XT video card. The audio output on the video card needs an audio input to connect on the sound card, but this sound card?does not appear have one.
Does anyone know how I can connect the video card to sound card so I get sound when using tv tuner? Where is the micro In line?I have it on the front panel on the external unit!!? But I would don't use this In line for this application!On my old sound card SB Li've! Platinum, I had a line at the rear PCI card (Line In & Micro Line In) and I had two others Line In on the Front Panel, It's the best, but this old card work only with Win 98 or Win 2000.... ? My new system have WinXP Pro!!!!I buy a new SB card (Audigy 2 ZS Platinum pro), but How to get sound fromo the TV tuner and what's the best setup for my micro (for MSN, Skype) ??Help will be greatly appreciated.Anybody wants to help me ?I wait your answer for my question...!
Thanks
Maybe you are looking for
-
Mini DisplayPort to VGA adapter not working under Vista (Boot Camp).
Hi there, I'm facing a very serious issue with MacBook Pro Unibody running MS Vista under Boot Camp: using the Mini DisplayPort to VGA adapter to hook a projector is 95% impossible because the only resolution available is 640x480 or sometimes 800x600
-
Error 1 when loading external data Message no. RSAR234 Diagonosis: Error number 1 occured when loading external data 1)Error when reading the file(access rights, file name...) 2)Error when generating the IDOC Can anyone tell what the error is regardi
-
I am trying to find out the Que position of a person in waiting Q. These are the steps I am following: 1. getting the record set <sql:query var="myRecordset" dataSource="$myDataBase " > SELECT myName FROM WaitingList ORDER BY registerationDate </sql:
-
Reading 'pdf' attachments to Outlook Express Email
I can't read 'pdf' attachments to my Outlook Express mail. I get an Error Message "This message does not have a program associated with it" However, I can save the message to my computer 'My Documents' and it then opens fine with Adobe Reader. Adobe
-
hi, can anyone tell me where i can leave comments for fixes in future versions of aperture? thanks aidan