Using PL/SQL for Oracle, convert date to year/month

I want to convert the date to a year/month.  An example would be the date is 01/10/2017 and converted to 201701.

And so any date within January would convert to 201701.  Any date within February would be 201702 etc.

Can this be done and if yes, how?

Thanks, Scott
Scott PalmerData AnalystAsked:
Who is Participating?
slightwv (䄆 Netminder) Commented:
If it is a DATE data type:

If it is a string (varchar2) just use SUBSTR and concatenation to move the bytes around:  substr(varchar2_column,7,4) || substr(varchar2_column,1,2)

Also:  PL/SQL is Oracle's Procedural Language.  You just need SQL.
Kent OlsenData Warehouse Architect / DBACommented:
Use the to_char() function

SELECT to_char (some_date, "YYYYMM") from ...

Scott PalmerData AnalystAuthor Commented:
Thanks Kent.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.