其他不常用的格式掩码
演示数据:24-SEP-1000 BC
格式元素 |
说明 |
结果 |
W |
月的周数 |
4 |
WW |
年的周数 |
39 |
Q |
年的季度 |
3 |
CC |
世纪 |
10 |
S preceding CC,YYYY,YEAR |
如果日期是BC,那么减号就在结果之前 |
-10,-1000或者-ONE THOUSAND |
IYYY,IYY,IY,I |
分别表示4,3,2,1为ISO日期 |
1000,000,00,0 |
BC,AD,B.C. and A.D. |
|
|
J |
儒略日—从公元前4713年12月31日开始的天数 |
1356075 |
IW |
ISO标准周(1到53) |
39 |
RM |
用罗马数字表示的月 |
IX |
时间组件的日期格式掩码
演示数据:27-JUN-2010 21:35:13
格式元素 |
说明 |
结果 |
AM,PM,A.M.和P.M. |
子午线指示器 |
PM |
HH,HH12,HH24 |
一天的小时,1-12时和0-23时 |
09,09,21 |
MI |
分(0-59) |
35 |
SS |
秒(0-59) |
12 |
SSSSS |
午夜之后的秒(0-86399) |
77713 |
其他日期格式掩码
格式元素 |
说明和格式掩码 |
结果 |
-/.,?#! |
标点符号:’MM.YY’ |
09.08 |
“any character literal” |
字符值:’”Week” W “”of” Month’ |
Week 2 of September |
TH |
位置或者序数文本:’DDth”of”Month’ |
12TH of September |
SP |
拼写出数字:’MmSP Month YYYYSP’ |
Nine September Two Thousand Eight |
THSP or SPTH |
拼写出位置或者序数:’hh24SpTh’ |
Fourteenth |
2)to_date
字符值->日期值
语法:to_date (string,[format mask],[nls_parameters])
参数:string 待转换的字符值
format mask:可选参数
格式掩码同to_char转换为date时相同。
备注:转换时要根据给定的string设定正确的格式掩码,否则
Ora_01840:input value is not long enough for date format.
Ora_01862:the numeric value does not match the length of the format item.
3) to_number
字符值->数字值
语法:to_number (string,[format mask],[nls_parameters])
参数:string 待转换的字符值
format mask:可选参数
格式掩码同to_char转换为number时相同。
备注:如果使用较短的格式掩码就会返回错误。
例如: to_number(123.56,’999.9’)返回错误。