有个兄弟非要在sql中返回月份01,02....
我想到下面2个办法
1.使用union
select '01' from dual union
select '02' from dual union
......
2.使用regexp_substr函数
select regexp_substr('01,02,03,04,05,06,07,08,09,10,11,12','[^,]+',1,rownum) from dual connect by rownum<=12
标准的格式应该是
select regexp_substr('01,02,03,04,05,06,07,08,09,10,11,12','[^,]+',1,rownum) from dual
connect by rownum<=length('01,02,03,04,05,06,07,08,09,10,11,12')-length(replace('01,02,03,04,05,06,07,08,09,10,11,12',','))+1
但是把长度计算一下就没有必要写那么长了。
比如 select regexp_substr('红色,白色,黑','[^,]+',1,rownum) from dual connect by rownum<=3