DB2 递归SQL 根据当前机构查询所有下属机构树
程序员文章站
2022-05-08 11:12:08
...
CREATE TABLE UNTECK_ORGANIZATION ( ID BIGINT NOT NULL, LEVEL_ INTEGER, NAME VARCHAR(64), AREACODE VARCHAR(8), ORGSEQ VARCHAR(128), PARENTID BIGINT, THESORT INTEGER, DESCN VARCHAR(256), DEL_FLAG INTEGER, CREATE_TIME TIMESTAMP, CREATE_USER V
CREATE TABLE UNTECK_ORGANIZATION (
ID BIGINT NOT NULL,
LEVEL_ INTEGER,
NAME VARCHAR(64),
AREACODE VARCHAR(8),
ORGSEQ VARCHAR(128),
PARENTID BIGINT,
THESORT INTEGER,
DESCN VARCHAR(256),
DEL_FLAG INTEGER,
CREATE_TIME TIMESTAMP,
CREATE_USER VARCHAR(64),
UPDATE_TIME TIMESTAMP,
UPDATE_USER VARCHAR(64),
CODE VARCHAR(64),
ADDRESS VARCHAR(255),
CELLPHONE VARCHAR(24),
ORGTYPE VARCHAR(20),
PRIMARY KEY (ID) );
with temptab(ID,NAME,CODE,PARENTID) as
(select a.ID,a.NAME,a.CODE,a.PARENTID
from UNTECK_ORGANIZATION a
where a.ID = 3413585099
union all
select sub.ID,sub.NAME,sub.CODE,sub.PARENTID
from UNTECK_ORGANIZATION sub, temptab super
where sub.PARENTID = super.ID
)
select ID,NAME,CODE,PARENTID from temptab