SQL ORACLE (DATE)

I want to insert a date from jsp that i have been make...

the date is format is 01-12-2016(DD-MM-YYYY) but it always said invalid month

My database date format is 05-DEC-16 (DD-MONTH-YYYY)

this is my function

insert into institution_exam(ACADEMIC_INSTITUITION_ID,place,start_date,end_date) values (i_e_id,V_place,(i_e_id,V_place,TO_DATE(V_date_start,'DD-MONTH-yyyy'),TO_DATE(V_date_end,'DD-MONTH-yyyy'));-----select max

there error ORA-01843: not a valid month

any idea's??


您可以使用适当格式的to_date() ,DD-MM-YYYY:

insert into institution_exam(ACADEMIC_INSTITUITION_ID, place, start_date, end_date)
    values (i_e_id, V_place,
            TO_DATE(V_date_start, 'DD-MM-YYYY'),
            TO_DATE(V_date_end, 'DD-MM-YYYY')
           );

This may help. Notice the difference between MONTH and MON in the date format model. It seems like your data uses the short name but in your query you are using MONTH instead of MON .

As an aside, notice how there is an extra space after DECEMBER in the long format... that's a "feature" in Oracle, where all month names (and same with week names), when spelled out in full, are all the same length - and padded with spaces to make them so. But that is probably irrelevant to your situation.

select to_char(sysdate, 'DD-MONTH-YYYY') as long_month_name, 
       to_char(sysdate, 'DD-MON-YYYY')   as short_month_name
from   dual;

LONG_MONTH_NAME    SHORT_MONTH_NAME
-----------------  ----------------
20-DECEMBER -2016  20-DEC-2016
链接地址: http://www.djcxy.com/p/36964.html

上一篇: 如何在Oracle中以毫秒为单位转换时间戳

下一篇: SQL ORACLE(日期)