ORA-01855: AM/A.M. or PM/P.M. required错误解决

环境:CentOS5.xOracle10R2

SQL*Plus中插入时间类型数据时报了下面这个错:

insert into t(typeid,typename,uptime) values(52,'登录问题',to_date('04/22/2010 10:30:44 上午','mm/dd/yyyy hh:mi:ss am'));

ERROR at line 1:

ORA-01855: AM/A.M. or PM/P.M. required

 

这个应该是和NLS_DATE_LANGUAGE的设置有关,在我设置的NLS_DATE_LANGUAGE指定的语言中并不支持“上午”这样的表示方法,也就是说不同国家地区用来表示“上午/下午”的方式并不一样。

查看当前我的NLS_DATE_LANGUAGE的设置:

SQL> select * from v$nls_parameters;

PARAMETER                                                        VALUE

---------------------------------------------------------------- -----------------------------

NLS_LANGUAGE                                                     AMERICAN

NLS_TERRITORY                                                    AMERICA

NLS_CURRENCY                                                     $

NLS_ISO_CURRENCY                                                 AMERICA

NLS_NUMERIC_CHARACTERS                                           .,

NLS_CALENDAR                                                     GREGORIAN

NLS_DATE_FORMAT                                                  YYYY-MM-DD HH24:MI:SS

NLS_DATE_LANGUAGE                                                AMERICAN

NLS_CHARACTERSET                                                 ZHS16GBK

NLS_SORT                                                         BINARY

NLS_TIME_FORMAT                                                  HH.MI.SSXFF AM

NLS_TIMESTAMP_FORMAT                                             DD-MON-RR HH.MI.SSXFF AM

NLS_TIME_TZ_FORMAT                                               HH.MI.SSXFF AM TZR

NLS_TIMESTAMP_TZ_FORMAT                                          DD-MON-RR HH.MI.SSXFF AM TZR

NLS_DUAL_CURRENCY                                                $

NLS_NCHAR_CHARACTERSET                                           UTF8

NLS_COMP                                                         BINARY

NLS_LENGTH_SEMANTICS                                             BYTE

NLS_NCHAR_CONV_EXCP                                              FALSE

 

19 rows selected.

可以看到我的设置为AMERICAN,所以应该把时间中“上午”改为“AM”,以适应其语言定义要求,如果为“SIMPLIFIED CHINESE”,就可以使用“上午”这样的表示方式了。

上面是一种解决方式,也是我采用的,不过还有另一种方法,就是在session级别修改NLS_DATE_LANGUAGE的定义:

SQL> alter session set NLS_DATE_LANGUAGE='SIMPLIFIED CHINESE';

Session altered.

SQL> insert into t(typeid,typename,uptime) values(52,'登录问题',to_date('04/22/2010 10:30:44 上午','mm/dd/yyyy hh:mi:ss am'));

1 row created.

 

数据是通过Toad导出之后插入同一个库,不知为什么时间的格式会不一样,难道是toad设置或是windows的影响,有知道的可以告诉我一声。

 

你可能感兴趣的:(职场,休闲,ORA-01855)