I want to store only the month and the year in oracle data type.
I have a date like ’01-FEB-2010′ stored in a column called time_period.
To get only the month and year i wrote a query like
select to_char(time_period,'MON-YYYY') from fact_table;
I go the result as ‘FEB-2010’ which is fine but the only problem is that it is in varchar datatype.
So I did like
select to_date(to_char(time_period,'MON-YYYY'),'MON-YYYY') from fact_table
and I get 01-FEB-2010. Is it not possible to store only FEB-2010 in the date datatype
“FEB-2010” is not a Date, so it would not make a lot of sense to store it in a date column.
You can always extract the string part you need , in your case “MON-YYYY” using the TO_CHAR logic you showed above.
If this is for a DIMENSION table in a Data warehouse environment and you want to include these as separate columns in the Dimension table (as Data attributes), you will need to store the month and Year in two different columns, with appropriate Datatypes…
Example..