1,查所有的子节点 select * from wz_tree start with id = 1 connect by prior id = pid;
2,查所有的父节点 select * from wz_tree start with id = 256 connect by prior pid = id;
3,查分类的路径, 用逗号连接:select sys_connect_by_path(mc, ',') from wz_tree start with id = 1 connect by prior id = pid; http://www.itpub.net/838127.html讲的很详细
4,查某个表的字段名:
select max(substr(SYS_CONNECT_BY_PATH(COLUMN_NAME, ','), 2)) col
from (select COLUMN_NAME, column_id
from user_tab_columns
where table_name = '&TEST')--&为plsqldeveloper里的字符串占位符,执行时会弹出对话框让你填值
start with column_id = 1
connect by column_id = rownum;
5,select * from wz_tree where mc like '%五金' start with id = 1 connect by prior id = pid;
和select * from wz_tree start with id = 1 connect by prior id = pid and mc like '%五金'
二者的查询结果不一样
2,查所有的父节点 select * from wz_tree start with id = 256 connect by prior pid = id;
3,查分类的路径, 用逗号连接:select sys_connect_by_path(mc, ',') from wz_tree start with id = 1 connect by prior id = pid; http://www.itpub.net/838127.html讲的很详细
4,查某个表的字段名:
select max(substr(SYS_CONNECT_BY_PATH(COLUMN_NAME, ','), 2)) col
from (select COLUMN_NAME, column_id
from user_tab_columns
where table_name = '&TEST')--&为plsqldeveloper里的字符串占位符,执行时会弹出对话框让你填值
start with column_id = 1
connect by column_id = rownum;
5,select * from wz_tree where mc like '%五金' start with id = 1 connect by prior id = pid;
和select * from wz_tree start with id = 1 connect by prior id = pid and mc like '%五金'
二者的查询结果不一样
本文介绍了使用Oracle SQL进行层次查询的方法,包括查询所有子节点、父节点及分类路径等,并提供示例说明如何获取表中的特定字段信息。
2714

被折叠的 条评论
为什么被折叠?



