4
5

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

ORACLEの機能を使って組織階層情報を取得

Last updated at Posted at 2014-05-19

組織階層情報の取得

  • 1テーブル内で、 [自身の組織コード][親の組織コード] を別カラムで保持するような構造のテーブルで有効
  • Oracleの機能を使って親子関係を簡単に取得する
  • 階層が変動的でも柔軟に出力してくれるので便利
SQL

/* 組織階層情報取得 */
select
     lpad(' ', 2*level) || t1.ORG_NAME  as LEVEL_DISP -- 階層レベルに合わせて高さを調整 
    ,substr(sys_connect_by_path(
              t1.ORG_NAME,' > '), 4 )    as TREE       -- 上位階層から並べて表示
    ,connect_by_isleaf                   as ISLEAF     -- リーフか否か
    ,level                               as NODE_LEVEL -- 階層レベルを数値で表示
from
        ORG_PARENT_CHILD t1
start  with
     t1.PARENT_ORG_CD = '20000000'
connect by nocycle prior
     t1.ORG_CD = t1.PARENT_ORG_CD   
order by
     t1.ORG_CD
/

4
5
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
4
5

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?