oracle fx成立时间,oracle 日期格式FM/FX和日期后缀SP/TH/SPTH/THSP

一、日期后缀

oracle的日期后缀,有SP、TH、SPTH/THSP几种

在oracle的官方联机文档上有,有如下描述:

摘录表格如下:

4ab0d054aba9a37c093bb1bff4949b05.png

TH是序数方式显示,SP是用字母拼写方式显示.

THSP或SPTH,就是两种方式都有。

--普通方式显示,月份后面,有很大的空格。

SQL> SELECT TO_CHAR(SYSDATE, 'DD') || ' of '  ||

2         TO_CHAR(SYSDATE, 'Month') || ', ' ||

3         TO_CHAR(SYSDATE, 'YYYY') "Ides"

4  FROM DUAL;

Ides

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

07 of May      , 2014

--序数方式显示,月份后面也一样有个大空格。

SQL> SELECT TO_CHAR(SYSDATE, 'DDTH') || ' of '||

2         TO_CHAR(SYSDATE, 'Month')|| ', '  ||

3         TO_CHAR(SYSDATE, 'YYYY') "Ides"

4  FROM DUAL;

Ides

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

07TH of May      , 2014

--改变Dd的大小写,th的大小写也会变化

SQL> SELECT TO_CHAR(SYSDATE, 'DdTH') || ' of '||

2         TO_CHAR(SYSDATE, 'Month')|| ', '  ||

3         TO_CHAR(SYSDATE, 'YYYY') "Ides"

4  FROM DUAL;

Ides

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

07th of May      , 2014

--改变dd的大小写,th的大小写也会变化

SQL> SELECT TO_CHAR(SYSDATE, 'ddTH')|| ' of '||

2         TO_CHAR(SYSDATE, 'Month') || ', ' ||

3         TO_CHAR(SYSDATE, 'YYYY') "Ides"

4  FROM DUAL;

Ides

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

07th of May      , 2014

-- SP是字母拼写方式显示

SQL>  SELECT TO_CHAR(SYSDATE, 'DDsp') || ' of ' ||

2          TO_CHAR(SYSDATE, 'Month') || ', ' ||

3          TO_CHAR(SYSDATE, 'YYYY') "Ides"

4   FROM DUAL;

Ides

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

SEVEN of May      , 2014

-- SPTH和THSP是字母拼写和序数方式显示

SQL> SELECT TO_CHAR(SYSDATE, 'DDSPTH') || ' of ' ||

2         TO_CHAR(SYSDATE, 'Month') || ', ' ||

3          TO_CHAR(SYSDATE, 'YYYY') "Ides"

4  FROM DUAL;

Ides

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

SEVENTH of May      , 2014

二、FM和FX格式

The FM and FX modifiers, used in format models in the TO_CHAR function, control blank padding and exact format checking.

FM和FX主要是用来控制填充和精确格式。

FM Fill mode. Oracle uses trailing blank characters and leading zeroes

to fill format elements to a constant width. The width is equal to the

display width of the largest element for the relevant format model:

Numeric elements are padded with leading zeros to the width of the

maximum value allowed for the element. For example, the YYYY element is

padded to four digits (the length of '9999'), HH24 to two digits (the

length of '23'), and DDD to three digits (the

length of '366').

The character elements MONTH, MON, DAY, and DY are padded with

trailing blanks to the width of the longest full month name, the longest

abbreviated month name, the longest full date name, or the longest

abbreviated day name, respectively, among valid names

determined by the values of NLS_DATE_LANGUAGE and NLS_CALENDAR

parameters. For example, when NLS_DATE_LANGUAGE is AMERICAN and

NLS_CALENDAR is GREGORIAN (the default), the largest element for MONTH

is SEPTEMBER, so all values of the MONTH format element are

padded to nine display characters. The values of the NLS_DATE_LANGUAGE

and NLS_CALENDAR parameters are specified in the third argument to

TO_CHAR and TO_* datetime functions or they are retrieved from the NLS

environment of the current session.

The character element RM is padded with trailing blanks to the length of 4, which is the length of 'viii'.

Other character elements and spelled-out numbers (SP, SPTH, and THSP suffixes) are not padded.

The FM modifier suppresses the above padding in the return value of the TO_CHAR function.

fm是填充模式

如果是字符格式化,指定fm参数后将仅返回指定属性实际所占长度(不再以空格填充)。

如果是数值格式化,fm参数会自动舍弃被格式化元素的前置0。

--序数方式显示,并且fm方式显示,会把多余的前缀0和多余的空格去掉。

SQL> SELECT TO_CHAR(SYSDATE, 'fmDDTH') || ' of ' ||

2         TO_CHAR(SYSDATE, 'fmMonth') || ', ' ||

3         TO_CHAR(SYSDATE, 'YYYY') "Ides"

4    FROM DUAL;

Ides

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

7TH of May, 2014

--字母拼写方式显示,并且fm方式显示,会把多余的前缀0和多余的空格去掉。

SQL> SELECT TO_CHAR(SYSDATE, 'fmDDTHSP') || ' of ' ||

2         TO_CHAR(SYSDATE, 'fmMonth') || ', ' ||

3         TO_CHAR(SYSDATE, 'YYYY') "Ides"

4  FROM DUAL;

Ides

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

SEVENTH of May, 2014

FX  Format exact. This modifier

specifies exact matching for the character argument and datetime format

model of a TO_DATE function:

Punctuation and quoted text in the character argument must exactly

match (except for case) the corresponding parts of the format model.

The character argument cannot have extra blanks. Without FX, Oracle ignores extra blanks.

Numeric data in the character argument must have the same number of

digits as the corresponding element in the format model. Without FX,

numbers in the character argument can omit leading zeros.

When FX is enabled, you can disable this check for leading zeros by using the FM modifier as well.

fx是精确匹配模式,使用FX格式后:

1.字符及对应的格式必须严格一一对应,甚至连分隔符都要相符。

2.不允许有多余的空格。

3.数值参与格式需要完全对应(或通过fm参数去掉前置0)

SQL> select to_date('2014-5-10','yyyy-mm-dd') from dual;SQL> select to_date('2014-5-10','yyyy-mm-dd') from dual;

TO_DATE('201

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

10-MAY-14

SQL> select to_date('2014-5-10','yyyy/mm/dd') from dual;

TO_DATE('201

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

10-MAY-14

SQL> select to_date('2014-5-10','fxyyyy-mm-dd') from dual;

select to_date('2014-5-10','fxyyyy-mm-dd') from dual

*

ERROR at line 1:

ORA-01862: the numeric value does not match the length of the format item

SQL> select to_date('2014-5-10','fxyyyy/mm/dd') from dual;

select to_date('2014-5-10','fxyyyy/mm/dd') from dual

*

ERROR at line 1:

ORA-01861: literal does not match format string

SQL> select to_date('2014-05-10','fxyyyy-mm-dd') from dual;

TO_DATE('201

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

10-MAY-14

SQL> select to_date('2014-5-10','fxyyyy-fmmm-dd') from dual;

TO_DATE('201

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

10-MAY-14 10-MAY-14

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值