zoukankan      html  css  js  c++  java
  • 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格式化函数'

  • 相关阅读:
    高质量图形库:pixellib
    有了 Docker,用 JavaScript 框架开发的 Web 站点也能很好地支持网络爬虫的内容抓取
    Freebie: Material Design UI Kit
    Git 10 周年之际,创始人 Linus Torvalds 访谈
    React.js 样式组件:React Style
    有趣 GIF 动图集
    10个免费开源的JS音乐播放器插件
    简约的单页应用引擎:sonnyJS
    2015年4月 非常干货之Python资源大全
    评论 ”[实例] 设计基于JQM的WebApp“
  • 原文地址:https://www.cnblogs.com/hyang0/p/10573183.html
Copyright © 2011-2022 走看看