oracle 日期格式化 TO_CHAR (datetime) 修饰语和后缀
Datetime Format Element Suffixes
Suffix | Meaning | Example Element | Example Value |
---|---|---|---|
TH | Ordinal Number | DDTH | 4TH |
SP | Spelled Number | DDSP | FOUR |
SPTH or THSP | Spelled, ordinal number | DDSPTH | FOURTH |
Notes on date format element suffixes:
- When you add one of these suffixes to a datetime format element, the return value is always in English.
- Datetime suffixes are valid only to format output. You cannot use them to insert a date into the database.
Format Model Modifiers
FM
Fill mode. Oracle uses blank characters to fill format elements to a constant width equal to the largest element for the relevant format model in the current session language. For example, when NLS_LANGUAGE is AMERICAN, the largest element for MONTH is SEPTEMBER, so all values of the MONTH format element are padded to 9 display characters. This modifier suppresses blank padding in the return value of the TO_CHAR function:
- In a datetime format element of a TO_CHAR function, this modifier suppresses blanks in subsequent character elements (such as MONTH) and suppresses leading zeroes for subsequent number elements (such as MI) in a date format model. Without FM, the result of a character element is always right padded with blanks to a fixed length, and leading zeroes are always returned for a number element. With FM, which suppresses blank padding, the length of the return value may vary.
- In a number format element of a TO_CHAR function, this modifier suppresses blanks added to the left of the number, so that the result is left-justified in the output buffer. Without FM, the result is always right-justified in the buffer, resulting in blank-padding to the left of the number.
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 zeroes.When FX is enabled, you can disable this check for leading zeroes by using the FM modifier as well.
If any portion of the character argument violates any of these conditions, then Oracle returns an error message.
Format Model Examples
SELECT TO_CHAR(SYSDATE, 'fmDDTH')||' of '||TO_CHAR
(SYSDATE, 'fmMonth')||', '||TO_CHAR(SYSDATE, 'YYYY') "Ides"
FROM DUAL;
Ides
------------------
3RD of April, 1998
SELECT TO_CHAR(SYSDATE, 'DDTH')||' of '||
TO_CHAR(SYSDATE, 'Month')||', '||
TO_CHAR(SYSDATE, 'YYYY') "Ides"
FROM DUAL;
Ides
-----------------------
03RD of April , 1998
SELECT TO_CHAR(SYSDATE, 'fmDay')||'''s Special' "Menu"
FROM DUAL;
Menu
-----------------
Tuesday's Special
参考:
[1]: https://docs.oracle.com/cd/B19306_01/server.102/b14200/sql_elements004.htm#i34924 'Oracle Format Models'
[2]: https://www.cnblogs.com/reborter/archive/2008/11/28/1343195.html 'Oracle to_char格式化函数'
oracle 日期格式化 TO_CHAR (datetime) 修饰语和后缀的更多相关文章
- Oracle日期格式化以及extract函数的使用
由于业务需要,这两天在学习Oracle,发现Oracle里面的日期它会给你转成一种很不习惯的格式,于是想着怎么样把它弄成年.月.日的格式来显示,查资料.看文档,最终找到解决办法了,其实是用到了to_c ...
- oracle日期格式化
TO_CHAR(t.CAMERA_CREAT_TIME, 'YYYY-MM-DD HH24:MI:SS') as point_registerdate,TO_CHAR(t.CAMERA_MODIFY_ ...
- oracle 日期格式化和数据去重
1.获取系统日期: select sysdate as date1 from dual: 当前时间减去7分钟的时间 select sysdate,sysdate - interval '7' MINU ...
- Oracle 英文 非标准格式 日期 格式化
最近在处理一张表的时候,需要按照日期排序,日期字段中日期的格式有两种. 格式一:07-Aug-2015 格式二:10/28/16 日期转化及格式化sql语句: select to_date('07-A ...
- C# DateTime日期格式化
在C#中DateTime是一个包含日期.时间的类型,此类型通过ToString()转换为字符串时,可根据传入给Tostring()的参数转换为多种字符串格式. 目录 1. 分类 2. 制式类型 3. ...
- django datetime format 日期格式化
django datetime format 日期格式化 www.jx-lab.com python 中 date,datetime,time对象都支持strftime(format)方法,但有一些区 ...
- Python时间日期格式化之time与datetime模块总结
1 引言 在实际开发过程中,我们经常会用到日期或者时间,那么在Python中我们怎么获取时间,以及如何将时间转换为我们需要的格式呢?在之前的开发中,也曾遇到time.datetime等模块下的不同函数 ...
- c#根据当前时间获取本周,本月,本年度等时间段和DateTime日期格式化
DateTime dt = DateTime.Now; //当前时间 DateTime startWeek = dt.AddDays( - Convert.ToInt32(dt.DayOfWeek.T ...
- ORACLE——日期时间格式化参数详解 之一
2.日期格式化参数详解 2.1 -/,.;: 指定返回字串分隔符 SQL> select to_char(sysdate,'yyyy.mm.dd') from dual; TO_CHAR(SYS ...
随机推荐
- zabbix报错cannot set resource limit: [13] Permission denied解决方法
zabbix-server启动时出现以下错误: 2912:20180326:050930.023 using configuration file: /etc/zabbix/zabbix_server ...
- mysql 开发进阶篇系列 29 数据库二进制包安装
概述 对于二进制安装,优点是可以安装到任何路径下,灵活性好,一台服务器可以安装多个mysql.缺点是已经绎过编译,性能不如源码编译得好,不能灵活定制编译参数.如果用户即不想安装最简单却不够灵活的RPM ...
- Java后端学习路线图,你真的只需要这一张!
前言 学习路线图往往是学习一样技术的入门指南.网上搜到的Java学习路线图也是一抓一大把. 今天我只选一张图,仅此一图,足以包罗Java后端技术的知识点.所谓不求最好,但求最全,学习Java ...
- Linux_CentOS-服务器搭建 <六>
修改MySQL编码: 二话不说先登录: mysql -u root -p 查看下神奇的mysql系统变量及其值: show variables like '%character%'; //记住分号哦, ...
- 从零开始学 Web 之 ES6(六)ES6基础语法四
大家好,这里是「 从零开始学 Web 系列教程 」,并在下列地址同步更新...... github:https://github.com/Daotin/Web 微信公众号:Web前端之巅 博客园:ht ...
- Feign自定义编程配置
介绍 在Spring Cloud中,Feign的默认配置类是FeignClientsConfiguration,该类定义了Feigh默认使用的编码器.解码器.所使用的契约等.Spring Cloud允 ...
- 一个电脑的重装到java开发环境安装配置的全过程
刚拿到一台别人用过的电脑.看着c盘爆满,而且用了还是windows7操作系统,强迫症发作马上就准备重装系统. 之前换固态使用wepe制作U盘启动盘装系统的步骤和过程全部忘记的,贼尴尬. 同事都看不过眼 ...
- vue-03-style与class
1, 绑定html class 1), 直接绑定 <div> isActive 为true, 则显示 active css <p v-bind:class="{active ...
- visual studio code (vsc)中查看 php 数组的全部元素
在 vsc 调试 php 时,如果数组元素过多,只能查看前面 30个左右的元素,如果需要看更多的元素,可以配置 xDebugSettings 修改项目中的 .vscode/launch.json 文件 ...
- C#读取Cookie
public class HttpCookie { [DllImport("wininet.dll", CharSet = CharSet.Auto, SetLastError = ...