1818IP-服务器技术教程,云服务器评测推荐,服务器系统排错处理,环境搭建,攻击防护等

当前位置:首页 - 数据库 - 正文

君子好学,自强不息!

Oracle to_char的用法描述

2022-11-26 | 数据库 | 1818ip | 603°c
A+ A-

以下的文章是通过Oracle to_char的用法的相关代码描述来剖析Oracle to_char的用法在实际中的具体应用,以下就是相关内容的详细介绍。以下是文章的具体介绍,望你浏览完以下的内容会有所收获。

Thefollowingarenumberexamplesfortheto_char
function. 
to_char(1210.73,'9999.9')wouldreturn'1210.7' 
to_char(1210.73,'9,999.99')wouldreturn'1,210.73' 
to_char(1210.73,'$9,999.00')wouldreturn'$1,210.73' 
to_char(21,'000099')wouldreturn'000021' 
Thefollowingisalistofvalidparameterswhen
theto_charfunctionisusedtoconvertadateto
astring.Theseparameterscanbeusedinmany
combinations. 
ParameterExplanation 
YEARYear,spelledout 
YYYY4-digityear 
YYY 
YY 
YLast3,2,or1digit(s)ofyear. 
IYY 
IY 
ILast3,2,or1digit(s)ofISOyear. 
IYYY4-digityearbasedontheISOstandard 
QQuarterofyear(1,2,3,4;JAN-MAR=1). 
MMMonth(01-12;JAN=01). 
MONAbbreviatednameofmonth. 
MONTHNameofmonth,paddedwithblankstolength
of9characters. 
RMRomannumeralmonth(I-XII;JAN=I). 
WWWeekofyear(1-53)whereweek1startsonthe
firstdayoftheyearandcontinuestotheseventh
dayoftheyear. 
WWeekofmonth(1-5)whereweek1startsonthe
firstdayofthemonthandendsontheseventh. 
IWWeekofyear(1-52or1-53)basedontheISOstandard. 
DDayofweek(1-7). 
DAYNameofday. 
DDDayofmonth(1-31). 
DDDDayofyear(1-366). 
DYAbbreviatednameofday. 
JJulianday;thenumberofdayssinceJanuary1,4712BC. 
HHHourofday(1-12). 
HH12Hourofday(1-12). 
HH24Hourofday(0-23). 
MIMinute(0-59). 
SSSecond(0-59). 
SSSSSSecondspastmidnight(0-86399). 
FFFractionalseconds. 
Thefollowingaredateexamplesfortheto_charfunction. 
to_char(sysdate,'yyyy/mm/dd');wouldreturn'2003/07/09' 
to_char(sysdate,'MonthDD,YYYY');
wouldreturn'July09,2003' 
to_char(sysdate,'FMMonthDD,YYYY');wouldreturn'July9,2003' 
to_char(sysdate,'MONDDth,YYYY');wouldreturn'JUL09TH,2003' 
to_char(sysdate,'FMMONDDth,YYYY');wouldreturn'JUL9TH,2003' 
to_char(sysdate,'FMMonddth,YYYY');wouldreturn'Jul9th,2003' 
Youwillnoticethatinsomeexamples,theformat_maskparameterbeginswith"FM".Thismeansthatzerosandblanksaresuppressed.Thiscanbeseenintheexamplesbelow. 
to_char(sysdate,'FMMonthDD,YYYY');wouldreturn'July9,2003' 
to_char(sysdate,'FMMONDDth,YYYY');wouldreturn'JUL9TH,2003' 
to_char(sysdate,'FMMonddth,YYYY');wouldreturn'Jul9th,2003' 
Thezeroshavebeensuppressedsothatthedaycomponentshowsas"9"asopposedto"09". 

Oracle函数to_char转化数字型指定小数点位数的用法

Oracle to_char,函数功能,就是将数值型或者日期型转化为字符型。

比如最简单的应用:

/*1.0123--->'1.0123'*/ 
SelectTO_CHAR(1.0123)FROMDUAL 
/*123--->'123'*/ 
SelectTO_CHAR(123)FROMDUAL 

接下来再看看下面:

/*0.123--->'.123'*/ 
SELECTO_CHAR(0.123)FROMDUAL 

上面的结果 ‘.123’ 在大多数情况下都不是我们想要的结果,我们想要的应该是 ‘0.123’。

我们来看一下to_char函数的具体用法:

TO_CHAR(n[,fmt[,'nlsparam']]) 

该函数将NUMBER类型的n按数值格式fmt转换成VARCHAR2类型的值。’nlsparams’指定由数值格式的元素返回的字符,包括:

.小数点字符

.组分隔符

.本地钱币符号

.国际钱币符号

变元的形式为:

'NLS_NUMERIC_CHARACTERS="dg"NLS_CURRENCY=
"tcxt"NLS_ISO_CURRENCY=territory'

其中d为小数点字符,g为组分隔符。

例 :

TO_CHAR(17145,'L099G999','NLS_NUMERIC_CHARACTERS
=".,"NLS_CURRENCY="NUD"')=NUD017,145

本文来源:1818IP

本文地址:https://www.1818ip.com/post/11840.html

免责声明:本文由用户上传,如有侵权请联系删除!

发表评论

必填

选填

选填

◎欢迎参与讨论,请在这里发表您的看法、交流您的观点。