Get the App
SLTechnology News&Howtos  ›  Database  › 

Oralce recursive query

Shulou Source: shulou.com Published: 2022-06-01 09:13:32 10月02日 Update

1. The basic syntax is: select... From where start with connect by; / /: filter condition, which is used to filter all returned records. / /: the qualification for re-starting the root node of the query result. /: join condition / / if prior in connect by prior is omitted, the query will not do deep recursion. two。 Query the current menu and all parent menus select t.* from s_menu t start with t.menu 510 'connect by prior t.fid = t.id3. Query up all superior menus (excluding the current menu) select t. * from s_menu t start with t. Connect by prior t.fid 510 'menu = t.id4. Query down the current menu and all subordinate menus select t. * from s_menu t start with t. Connect by prior t. Id = t.fid 5. Query down all subordinate menus (excluding the current menu) select t. * from s_menu t start with t. Connect by prior t. Id = t.fid6. Query the recursive path select t. Idret t. Namedepartment fiddirection substr (sys_connect_by_path (NAME,'- >'), 3) menu_pathfrom s_menu t start with t.name = 'system function' connect by prior t.id = t.fid order by t.id7. Hierarchical display of select t.idrpad LPad ('-', (level-1) * 4 ID'| -') | | lpad ('", 2) | | t.name | | rpad ('", 2) the key to upward and downward recursion is the last condition. If the parent ID equals ID, it recurses upward, and vice versa.

Reference: http://www.cnblogs.com/wanghonghu/archive/2012/08/31/2665945.html

Tags: Menu query recursion condition superior subordinate key function that is hierarchical deep system result node grammar path reference start Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno NVidia Redmi Shulou Technology Shulou Information MySQL