Trouble of the day: Oracle error ORA-01843. How to insert a date in an Oracle Database.

Hi all!
I'm still playing in the amazing world of Oracle Database. Let me write down this small post just to tell you how to solve a stupid problem, that anyway takes some time to figure out.

So, as I wrote in my last post, I finally managed to create my first table with Oracle Database. I created it, celebrate, wrote down a blog post, had a cookie and then... started to populate it. First statement:

insert into P2 values(1010, 'john', '1940-10-21', 'Rome');
>>ERROR ORA-01843: month not valid.
 
 
 
Aaaaaargh!!!
Well then, after some attempts with various formats and some googling, I found out that the correct way to insert a date in OracleDB is using
 
TO_DATE('21/10/40', 'DD/MM/YY');
 
 
So that the whole insert query is going to be:

insert into P2 values(1010, 'john', TO_DATE('21/10/40', 'DD/MM/YY'), 'Rome');
 
 
Interesting, isn't it?
Hope this post helped! I think I'm going to write down a lot of this kind of post while I'm struggling with Oracle Database!

Commenti