The PRIOR unary operator is for use only in the CONNECT BY clause of hierarchical queries (SQLSTATE 428H4).
The CONNECT BY clause performs an inner join between the intermediate result table Hn of the hierarchical query and the source result table specified in the FROM clause. All column references to tables that are referenced in the FROM clause, and which are arguments to the PRIOR operator, are considered to be ranging over Hn.
CONNECT BY PRIOR T.PK = T.FK
If
the primary key is a composite key, care must be taken to prefix each
column with PRIOR: CONNECT BY PRIOR T.PK1 = T.FK1 AND PRIOR T.PK2 = T.FK2
The result data type of the operator is the result data type of the expression.
Notes:
PRIOR FIRSTNME || LASTNAME
returns
the FIRSTNME value of the prior row concatenated with the LASTNAME
value of the actual row in the hierarchy, because this expression
is equivalent to: (PRIOR FIRSTNME) || LASTNAME
rather
than: PRIOR (FIRSTNME || LASTNAME)
Example:
SELECT LEVEL, DEPTNAME
FROM DEPARTMENT START WITH DEPTNO = 'A00'
CONNECT BY NOCYCLE PRIOR DEPTNO = ADMRDEPT
This
query returns:LEVEL DEPTNAME
----------- ----------------------------------------
1 SPIFFY COMPUTER SERVICE DIV.
2 PLANNING
2 INFORMATION CENTER
2 DEVELOPMENT CENTER
3 MANUFACTURING SYSTEMS
3 ADMINISTRATION SYSTEMS
2 SUPPORT SERVICES
3 OPERATIONS
3 SOFTWARE SUPPORT
3 BRANCH OFFICE F2
3 BRANCH OFFICE G2
3 BRANCH OFFICE H2
3 BRANCH OFFICE I2
3 BRANCH OFFICE J2