niXforums Forum Index
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   PreferencesPreferences   Log in to check your private messagesLog in to check your private messages   Log inLog in 
·  nixdoc.net ·  man pages ·  Linux HOWTOs ·  FreeBSD Tips ·  Forums
navigation Forum index » Databases » Oracle » Server
recursive query
Post new topic   Reply to topic Page 1 of 1 [2 Posts] View previous topic :: View next topic
Author Message
Jürg Schaufelberger
*nix forums beginner


Joined: 15 Sep 2005
Posts: 4

PostPosted: Thu Jul 20, 2006 6:06 pm    Post subject: recursive query Reply with quote

Hello ng

A table RECHTGRUNDSTUECK has the following structure:
FID number(10)
FID_BETROFFENESGRUNDSTUECK number(10)
(foreign key of the parent node)
FID_BERECHTIGTESGRUNDSTUECK number(10)
(foreign key of the child)
..
..

Why does the following query only list the first level of the tree ? I
want to list the FID of the root-node and all the leaves. The nodes
between the root and the leaves aren't interesting.

SELECT
RG0.FID_BETROFFENESGRUNDSTUECK, RG0.FID_BERECHTIGTESGRUNDSTUECK
FROM RECHTGRUNDSTUECK RG0
START WITH FID_BETROFFENESGRUNDSTUECK = 534
CONNECT BY PRIOR
FID_BERECHTIGTESGRUNDSTUECK = FID_BETROFFENESGRUNDSTUECK


Oracle Version 9.2
Thanks for any help

Jürg
Back to top
Charles Hooper
*nix forums addict


Joined: 09 Jul 2006
Posts: 51

PostPosted: Thu Jul 20, 2006 10:05 pm    Post subject: Re: recursive query Reply with quote

Jürg Schaufelberger wrote:
Quote:
Hello ng

A table RECHTGRUNDSTUECK has the following structure:
FID number(10)
FID_BETROFFENESGRUNDSTUECK number(10)
(foreign key of the parent node)
FID_BERECHTIGTESGRUNDSTUECK number(10)
(foreign key of the child)
.
.

Why does the following query only list the first level of the tree ? I
want to list the FID of the root-node and all the leaves. The nodes
between the root and the leaves aren't interesting.

SELECT
RG0.FID_BETROFFENESGRUNDSTUECK, RG0.FID_BERECHTIGTESGRUNDSTUECK
FROM RECHTGRUNDSTUECK RG0
START WITH FID_BETROFFENESGRUNDSTUECK = 534
CONNECT BY PRIOR
FID_BERECHTIGTESGRUNDSTUECK = FID_BETROFFENESGRUNDSTUECK


Oracle Version 9.2
Thanks for any help

Jürg

I am having a bit of difficulty reading your example. Here is a simple
example from my database. The ACCOUNT table contains a hierarchy:
ID (primary key ID column) and the parent of this ID (PARENT_ACCT_ID
column). If I want to build a hierarchy for this table, I would create
a SQL statement like this (0000 is the root or top PARENT_ACCT_ID for
the table):
SELECT
PARENT_ACCT_ID,
ID,
LEVEL
FROM
ACCOUNT
CONNECT BY PRIOR
ID=PARENT_ACCT_ID
START WITH
PARENT_ACCT_ID='0000';

This produces 509 rows in the result.

If I make a mistake with the connect by prior:
CONNECT BY PRIOR
PARENT_ACCT_ID=ID
START WITH
PARENT_ACCT_ID='0000';

I see only 4 rows in the result. This seems to be somewhat consistent
with your result. Try reversing the order of the columns in the
CONNECT BY PRIOR clause to see if this corrects the problem that you
are experiencing.

Charles Hooper
PC Support Specialist
K&M Machine-Fabricating, Inc.
Back to top
Google

Back to top
Display posts from previous:   
Post new topic   Reply to topic Page 1 of 1 [2 Posts] View previous topic :: View next topic
The time now is Mon Dec 01, 2008 8:32 pm | All times are GMT
navigation Forum index » Databases » Oracle » Server
Jump to:  

Similar Topics
Topic Author Forum Replies Last Post
No new posts Very slow query Michael Sutter MySQL 0 Fri Jul 21, 2006 1:10 pm
No new posts Column info without executing query Dan Strömberg PostgreSQL 10 Thu Jul 20, 2006 6:21 pm
No new posts How to query on part of a date column? Barry Newton MySQL 4 Thu Jul 20, 2006 5:02 pm
No new posts Invalid syntax with STD() function when more than one fie... William Bronsema MySQL 1 Thu Jul 20, 2006 2:18 pm
No new posts Query for file names like SC* dmeiser IBM DB2 1 Thu Jul 20, 2006 12:04 pm

Mobile Phone | Israel Perry | Mortgage Calculator | Secured Loans | Credit Cards
Copyright © 2004-2005 DeniX Solutions SRL
 
Other DeniX Solutions sites: Unix/Linux blog |  electronics forum |  medicine forum |  science forum | 
Privacy Policy


Powered by phpBB © 2001, 2005 phpBB Group
[ Time: 0.1951s ][ Queries: 16 (0.1187s) ][ GZIP on - Debug on ]