代码改变世界

一种使用connect by level转集合的SQL 语句。

2010-12-24 14:12  Tracy.  阅读(690)  评论(0编辑  收藏  举报

/* Formatted on 12/24/2010 2:02:41 PM (QP5 v5.163.1008.3004) */
SELECT       TO_CHAR (SUBSTR (c,
                              INSTR (c,
                                     ',',
                                     1,
                                     LEVEL)
                              + 1,
                                INSTR (c,
                                       ',',
                                       1,
                                       LEVEL + 1)
                              - INSTR (c,
                                       ',',
                                       1,
                                       LEVEL)
                              - 1)) dayofweek
      FROM   (SELECT ',' || 'MON,TUE,WED' || ',' c FROM DUAL)
CONNECT BY   LEVEL < LENGTH (c) - LENGTH (REPLACE (c, ','))