<?xml version="1.0" encoding="utf-8" standalone="yes"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:trackback="http://madskills.com/public/xml/rss/module/trackback/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/"><channel><title>BlogJava-apple0668-随笔分类-oracle</title><link>http://www.blogjava.net/apple0668/category/35166.html</link><description>上善若水，水善利万物而不争，处众人之所恶而不争，故几于道——《老子》</description><language>zh-cn</language><lastBuildDate>Mon, 13 Oct 2008 14:21:05 GMT</lastBuildDate><pubDate>Mon, 13 Oct 2008 14:21:05 GMT</pubDate><ttl>60</ttl><item><title>&lt;转&gt;Oracle中常用的to_Char用法详解（有FMT的详细列表）</title><link>http://www.blogjava.net/apple0668/archive/2008/10/13/234110.html</link><dc:creator>apple0668</dc:creator><author>apple0668</author><pubDate>Mon, 13 Oct 2008 13:48:00 GMT</pubDate><guid>http://www.blogjava.net/apple0668/archive/2008/10/13/234110.html</guid><wfw:comment>http://www.blogjava.net/apple0668/comments/234110.html</wfw:comment><comments>http://www.blogjava.net/apple0668/archive/2008/10/13/234110.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/apple0668/comments/commentRss/234110.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/apple0668/services/trackbacks/234110.html</trackback:ping><description><![CDATA[<p>以下内容转自网络，感觉这个比较有用。收藏一下。<br />
<br />
The following are number examples for the <strong>to_char</strong> function.</p>
<blockquote>
<table cellspacing="0" cellpadding="3" width="432" border="0">
    <tbody>
        <tr>
            <td class="function_example" width="207">to_char(1210.73, '9999.9')</td>
            <td class="function_desc">would return '1210.7'</td>
        </tr>
        <tr>
            <td class="function_example">to_char(1210.73, '9,999.99')</td>
            <td class="function_desc">would return '1,210.73'</td>
        </tr>
        <tr>
            <td class="function_example">to_char(1210.73, '$9,999.00')</td>
            <td class="function_desc">would return '$1,210.73'</td>
        </tr>
        <tr>
            <td class="function_example">to_char(21, '000099')</td>
            <td class="function_desc">would return '000021'</td>
        </tr>
    </tbody>
</table>
</blockquote>
<p>&nbsp;</p>
<p>The following is a list of valid parameters when the <strong>to_char</strong> function is used to convert a date to a string. These parameters can be used in many combinations.</p>
<blockquote>
<table class="parm_values" cellspacing="0" cellpadding="3" width="500" border="1">
    <tbody>
        <tr class="th_left_top">
            <th width="93">Parameter</th>
            <th>Explanation</th>
        </tr>
        <tr class="tr_left_top">
            <td>YEAR</td>
            <td>Year, spelled out</td>
        </tr>
        <tr class="tr_left_top">
            <td>YYYY</td>
            <td>4-digit year</td>
        </tr>
        <tr class="tr_left_top">
            <td>YYY<br />
            YY<br />
            Y</td>
            <td>Last 3, 2, or 1 digit(s) of year.</td>
        </tr>
        <tr class="tr_left_top">
            <td>IYY<br />
            IY<br />
            I</td>
            <td>Last 3, 2, or 1 digit(s) of ISO year.</td>
        </tr>
        <tr class="tr_left_top">
            <td>IYYY</td>
            <td>4-digit year based on the ISO standard</td>
        </tr>
        <tr class="tr_left_top">
            <td>Q</td>
            <td>Quarter of year (1, 2, 3, 4; JAN-MAR = 1).</td>
        </tr>
        <tr class="tr_left_top">
            <td>MM</td>
            <td>Month (01-12; JAN = 01).</td>
        </tr>
        <tr class="tr_left_top">
            <td>MON</td>
            <td>Abbreviated name of month.</td>
        </tr>
        <tr class="tr_left_top">
            <td>MONTH</td>
            <td>Name of month, padded with blanks to length of 9 characters.</td>
        </tr>
        <tr class="tr_left_top">
            <td>RM</td>
            <td>Roman numeral month (I-XII; JAN = I).</td>
        </tr>
        <tr class="tr_left_top">
            <td>WW</td>
            <td>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.</td>
        </tr>
        <tr class="tr_left_top">
            <td>W</td>
            <td>Week of month (1-5) where week 1 starts on the first day of the month and ends on the seventh.</td>
        </tr>
        <tr class="tr_left_top">
            <td>IW</td>
            <td>Week of year (1-52 or 1-53) based on the ISO standard.</td>
        </tr>
        <tr class="tr_left_top">
            <td>D</td>
            <td>Day of week (1-7).</td>
        </tr>
        <tr class="tr_left_top">
            <td>DAY</td>
            <td>Name of day.</td>
        </tr>
        <tr class="tr_left_top">
            <td>DD</td>
            <td>Day of month (1-31).</td>
        </tr>
        <tr class="tr_left_top">
            <td>DDD</td>
            <td>Day of year (1-366).</td>
        </tr>
        <tr class="tr_left_top">
            <td>DY</td>
            <td>Abbreviated name of day.</td>
        </tr>
        <tr class="tr_left_top">
            <td>J</td>
            <td>Julian day; the number of days since January 1, 4712 BC.</td>
        </tr>
        <tr class="tr_left_top">
            <td>HH</td>
            <td>Hour of day (1-12).</td>
        </tr>
        <tr class="tr_left_top">
            <td>HH12</td>
            <td>Hour of day (1-12).</td>
        </tr>
        <tr class="tr_left_top">
            <td>HH24</td>
            <td>Hour of day (0-23).</td>
        </tr>
        <tr class="tr_left_top">
            <td>MI</td>
            <td>Minute (0-59).</td>
        </tr>
        <tr class="tr_left_top">
            <td>SS</td>
            <td>Second (0-59).</td>
        </tr>
        <tr class="tr_left_top">
            <td>SSSSS</td>
            <td>Seconds past midnight (0-86399).</td>
        </tr>
        <tr class="tr_left_top">
            <td>FF</td>
            <td>Fractional seconds.</td>
        </tr>
    </tbody>
</table>
</blockquote>
<p><br />
</p>
<p>The following are date examples for the <strong>to_char</strong> function.</p>
<blockquote>
<table cellspacing="0" cellpadding="3" width="460" border="0">
    <tbody>
        <tr>
            <td class="function_example" width="253">to_char(sysdate, 'yyyy/mm/dd');</td>
            <td class="function_desc">would return '2003/07/09'</td>
        </tr>
        <tr>
            <td class="function_example">to_char(sysdate, 'Month DD, YYYY');</td>
            <td class="function_desc">would return 'July 09, 2003'</td>
        </tr>
        <tr>
            <td class="function_example">to_char(sysdate, 'FMMonth DD, YYYY');</td>
            <td class="function_desc">would return 'July 9, 2003'</td>
        </tr>
        <tr>
            <td class="function_example">to_char(sysdate, 'MON DDth, YYYY');</td>
            <td class="function_desc">would return 'JUL 09TH, 2003'</td>
        </tr>
        <tr>
            <td class="function_example">to_char(sysdate, 'FMMON DDth, YYYY');</td>
            <td class="function_desc">would return 'JUL 9TH, 2003'</td>
        </tr>
        <tr>
            <td class="function_example">to_char(sysdate, 'FMMon ddth, YYYY');</td>
            <td class="function_desc">would return 'Jul 9th, 2003'</td>
        </tr>
    </tbody>
</table>
</blockquote>
<p><br />
</p>
<p>You will notice that in some examples, the <em>format_mask</em> parameter begins with "FM". This means that zeros and blanks are suppressed. This can be seen in the examples below.</p>
<blockquote>
<table cellspacing="0" cellpadding="3" width="460" border="0">
    <tbody>
        <tr>
            <td class="function_example" width="253">to_char(sysdate, 'FMMonth DD, YYYY');</td>
            <td class="function_desc">would return 'July 9, 2003'</td>
        </tr>
        <tr>
            <td class="function_example">to_char(sysdate, 'FMMON DDth, YYYY');</td>
            <td class="function_desc">would return 'JUL 9TH, 2003'</td>
        </tr>
        <tr>
            <td class="function_example">to_char(sysdate, 'FMMon ddth, YYYY');</td>
            <td class="function_desc">would return 'Jul 9th, 2003'</td>
        </tr>
    </tbody>
</table>
</blockquote>
<p>The zeros have been suppressed so that the day component shows as "9" as opposed to "09".</p>
<br />
<p id="TBPingURL"><strong>Oracle函数to_char转化数字型指定小数点位数的用法</strong><br />
</p>
<p>to_char，函数功能，就是将数值型或者日期型转化为字符型。</p>
<p>比如最简单的应用：</p>
<div style="border-right: #8a8a8a 1px solid; padding-right: 6px; border-top: #8a8a8a 1px solid; padding-left: 6px; font-size: 12px; padding-bottom: 6px; margin: 1px; overflow: auto; border-left: #8a8a8a 1px solid; padding-top: 6px; border-bottom: #8a8a8a 1px solid"><span style="color: #008000">/*1.0123---&gt;'1.0123'*/</span> <br />
<span style="color: #0000ff">Select</span>&nbsp;<span style="color: #0000ff">TO_CHAR</span>(1.0123)&nbsp;<span style="color: #0000ff">FROM</span>&nbsp;<span style="color: #0000ff">DUAL</span> <br />
<span style="color: #008000">/*123---&gt;'123'*/</span> <br />
<span style="color: #0000ff">Select</span>&nbsp;<span style="color: #0000ff">TO_CHAR</span>(123)&nbsp;<span style="color: #0000ff">FROM</span>&nbsp;<span style="color: #0000ff">DUAL</span></div>
<p>&nbsp;接下来再看看下面