Oracle FAQ Your Portal to the Oracle Knowledge Grid
HOME | ASK QUESTION | ADD INFO | SEARCH | E-MAIL US
 

Home -> Community -> Mailing Lists -> Oracle-L -> RE: writing "recursive SQL"

RE: writing "recursive SQL"

From: Igor Neyman <ineyman_at_perceptron.com>
Date: Thu, 9 Sep 2004 15:39:25 -0400
Message-ID: <003001c496a4$b6723f00$0704a8c0@development.perceptron.com>


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

Igor Neyman, OCP DBA
ineyman_at_perceptron.com

-----Original Message-----

From: oracle-l-bounce_at_freelists.org
[mailto:oracle-l-bounce_at_freelists.org] On Behalf Of susan lam Sent: Thursday, September 09, 2004 2:27 PM To: oracle-l_at_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_at_freelists.org&subject=unsubscribe To search the archives - http://www.freelists.org/archives/oracle-l/

--

To unsubscribe - mailto:oracle-l-request_at_freelists.org&subject=unsubscribe To search the archives - http://www.freelists.org/archives/oracle-l/ Received on Thu Sep 09 2004 - 14:34:55 CDT

Original text of this message

HOME | ASK QUESTION | ADD INFO | SEARCH | E-MAIL US