使用to_char函数解析为字符串时,如何从Oracle中的日和月值中删除前导零? [英] How to remove leading zeroes from day and month values in Oracle, when parsing to string using to_char function?
问题描述
我想检索一个select语句中日期和月份值前无前导零的日期.如果我执行以下查询
I want to retrieve a date without the leading zeroes in front of the day and month values in a select statement. If I execute the following query
select to_char(sysdate, 'dd.mm.yyyy') from dual;
结果我将获得21.03.2014的结果.此外,如果今天是2014年3月7日,那么我会得到07.03.2014.如何摆脱这些前导零?
I will get 21.03.2014 as a result. Moreover, if today was, for example, 7th of March, 2014, I would get 07.03.2014. How can I get rid of these leading zeroes?
推荐答案
select to_char(sysdate,'DD.MM.YY') -- Without Fill Mode
, to_char(sysdate-20,'fmDD.fmMM.YY') -- With Fill Mode, 20 days ago
from dual;
返回
21.03.14 | 1.3.14
FM填充模式.
在TO_CHAR函数的日期时间格式元素中,此修饰符可抑制后续字符元素(例如MONTH)中的空格,并抑制日期格式模型中后续数字元素(例如MI)的前导零.如果不使用FM,则始终用空白将字符元素的结果正确填充到固定长度,并且始终为数字元素返回前导零.使用FM抑制空白填充时,返回值的长度可能会有所不同.
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.
这篇关于使用to_char函数解析为字符串时,如何从Oracle中的日和月值中删除前导零?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!