Inner join
stepbystep s
ON (
s.node = r.parent )
)
SEARCH DEPTH
FIRST BY node DESC SET orderval
SELECT way,
distance, orderval
FROM
stepbystep
ORDER BY orderval
DESC
/
Ответ:
WAY
DISTANCE ORDERVAL
----------------------------------------
---------- ----------
Москва-Ленинград-Выборг
831 5
Москва-Ленинград
696 4
Москва-Новгород-Ленинград-Выборг
852 3
Москва-Новгород-Ленинград
717 2
Москва-Новгород
538 1
Подробности и прочие
свойства построений указания SEARCH
приведены в документации по Oracle.
Single-Row Functions - sys connect by path
Page
Discussion
View source
History
SYS_CONNECT_BY_PATH
is valid only in hierarchical queries. It returns the path of a
column value from root to node, with column values separated by char
for each row returned by CONNECT BY condition.
Both column and
char can be any of the datatypes CHAR, VARCHAR2, NCHAR, or NVARCHAR2.
The string returned is of VARCHAR2 datatype and is in the same
character set as column.
Syntax
>─SYS_CONNECT_BY_PATH──(column
, char)──><
SQL Example
The following
example returns the path of employee names from employee Kochhar to
all employees of Kochhar (and their employees):
01.SELECT LPAD('
', 2*level-1)||SYS_CONNECT_BY_PATH(last_name, '/') "Path"
02.FROM employees
03.START WITH
last_name = 'Kochhar'
04.CONNECT BY
PRIOR employee_id = manager_id;
05
06.Path
07.
---------------------------------------------------------------
08./Kochhar
09./Kochhar/Greenberg
10./Kochhar/Greenberg/Faviet
11./Kochhar/Greenberg/Chen
12./Kochhar/Greenberg/Sciarra
13.
/Kochhar/Greenberg/Urman
14./Kochhar/Greenberg/Popp
15./Kochhar/Whalen
16./Kochhar/Marvis
17./Kochhar/Baer
18./Kochhar/Higgens
19./Kochhar/Higgens/Gietz
20.
21.12 rows
selected.