Table has a column with nvarchar datatype. This column store a data in this format: yyyy-mm-dd hh:mm:ss.
And I need to fetch data in this format dd-mm-yyyy. So I am using this to_char(to_date(columnname,'yyyy-mm-dd hh:mm:ss'),'dd-mm-yyyy'). I am getting correct data while fetching from select statement but when I am creating Materialized view then its throwing an error "literals string does not matching format string".
Please advise on this.
Format mask you use is wrong; minutes are
mi, notmm(that's month).Apart from that: saying that query returns desired result, are you sure that it returned all rows? GUIs (SQL Developer, TOAD, ...) usually return the first 50, 100, 500 (or whichever number it might be) rows - not all of them.
Error you got suggests that NOT ALL rows in that table contain data in format you think they have (i.e. yyyy-mm-dd hh:mi:ss).
Here's example: this is source table; note that 2nd row doesn't contain data in format you specified:
Let's create a view:
Can I fetch from it? Nope; error just as the one you got:
What to do? It depends on database you use. If it is 12c or newer (12.2; not sure for 12.1), apply
on conversion errortoto_datefunction. Otherwise, you'll have to sanitize source data and make sure that all rows contain values in that format. Then move on with creating the (materialized) view.