-2
TO_CHAR((  TO_DATE(calendar_key,'YYYYMMDD' )+ 1),'IW') week

Can somebody tell me what's happening in this query? I know what the to_date operation does, I am confused about the '+1' over there, does it add 1 year to the date??

And what about the 'IW'? Is it alias name? and then why 'week'?

Plese help me. Thanks in advance

Niranjan Sonachalam
  • 1,545
  • 1
  • 20
  • 29
  • 1
    " does it add 1 year to the date??" --- is it that difficult to run `SELECT systimestamp + 1 FROM DUAL` and see? – zerkms Jun 15 '12 at 04:43
  • "And what about the 'IW'? Is it alias name? and then why 'week'?" --- http://docs.oracle.com/cd/B19306_01/server.102/b14200/sql_elements004.htm#i34948 – zerkms Jun 15 '12 at 04:44
  • Resolution: **every** programmer should know how to use google and try solving the issue themselves it first, after - ask it on SO – zerkms Jun 15 '12 at 04:44

1 Answers1

1

1) When using basic arithmetics on dates - it operates with days. So +1 means add one day

How could you figure it out yourself:

SELECT systimestamp, systimestamp + 1 FROM DUAL

2) http://docs.oracle.com/cd/B19306_01/server.102/b14200/sql_elements004.htm#i34948

IW - Week of year (1-52 or 1-53) based on the ISO standard.

How could you figure it out yourself:

Google for: "oracle to_char"

PS:

Is it alias name?

Aliases cannot be enclosed by single quotes by definition: they may be placed inside of double quotes or without quotes around at all. So if you see something put in single quotes - it is definitely a string literal.

zerkms
  • 249,484
  • 69
  • 436
  • 539