{"id":94430,"date":"2024-10-19T19:12:17","date_gmt":"2024-10-19T11:12:17","guid":{"rendered":"https:\/\/server.hk\/cnblog\/94430\/"},"modified":"2024-10-19T19:12:18","modified_gmt":"2024-10-19T11:12:18","slug":"oracle-to_char%e5%87%bd%e6%95%b8%e5%85%b7%e6%9c%89%e5%bc%b7%e5%a4%a7%e7%9a%84%e5%8a%9f%e8%83%bd","status":"publish","type":"post","link":"https:\/\/server.hk\/cnblog\/94430\/","title":{"rendered":"Oracle to_char()\u51fd\u6578\u5177\u6709\u5f37\u5927\u7684\u529f\u80fd"},"content":{"rendered":"<h1 id=\"oracle-to_char%e5%87%bd%e6%95%b8%e5%85%b7%e6%9c%89%e5%bc%b7%e5%a4%a7%e7%9a%84%e5%8a%9f%e8%83%bd-FbjSNdiBLU\">Oracle to_char()\u51fd\u6578\u5177\u6709\u5f37\u5927\u7684\u529f\u80fd<\/h1>\n<p>\u5728Oracle\u8cc7\u6599\u5eab\u4e2d\uff0c<code>to_char()<\/code>\u51fd\u6578\u662f\u4e00\u500b\u975e\u5e38\u91cd\u8981\u4e14\u5f37\u5927\u7684\u5de5\u5177\uff0c\u4e3b\u8981\u7528\u65bc\u5c07\u65e5\u671f\u548c\u6578\u5b57\u8f49\u63db\u70ba\u5b57\u4e32\u683c\u5f0f\u3002\u9019\u500b\u51fd\u6578\u7684\u9748\u6d3b\u6027\u548c\u591a\u6a23\u6027\u4f7f\u5f97\u5b83\u5728\u8cc7\u6599\u8655\u7406\u548c\u5831\u8868\u751f\u6210\u4e2d\u626e\u6f14\u8457\u95dc\u9375\u89d2\u8272\u3002\u672c\u6587\u5c07\u6df1\u5165\u63a2\u8a0e<code>to_char()<\/code>\u51fd\u6578\u7684\u529f\u80fd\u3001\u7528\u6cd5\u53ca\u5176\u5728\u5be6\u969b\u61c9\u7528\u4e2d\u7684\u793a\u4f8b\u3002<\/p>\n<h2 id=\"to_char%e5%87%bd%e6%95%b8%e7%9a%84%e5%9f%ba%e6%9c%ac%e8%aa%9e%e6%b3%95-FbjSNdiBLU\">to_char()\u51fd\u6578\u7684\u57fa\u672c\u8a9e\u6cd5<\/h2>\n<p><code>to_char()<\/code>\u51fd\u6578\u7684\u57fa\u672c\u8a9e\u6cd5\u5982\u4e0b\uff1a<\/p>\n<pre><code>to_char(value, format)<\/code><\/pre>\n<p>\u5176\u4e2d\uff0c<code>value<\/code>\u53ef\u4ee5\u662f\u65e5\u671f\u6216\u6578\u5b57\uff0c\u800c<code>format<\/code>\u5247\u662f\u6307\u5b9a\u8f38\u51fa\u683c\u5f0f\u7684\u5b57\u4e32\u3002\u9019\u4f7f\u5f97\u4f7f\u7528\u8005\u53ef\u4ee5\u6839\u64da\u9700\u6c42\u81ea\u5b9a\u7fa9\u8f38\u51fa\u7684\u6a23\u5f0f\u3002<\/p>\n<h2 id=\"%e6%97%a5%e6%9c%9f%e8%bd%89%e6%8f%9b-FbjSNdiBLU\">\u65e5\u671f\u8f49\u63db<\/h2>\n<p>\u5728\u8655\u7406\u65e5\u671f\u6642\uff0c<code>to_char()<\/code>\u51fd\u6578\u53ef\u4ee5\u5c07\u65e5\u671f\u8f49\u63db\u70ba\u7279\u5b9a\u683c\u5f0f\u7684\u5b57\u4e32\u3002\u4f8b\u5982\uff0c\u5047\u8a2d\u6211\u5011\u6709\u4e00\u500b\u65e5\u671f\uff0c\u60f3\u8981\u5c07\u5176\u683c\u5f0f\u5316\u70ba\u201cYYYY-MM-DD\u201d\u7684\u5f62\u5f0f\uff0c\u53ef\u4ee5\u4f7f\u7528\u4ee5\u4e0b\u8a9e\u53e5\uff1a<\/p>\n<pre><code>SELECT to_char(SYSDATE, 'YYYY-MM-DD') AS formatted_date FROM dual;<\/code><\/pre>\n<p>\u9019\u5c07\u8fd4\u56de\u7576\u524d\u65e5\u671f\u7684\u5b57\u4e32\u8868\u793a\uff0c\u683c\u5f0f\u70ba\u201c2023-10-01\u201d\u3002<\/p>\n<h3 id=\"%e5%b8%b8%e7%94%a8%e7%9a%84%e6%97%a5%e6%9c%9f%e6%a0%bc%e5%bc%8f%e5%8c%96%e9%81%b8%e9%a0%85-FbjSNdiBLU\">\u5e38\u7528\u7684\u65e5\u671f\u683c\u5f0f\u5316\u9078\u9805<\/h3>\n<ul>\n<li><code>YYYY<\/code> &#8211; \u56db\u4f4d\u6578\u5e74\u4efd<\/li>\n<li><code>MM<\/code> &#8211; \u5169\u4f4d\u6578\u6708\u4efd<\/li>\n<li><code>DD<\/code> &#8211; \u5169\u4f4d\u6578\u65e5\u671f<\/li>\n<li><code>HH24<\/code> &#8211; 24\u5c0f\u6642\u5236\u7684\u6642<\/li>\n<li><code>MI<\/code> &#8211; \u5206\u9418<\/li>\n<li><code>SS<\/code> &#8211; \u79d2<\/li>\n<\/ul>\n<p>\u4f8b\u5982\uff0c\u82e5\u8981\u986f\u793a\u5b8c\u6574\u7684\u65e5\u671f\u548c\u6642\u9593\uff0c\u53ef\u4ee5\u4f7f\u7528\uff1a<\/p>\n<pre><code>SELECT to_char(SYSDATE, 'YYYY-MM-DD HH24:MI:SS') AS formatted_datetime FROM dual;<\/code><\/pre>\n<h2 id=\"%e6%95%b8%e5%ad%97%e8%bd%89%e6%8f%9b-FbjSNdiBLU\">\u6578\u5b57\u8f49\u63db<\/h2>\n<p>\u9664\u4e86\u65e5\u671f\uff0c<code>to_char()<\/code>\u51fd\u6578\u4e5f\u53ef\u4ee5\u7528\u65bc\u6578\u5b57\u7684\u683c\u5f0f\u5316\u3002\u9019\u5728\u751f\u6210\u5831\u8868\u6642\u7279\u5225\u6709\u7528\u3002\u4f8b\u5982\uff0c\u82e5\u8981\u5c07\u4e00\u500b\u6578\u5b57\u683c\u5f0f\u5316\u70ba\u8ca8\u5e63\u5f62\u5f0f\uff0c\u53ef\u4ee5\u4f7f\u7528\uff1a<\/p>\n<pre><code>SELECT to_char(12345.67, 'FM$99999.00') AS formatted_number FROM dual;<\/code><\/pre>\n<p>\u9019\u5c07\u8fd4\u56de\u201c$12345.67\u201d\u3002\u5728\u9019\u88e1\uff0c<code>FM<\/code>\u524d\u7db4\u7528\u65bc\u53bb\u9664\u524d\u5c0e\u7a7a\u683c\u3002<\/p>\n<h3 id=\"%e6%95%b8%e5%ad%97%e6%a0%bc%e5%bc%8f%e5%8c%96%e9%81%b8%e9%a0%85-FbjSNdiBLU\">\u6578\u5b57\u683c\u5f0f\u5316\u9078\u9805<\/h3>\n<ul>\n<li><code>9<\/code> &#8211; \u4ee3\u8868\u6578\u5b57\u7684\u4f4d\u7f6e<\/li>\n<li><code>0<\/code> &#8211; \u4ee3\u8868\u5fc5\u9808\u986f\u793a\u7684\u6578\u5b57<\/li>\n<li><code>.<\/code> &#8211; \u5c0f\u6578\u9ede<\/li>\n<li><code>$<\/code> &#8211; \u8ca8\u5e63\u7b26\u865f<\/li>\n<\/ul>\n<p>\u9019\u4e9b\u683c\u5f0f\u5316\u9078\u9805\u4f7f\u5f97<code>to_char()<\/code>\u51fd\u6578\u5728\u6578\u5b57\u8655\u7406\u4e0a\u975e\u5e38\u9748\u6d3b\u3002<\/p>\n<h2 id=\"%e5%af%a6%e9%9a%9b%e6%87%89%e7%94%a8%e6%a1%88%e4%be%8b-FbjSNdiBLU\">\u5be6\u969b\u61c9\u7528\u6848\u4f8b<\/h2>\n<p>\u5728\u5be6\u969b\u61c9\u7528\u4e2d\uff0c<code>to_char()<\/code>\u51fd\u6578\u53ef\u4ee5\u7528\u65bc\u751f\u6210\u5831\u8868\u3001\u6578\u64da\u5206\u6790\u53ca\u8cc7\u6599\u5c55\u793a\u7b49\u591a\u7a2e\u5834\u666f\u3002\u4f8b\u5982\uff0c\u5728\u4e00\u500b\u92b7\u552e\u5831\u8868\u4e2d\uff0c\u60a8\u53ef\u80fd\u9700\u8981\u5c07\u92b7\u552e\u65e5\u671f\u548c\u91d1\u984d\u683c\u5f0f\u5316\u70ba\u6613\u65bc\u95b1\u8b80\u7684\u5f62\u5f0f\u3002\u4ee5\u4e0b\u662f\u4e00\u500b\u7c21\u55ae\u7684\u67e5\u8a62\u793a\u4f8b\uff1a<\/p>\n<pre><code>SELECT \n    to_char(sale_date, 'YYYY-MM-DD') AS sale_date,\n    to_char(sale_amount, 'FM$99999.00') AS sale_amount\nFROM sales;<\/code><\/pre>\n<p>\u9019\u6a23\u7684\u67e5\u8a62\u5c07\u4f7f\u5f97\u5831\u8868\u66f4\u52a0\u6e05\u6670\u6613\u61c2\u3002<\/p>\n<h2 id=\"%e7%b8%bd%e7%b5%90-FbjSNdiBLU\">\u7e3d\u7d50<\/h2>\n<p>Oracle\u7684<code>to_char()<\/code>\u51fd\u6578\u63d0\u4f9b\u4e86\u5f37\u5927\u7684\u529f\u80fd\uff0c\u80fd\u5920\u9748\u6d3b\u5730\u5c07\u65e5\u671f\u548c\u6578\u5b57\u8f49\u63db\u70ba\u5b57\u4e32\u683c\u5f0f\u3002\u7121\u8ad6\u662f\u5728\u8cc7\u6599\u8655\u7406\u3001\u5831\u8868\u751f\u6210\u9084\u662f\u6578\u64da\u5206\u6790\u4e2d\uff0c\u9019\u500b\u51fd\u6578\u90fd\u80fd\u5920\u5e6b\u52a9\u4f7f\u7528\u8005\u4ee5\u66f4\u76f4\u89c0\u7684\u65b9\u5f0f\u5c55\u793a\u8cc7\u6599\u3002\u900f\u904e\u638c\u63e1<code>to_char()<\/code>\u7684\u4f7f\u7528\uff0c\u958b\u767c\u8005\u53ef\u4ee5\u63d0\u5347\u8cc7\u6599\u5eab\u64cd\u4f5c\u7684\u6548\u7387\u548c\u6e96\u78ba\u6027\u3002<\/p>\n<p>\u5982\u9700\u4e86\u89e3\u66f4\u591a\u6709\u95dc<code>VPS<\/code>\u3001<a href=\"https:\/\/server.hk\">\u9999\u6e2fVPS<\/a>\u53ca\u5176\u4ed6\u76f8\u95dc\u670d\u52d9\u7684\u4fe1\u606f\uff0c\u8acb\u8a2a\u554f\u6211\u5011\u7684\u7db2\u7ad9\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u63a2\u7d22Oracle to_char()\u51fd\u6578\u7684\u5f37\u5927\u529f\u80fd\uff0c\u8f15\u9b06\u683c\u5f0f\u5316\u65e5\u671f\u548c\u6578\u5b57\uff0c\u63d0\u5347\u6578\u64da\u8655\u7406\u6548\u7387\u8207\u53ef\u8b80\u6027\u3002<\/p>\n","protected":false},"author":0,"featured_media":0,"comment_status":"closed","ping_status":"","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[101],"tags":[],"class_list":["post-94430","post","type-post","status-publish","format-standard","hentry","category-database"],"_links":{"self":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/94430","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/types\/post"}],"replies":[{"embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/comments?post=94430"}],"version-history":[{"count":1,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/94430\/revisions"}],"predecessor-version":[{"id":94431,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/94430\/revisions\/94431"}],"wp:attachment":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/media?parent=94430"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/categories?post=94430"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/tags?post=94430"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}