ORACLEto_char()函数获取自然周数
作者:互联网
转 ORACLE to_char() 函数获取自然周数https://blog.csdn.net/tianlesoftware/article/details/4925059 最简单的是使用
/* Formatted on 2009/12/02 16:01 (Formatter Plus v4.8.8) */
SELECT TO_CHAR (TO_DATE ('2009-12-02', 'YYYY-MM-DD'), 'WW')
FROM DUAL;
不过to_char()函数在计算一年中第几周是从该年的1月1日开始的。
以下SQL 能得到正确的自然周数.
/* Formatted on 2009/12/02 15:31 (Formatter Plus v4.8.8) */
SELECT TO_CHAR
(DECODE
(SIGN
( ( TO_DATE ('2009-12-02', 'YYYY-MM-DD')
+ TO_NUMBER
(DECODE (TO_CHAR (TRUNC (TO_DATE ('2009-12-02',
'YYYY-MM-DD'
),
'YYYY'
),
'D'
),
'1', '8',
TO_CHAR (TRUNC (TO_DATE ('2009-12-02',
'YYYY-MM-DD'
),
'YYYY'
),
'D'
)
)
)
- 2
)
- LAST_DAY (TO_DATE ('2009-12-02', 'YYYY-MM-DD'))
),
1, LAST_DAY (TO_DATE ('2009-12-02', 'YYYY-MM-DD')),
( TO_DATE ('2009-12-02', 'YYYY-MM-DD')
+ TO_NUMBER (DECODE (TO_CHAR (TRUNC (TO_DATE ('2009-12-02',
'YYYY-MM-DD'
),
'YYYY'
),
'D'
),
'1', '8',
TO_CHAR (TRUNC (TO_DATE ('2009-12-02',
'YYYY-MM-DD'
),
'YYYY'
),
'D'
)
)
)
- 2
)
),
'WW'
)
FROM DUAL;
https://www.icode9.com/i/ll/?i=20190217105710569.png?,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3UwMTEwNzgxNDE=,size_16,color_FFFFFF,t_70《算法导论 第三版英文版》_高清中文版.pdf
https://pan.baidu.com/s/17D1kXU6dLdU0YwHM2cvNMw
《深度学习入门:基于Python的理论与实现》_高清中文版.pdf
https://pan.baidu.com/s/1IeVs35f3gX5r6eAdiRQw4A
《深入浅出数据分析》_高清中文版.pdf
https://pan.baidu.com/s/1GV-QNbtmjZqumDkk8s7z5w
《Python编程:从入门到实践》_高清中文版.pdf
https://pan.baidu.com/s/1GUNSg4mdpeOf1LC_MjXunQ
《Python科学计算》_高清中文版.pdf
https://pan.baidu.com/s/1-hDKhK-7rDDFll_UFpKmpw
标签:02,YYYY,12,MM,周数,ORACLEto,char,2009,DD 来源: https://blog.csdn.net/u011078141/article/details/88090324