我想以格式输出当前日期:
1-1-2015
所以没有这个例子中的零:
SELECT TO_CHAR(SYSDATE, 'DD-MM-YYYY') AS today
FROM dual
输出:
17-06-2015
答案 0 :(得分:7)
你可以在MM之前使用fm。
查询
SELECT TO_CHAR (SYSDATE, 'DD-fmMM-YYYY') AS today FROM dual;
输出
17-6-2015
http://docs.oracle.com/cd/B28359_01/server.111/b28286/sql_elements004.htm#SQLRF00216
添加:
删除所有前导零:
SELECT TO_CHAR (TO_DATE('01-01-2015', 'DD-MM-YYYY'), 'fmDD-MM-YYYY') AS today FROM dual;
1-1-2015
从月号中删除前导零:
SELECT TO_CHAR (TO_DATE('01-01-2015', 'DD-MM-YYYY'), 'DD-fmMM-YYYY') AS today FROM dual;
01-1-2015
fm用作开关。在这个例子中,DD很好,但MM再次具有前导零。
SELECT TO_CHAR (TO_DATE('01-01-2015', 'DD-MM-YYYY'), 'fmDD-fmMM-YYYY') AS today FROM dual;
1-01-2015
答案 1 :(得分:0)
SELECT TO_CHAR (SYSDATE, 'fmDD-fmMM-YYYY') AS today FROM dual
FM是填充模式,您可以找到更多信息here