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 '%五金'
二者的查询结果不一样