RE: writing "recursive SQL"

  • From: "Jacques Kilchoer" <Jacques.Kilchoer@xxxxxxxxx>
  • To: <susanzlam@xxxxxxxxx>, <oracle-l@xxxxxxxxxxxxx>
  • Date: Thu, 9 Sep 2004 12:49:04 -0700

SQL> select * from mytable ;
        A         B
--------- ---------
        1         2
        2         3
        3         4
        4         5
        5         6
        0         7
        7         8
        8         9
8 ligne(s) sélectionnée(s).
SQL> select b
  2   from mytable
  3   connect by prior b = a
  4   start with a = 3 ;
        B
---------
        4
        5
        6

SQL> select b
  2   from mytable
  3   connect by prior b = a
  4   start with a = 7 ;
        B
---------
        8
        9
SQL> 

-----Original Message-----
From: oracle-l-bounce@xxxxxxxxxxxxx [mailto:oracle-l-bounce@xxxxxxxxxxxxx] On 
Behalf Of susan lam
...
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

...


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

Other related posts: