PRIOR is an Oracle-specific keyword used only inside a CONNECT BY clause to build hierarchical result sets. It tells the optimizer which side of the comparison refers to the parent row and which side refers to the child row. By marking one column with PRIOR, Oracle can traverse self-referencing tables (such as employee-manager or folder-subfolder structures) and return rows in depth-first order while automatically populating the pseudo-columns LEVEL, CONNECT_BY_ISCYCLE, and CONNECT_BY_ROOT. PRIOR does not change data; it only influences how rows are matched during recursive evaluation. The keyword can appear on either side of the comparison, letting you control parent-to-child or child-to-parent navigation. Outside CONNECT BY, PRIOR has no meaning and will raise a syntax error.
CONNECT BY, START WITH, LEVEL pseudo-column, recursive common table expression (WITH RECURSIVE), CONNECT_BY_ISCYCLE, CONNECT_BY_ROOT
Oracle7 (1992)
PRIOR tells Oracle which column in the CONNECT BY comparison belongs to the parent row, enabling hierarchical traversal.
No. PostgreSQL, MySQL, SQL Server, and SQLite do not recognize PRIOR. Use recursive CTEs instead.
Yes. Without at least one PRIOR, Oracle cannot distinguish parent from child rows and raises ORA-01436.
Absolutely. Place PRIOR on the column that belongs to the parent row to control traversal direction.