Oracle Connect By Prior用法(实现递归查询)

来源:互联网 发布:sqlite linux 安装 编辑:程序博客网 时间:2024/05/18 00:29
SQL:select id,pid,treename,url,treetype from  web_menu_tree  where  roleid = 1 and  delflag = 1 start with  id = 1 connect by prior id = pid表结构-- Create tablecreate table WEB_MENU_TREE(  ID         NUMBER not null,  PID        NUMBER,  TREENAME   VARCHAR2(200),  URL        VARCHAR2(200),  ROLEID     NUMBER,  TREETYPE   NUMBER,  ORDERNUM   NUMBER,  DELFLAG    NUMBER,  CREATETIME DATE default SYSDATE)tablespace IBM_DATA  pctfree 10  initrans 1  maxtrans 255  storage  (    initial 64K    minextents 1    maxextents unlimited  );start with...connect by prior子句用法 connect by 是结构化查询中用到的, 基本语法是: select  *  from tablename start with 条件1  connect by 条件2  where  条件3;  最近在写一棵目录树的时候,由于设计时表结构设计的不是特别好,所以只有采用递归查询来处理顺便请教了我们公司的Oracle DB大师的精典写法,了解一下吧,好处不少。很多地方可以用得到。

 
原创粉丝点击