DB2 Version 9.7 for Linux, UNIX, and Windows

SYS_CONNECT_BY_PATH scalar function

The SYS_CONNECT_BY_PATH function (in the SYSIBM schema) is used in hierarchical queries to build a string representing a path from the root row to this row.

Read syntax diagramSkip visual syntax diagram
>>-SYS_CONNECT_BY_PATH--(--string-expression1--,--string-expression2--)-><

The string for a given row at LEVEL n is built as follows:
  • Step 1 (using the values of the root row from the first intermediate result table H1):
    path1 := string-expression2 || string-expression1
  • Step n (based on the row from the intermediate result table Hn):
    pathn := pathn-1 || string-expression2 || string-expression1
string-expression1
A character string expression that identifies the row. The expression must not include a NEXT VALUE expression for a sequence (SQLSTATE 428F9), any hierarchical query construct, such as the LEVEL pseudocolumn or the CONNECT_BY_ROOT operator (SQLSTATE 428H4), an OLAP function, or an aggregate function (SQLSTATE 428H4).
string-expression2
A constant string that serves as a separator. The expression must not include a NEXT VALUE expression for a sequence (SQLSTATE 428F9), any hierarchical query construct, such as the LEVEL pseudocolumn or the CONNECT_BY_ROOT operator (SQLSTATE 428H4), an OLAP function, or an aggregate function (SQLSTATE 428H4).

The result is a varying-length character string. The length attribute of the result data type is the greater of 1000 and the length attribute of string-expression1.

Rules:

Example: