Oracle 伪列Level的应用
目录导航: 1. 根据ID的数量按序展开 2. 根据ID的数量按序展开 3. 生成随机数 4. 转置截取字符串 1、根据ID的数量按序展开 WITH TB AS (SELECT 'U101' USER_ID, DATE '2016-11-02' START_DT, DATE '2016-11-06' END_DT FROM DUAL UNION ALL SELECT 'U102', DATE '2015-06-01', DATE '2015-06-03' FROM DUAL) SELECT TB.USER_ID, TB.START_DT + LEVEL - 1 FROM TB CONNECT BY TB.USER_ID = PRIOR TB.USER_ID AND LEVEL <= (TB.END_DT - TB.START_DT + 1) AND PRIOR DBMS_RANDOM.VALUE IS NOT NULL; 2. 根据ID的数量按序展开 WITH TB AS (SELECT 'U101' USER_ID, '12345' MOBILE, 3 CNT FROM DUAL UNION ALL SELECT 'U102', '33563', 4 FROM DUAL) SELECT A.USER_ID, A.MOBILE, B.LV FROM TB A LEFT JOIN