DB2 ORACLE 재 귀적 조회 줄 전환 열

1355 단어 Oacle
ORACLE
재 귀적 조회:

select parent_inst_id, inst_id
  from uprr.u_base_inst
 start with inst_id = '222000000000'
connect by prior inst_id = parent_inst_id;

열 바 꾸 기:

select user_id, wmsys.wm_concat(organ_id)
  from v_organ_user_info
 group by user_id;

DB2
재 귀적 조회:
WITH t(pid, id) AS(
  SELECT parent_inst_id, inst_id
    FROM uprr.u_base_inst
   WHERE inst_id = '222000000000'
  UNION ALL
  SELECT c.parent_inst_id, c.inst_id
    FROM t p, uprr.u_base_inst c
   WHERE p.id = c.parent_inst_id)

  SELECT * FROM t

행 열

WITH t1(u,o,num) AS (
    SELECT user_id,organ_id,row_number() over(PARTITION BY user_id ORDER BY organ_id) FROM V_ORGAN_USER_INFO
),
t2(au,ao,anum) AS (
    SELECT u,o,num FROM t1 WHERE num=1
    UNION ALL
    SELECT t1.u,t2.ao||','||t1.o,t1.num FROM t1,t2 
    WHERE t1.num=t2.anum+1 AND t1.u=t2.au AND t1.num <3)

SELECT au,ao FROM t2
WHERE aNUM = (SELECT max(anum) FROM t2 temp WHERE temp.au=t2.au)
ORDER BY t2.au;

이 중 DB2 가 줄 을 돌 릴 때 필드 길이 가 길지 않 으 면 22001 오류 가 발생 합 니 다.

좋은 웹페이지 즐겨찾기