`
咖啡舞者
  • 浏览: 126969 次
  • 性别: Icon_minigender_1
  • 来自: 福州
社区版块
存档分类
最新评论

to_char 函数

阅读更多

Oracle/PLSQL: To_Char Function


In Oracle/PLSQL, the to_char function converts a number or date to a string.

The syntax for the to_char function is:

to_char( value, [ format_mask ], [ nls_language ] )

value can either be a number or date that will be converted to a string.

format_mask is optional. This is the format that will be used to convert value to a string.

nls_language is optional. This is the nls language used to convert value to a string.

 

Applies To:

  • Oracle 8i, Oracle 9i, Oracle 10g, Oracle 11g

 

Examples - Numbers

The following are number examples for the to_char function.

to_char(1210.73, '9999.9') would return '1210.7'
to_char(1210.73, '9,999.99') would return '1,210.73'
to_char(1210.73, '$9,999.00') would return '$1,210.73'
to_char(21, '000099') would return '000021'

 

Examples - Dates

The following is a list of valid parameters when the to_char function is used to convert a date to a string. These parameters can be used in many combinations.

ParameterExplanation
YEAR Year, spelled out
YYYY 4-digit year
YYY
YY
Y
Last 3, 2, or 1 digit(s) of year.
IYY
IY
I
Last 3, 2, or 1 digit(s) of ISO year.
IYYY 4-digit year based on the ISO standard
Q Quarter of year (1, 2, 3, 4; JAN-MAR = 1).
MM Month (01-12; JAN = 01).
MON Abbreviated name of month.
MONTH Name of month, padded with blanks to length of 9 characters.
RM Roman numeral month (I-XII; JAN = I).
WW Week of year (1-53) where week 1 starts on the first day of the year and continues to the seventh day of the year.
W Week of month (1-5) where week 1 starts on the first day of the month and ends on the seventh.
IW Week of year (1-52 or 1-53) based on the ISO standard.
D Day of week (1-7).
DAY Name of day.
DD Day of month (1-31).
DDD Day of year (1-366).
DY Abbreviated name of day.
J Julian day; the number of days since January 1, 4712 BC.
HH Hour of day (1-12).
HH12 Hour of day (1-12).
HH24 Hour of day (0-23).
MI Minute (0-59).
SS Second (0-59).
SSSSS Seconds past midnight (0-86399).
FF Fractional seconds.

 

The following are date examples for the to_char function.

to_char(sysdate, 'yyyy/mm/dd'); would return '2003/07/09'
to_char(sysdate, 'Month DD, YYYY'); would return 'July 09, 2003'
to_char(sysdate, 'FMMonth DD, YYYY'); would return 'July 9, 2003'
to_char(sysdate, 'MON DDth, YYYY'); would return 'JUL 09TH, 2003'
to_char(sysdate, 'FMMON DDth, YYYY'); would return 'JUL 9TH, 2003'
to_char(sysdate, 'FMMon ddth, YYYY'); would return 'Jul 9th, 2003'

 

You will notice that in some examples, the format_mask parameter begins with "FM". This means that zeros and blanks are suppressed. This can be seen in the examples below.

to_char(sysdate, 'FMMonth DD, YYYY'); would return 'July 9, 2003'
to_char(sysdate, 'FMMON DDth, YYYY'); would return 'JUL 9TH, 2003'
to_char(sysdate, 'FMMon ddth, YYYY'); would return 'Jul 9th, 2003'

The zeros have been suppressed so that the day component shows as "9" as opposed to "09".

分享到:
评论

相关推荐

    Oracle 中的 TO_DATE 和 TO_CHAR 函数

    Oracle 中的 TO_DATE 和 TO_CHAR 函数 oracle 中 TO_DATE 函数的时间格式,以 2008-09-10 234556 为例

    Oracle 中的 TO_DATE 和 TO_CHAR 函数 日期处理

    Oracle 中的 TO_DATE 和 TO_CHAR 函数 日期处理 Oracle 中的 TO_DATE 和 TO_CHAR 函数 日期处理

    Oracle to_char函数的使用方法

    Oracle to_char函数的功能是将数值型或者日期型转化为字符型,下面就为您详细介绍Oracle to_char函数的使用,希望对您能有所帮助。 Postgres 格式化函数提供一套有效的工具用于把各种数据类型(日期/时间,int,...

    oracle to_char函数将number转成string

    很多数据转换处理操作时,会遇到将0.007007040000转换成0.70%的需求,我们使用Oracle 的SQL 函数 to_char可以实现这种转换。 这个函数用来将DATE或NUMBER数据类型转换成可显示的字符串,格式是to_char(number_type, ...

    oracle-sql基本语法例子,包括to_date,to_char

    总结的sql语法,其中包括一些函数的用法,to_date,to_char,to_number等等函数

    oracle to_char function

    oracle to_char函数的各种应用,在pl_sql当中的各种写法

    oracle 数值型函数,字符型函数,日期函数,转换函数,to_char

    oracle 数值型函数,字符型函数,日期函数,转换函数,to_char

    Oracle中TO_DATE、TO_CHAR,Oracle函数大全

    NULL 博文链接:https://576017120.iteye.com/blog/1280786

    Oracle to_char 日期转换字符串语句分享

    SQL>select to_char(sysdate,’YYYY-MM-DD HH12:MI:SS AM’)from dual; TO_CHAR(SYSDATE,’YYYY-MM-DDHH1 —————————— 2007-06-29 02:50:06 下午 2》以24小时制显示 SQL> select to_char(sysdate,’...

    Oracle10g自定义聚合函数(字符串拼接)

    * 可自定义指定排序字段sequence,对于数字或日期类型的字段,先转为字符串,比如to_char(line, 'FM000') * 由于聚合函数只支持一个参数,这里使用对象类型实现传入多个参数 * Oracle11g Release2版本引入了...

    infoxmix日期比较

    例date(‘12/7/04’) <br>To_char函数将datetime和date值转化为字符值。 <br>To_date函数将字符值转化为datetime类型的值。例to_date(“1978-10-0710:00”,”%Y-%m-%d%H:%M) <br>...

    oracle日期类型的处理

    1. 日期和字符转换函数用法(to_date,to_char) select to_char(sysdate,'yyyy-mm-dd hh24:mi:ss') as nowTime from dual; //日期转化为字符串 select to_char(sysdate,'yyyy') as nowYear from dual; //获取时间...

    基于oracle小数点前零丢失的问题分析

    2.解决办法:用to_char函数格式化数字显示 select to_char(0.338,’fm9999999990.00′) from dual; 结果:0.34 这里重点要看 fm9999999999.99,表示整数部分最多10位,小数部分2位,fm表示去 掉转位字符串后前面的空格,...

    Oracle to_date()函数的用法介绍

    在Oracle数据库中,Oracle to_date()函数是我们经常使用的函数,下面就为您详细介绍Oracle to_date()函数的用法,希望可以对您有所启迪。 to_date()与24小时制表示法及mm分钟的显示: 一、在使用Oracle的to_date函数...

    浅析Oracle中char和varchar2的区别

    char是定长的 char(10) varchar2(10) 同样存 a ,char占用了10个字符,varchar2 ... 您可能感兴趣的文章:oracle to_char函数将number转成stringOracle to_char函数的使用方法SQL中Charindex和Oracle中对应的函数Instr

    oracle中to_date详细用法示例(oracle日期格式转换)

    1. 日期和字符转换函数用法(to_date,to_char) 代码如下:select to_char(sysdate,’yyyy-mm-dd hh24:mi:ss’) as nowTime from dual; //日期转化为字符串 select to_char(sysdate,’yyyy’) as nowYear from ...

    orcale笔记

    11. to_char函数将日期或数字串转换为固定的格式 2 12. to_date函数将字符串转换为指定的日期格式 2 13. to_number函数 2 14. group by 2 15. 建表create 2 16. 修改表结构alter 3 17. 查看相关表、视图、字典、约束...

    MySQL与Oracle的语法区别详细对比

    Oracle和mysql的一些简单命令对比 1) SQL> select to_char(sysdate,’yyyy-mm-dd’) from dual; SQL> select to_char(sysdate,... 日期函数 增加一个月: SQL> select to_char(add_months(to_date (‘20000101′,’yyy

Global site tag (gtag.js) - Google Analytics