From oracle-l-bounce@freelists.org  Thu Sep  9 14:34:55 2004
Return-Path: <oracle-l-bounce@freelists.org>
Received: from air189.startdedicated.com (root@localhost)
 by orafaq.com (8.11.6/8.11.6) with ESMTP id i89JYt913695
 for <oracle-l@orafaq.com>; Thu, 9 Sep 2004 14:34:55 -0500
X-ClientAddr: 206.53.239.180
Received: from turing.freelists.org (freelists-180.iquest.net [206.53.239.180])
 by air189.startdedicated.com (8.11.6/8.11.6) with ESMTP id i89JYtI13690
 for <oracle-l@orafaq.com>; Thu, 9 Sep 2004 14:34:55 -0500
Received: from localhost (localhost [127.0.0.1])
 by turing.freelists.org (Avenir Technologies Mail Multiplex) with ESMTP
 id C890E72CE71; Thu,  9 Sep 2004 14:36:30 -0500 (EST)
Received: from turing.freelists.org ([127.0.0.1])
 by localhost (turing [127.0.0.1]) (amavisd-new, port 10024) with ESMTP
 id 08334-65; Thu,  9 Sep 2004 14:36:30 -0500 (EST)
Received: from turing (localhost [127.0.0.1])
 by turing.freelists.org (Avenir Technologies Mail Multiplex) with ESMTP
 id 3881472D171; Thu,  9 Sep 2004 14:36:30 -0500 (EST)
From: "Igor Neyman" <ineyman@perceptron.com>
To: <susanzlam@yahoo.com>, <oracle-l@freelists.org>
Subject: RE: writing "recursive SQL"
Date: Thu, 9 Sep 2004 15:39:25 -0400
Message-ID: <003001c496a4$b6723f00$0704a8c0@development.perceptron.com>
MIME-Version: 1.0
Content-type: text/plain; charset=US-ASCII
Content-Transfer-Encoding: 8bit
In-Reply-To: <20040909192716.29904.qmail@web53302.mail.yahoo.com>
X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.2180
X-archive-position: 9330
X-ecartis-version: Ecartis v1.0.0
Sender: oracle-l-bounce@freelists.org
Errors-To: oracle-l-bounce@freelists.org
X-original-sender: ineyman@perceptron.com
Precedence: normal
Reply-To: ineyman@perceptron.com
X-list: oracle-l
X-Virus-Scanned: by amavisd-new at freelists.org

It's called hierachical query.
Check "connect by ... prior ... start with..." in SQL manual.

Igor Neyman, OCP DBA
ineyman@perceptron.com



-----Original Message-----
From: oracle-l-bounce@freelists.org
[mailto:oracle-l-bounce@freelists.org] On Behalf Of susan lam
Sent: Thursday, September 09, 2004 2:27 PM
To: oracle-l@freelists.org
Subject: writing "recursive SQL"

Hi,
I would like to write a SQL to recursively extract
data from a table. 

The algorithm is as follows:

SQL> select * from mytable;
        A          B
---------- ----------
         1          2
         2          3
         3          4
         4          5
         5          6
         0          7
         7          8
         8          9

8 rows selected.

If A=3, output the corresponding value of B (ie 4), 
then match B (ie 4) with A and output the next
corresponding value of B (ie 5) and so on...  
Recursion stops when B != A

A & B are unqiue and A=<value> is a user input value

The result I'm looking for is:

if A=3, then the output is:
4
5
6

if A=7, then the output is:
8 
9

Is there a way to accomplish that in SQL?


thanks.

susan


		
__________________________________
Do you Yahoo!?
Yahoo! Mail - You care about security. So do we.
http://promotions.yahoo.com/new_mail
--
To unsubscribe -
mailto:oracle-l-request@freelists.org&subject=unsubscribe 
To search the archives - http://www.freelists.org/archives/oracle-l/


--
To unsubscribe - mailto:oracle-l-request@freelists.org&subject=unsubscribe 
To search the archives - http://www.freelists.org/archives/oracle-l/

