Week numbers in Oracle DB
To get the current ISO 8601 week number in Oracle DB, use the following code snippet:
SELECT TO_CHAR(SYSDATE, 'IW') FROM DUAL;
* Ensure your system or application regional settings are set to follow ISO 8601 standards (weeks start on Monday) if the output varies.
Step-by-Step Instructions
- Run: SELECT TO_CHAR(SYSDATE, 'IW') FROM DUAL;
- 'IW' is the ISO 8601 week number as a two-digit string.
- Use TO_CHAR(SYSDATE, 'IYYY') for the matching ISO year.
Good to Know
Oracle's 'WW' format is NOT ISO (it counts 7-day blocks from January 1). Always combine 'IW' with 'IYYY', not 'YYYY', so week labels stay consistent across the year boundary.