oracle fx成立时间,oracle 日期格式FM/FX和日期后缀SP/TH/SPTH/THSP
一、日期后綴
oracle的日期后綴,有SP、TH、SPTH/THSP幾種
在oracle的官方聯(lián)機(jī)文檔上有,有如下描述:
摘錄表格如下:
TH是序數(shù)方式顯示,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
--序數(shù)方式顯示,月份后面也一樣有個(gè)大空格。
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的大小寫也會(huì)變化
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的大小寫也會(huì)變化
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是字母拼寫和序數(shù)方式顯示
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參數(shù)后將僅返回指定屬性實(shí)際所占長度(不再以空格填充)。
如果是數(shù)值格式化,fm參數(shù)會(huì)自動(dòng)舍棄被格式化元素的前置0。
--序數(shù)方式顯示,并且fm方式顯示,會(huì)把多余的前綴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方式顯示,會(huì)把多余的前綴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.字符及對應(yīng)的格式必須嚴(yán)格一一對應(yīng),甚至連分隔符都要相符。
2.不允許有多余的空格。
3.數(shù)值參與格式需要完全對應(yīng)(或通過fm參數(shù)去掉前置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
總結(jié)
以上是生活随笔為你收集整理的oracle fx成立时间,oracle 日期格式FM/FX和日期后缀SP/TH/SPTH/THSP的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: APUE---chap3文件I/O---
- 下一篇: 为什么要CGI