zoukankan      html  css  js  c++  java
  • sys_connect_by_path的两种用法

    本文主要讨论sys_connect_by_path的使用方法。

    1、带层次关系

    SQL> create table dept(deptno number,deptname varchar2(20),mgrno number);

    Table created.

    SQL> insert into dept values(1,'总公司',null);

    1 row created.

    SQL> insert into dept values(2,'浙江分公司',1);

    1 row created.

    SQL> insert into dept values(3,'杭州分公司',2);

    1 row created.

    SQL> commit;

    Commit complete.

    SQL> select max(substr(sys_connect_by_path(deptname,','),2)) from dept connect by prior deptno=mgrno;

    MAX(SUBSTR(SYS_CONNECT_BY_PATH(DEPTNAME,','),2))
    --------------------------------------------------------------------------------
    总公司,浙江分公司,杭州分公司

    2、行列转换
    如把一个表的所有列连成一行,用逗号分隔:

    SQL> select max(substr(sys_connect_by_path(column_name,','),2))
    from (select column_name,rownum rn from user_tab_columns where table_name ='DEPT')
    start with rn=1 connect by rn=rownum ;

    MAX(SUBSTR(SYS_CONNECT_BY_PATH(COLUMN_NAME,','),2))
    --------------------------------------------------------------------------------
    DEPTNO,DEPTNAME,MGRNO

  • 相关阅读:
    shared_ptr weak_ptr boost 内存管理
    _vimrc win7 gvim
    qt 拖放
    数学小魔术 斐波那契数列
    qt4 程序 移植到 qt5
    (转)字符串匹配算法总结
    c++11
    BM 字符串匹配
    编译qt5 demo
    c++ 类库 学习资源
  • 原文地址:https://www.cnblogs.com/eric_ibm/p/1398978.html
Copyright © 2011-2022 走看看