Search code examples
sqlplsqlto-date

What does this to_date() function of PLSQL do?


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


Solution

  • 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.