{"id":94432,"date":"2024-10-19T19:13:16","date_gmt":"2024-10-19T11:13:16","guid":{"rendered":"https:\/\/server.hk\/cnblog\/94432\/"},"modified":"2024-10-19T19:13:17","modified_gmt":"2024-10-19T11:13:17","slug":"oracle-to_char%e7%9a%84%e7%94%a8%e6%b3%95%e6%8f%8f%e8%bf%b0","status":"publish","type":"post","link":"https:\/\/server.hk\/cnblog\/94432\/","title":{"rendered":"Oracle to_char\u7684\u7528\u6cd5\u63cf\u8ff0"},"content":{"rendered":"<h1 id=\"oracle-to_char%e7%9a%84%e7%94%a8%e6%b3%95%e6%8f%8f%e8%bf%b0-YOzIxSpPxR\">Oracle to_char\u7684\u7528\u6cd5\u63cf\u8ff0<\/h1>\n<p>\u5728Oracle\u6570\u636e\u5e93\u4e2d\uff0c<code>to_char<\/code>\u51fd\u6578\u662f\u4e00\u500b\u975e\u5e38\u91cd\u8981\u7684\u5de5\u5177\uff0c\u4e3b\u8981\u7528\u65bc\u5c07\u65e5\u671f\u548c\u6578\u5b57\u8f49\u63db\u70ba\u5b57\u7b26\u578b\u614b\u3002\u9019\u500b\u51fd\u6578\u7684\u9748\u6d3b\u6027\u4f7f\u5f97\u5b83\u5728\u6578\u64da\u683c\u5f0f\u5316\u548c\u5831\u544a\u751f\u6210\u4e2d\u626e\u6f14\u8457\u95dc\u9375\u89d2\u8272\u3002\u672c\u6587\u5c07\u6df1\u5165\u63a2\u8a0e<code>to_char<\/code>\u7684\u7528\u6cd5\uff0c\u5305\u62ec\u5176\u8a9e\u6cd5\u3001\u53c3\u6578\u4ee5\u53ca\u5be6\u969b\u61c9\u7528\u793a\u4f8b\u3002<\/p>\n<h2 id=\"to_char%e5%87%bd%e6%95%b8%e7%9a%84%e8%aa%9e%e6%b3%95-YOzIxSpPxR\">to_char\u51fd\u6578\u7684\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\u7528\u4f86\u6307\u5b9a\u8f38\u51fa\u683c\u5f0f\u7684\u5b57\u7b26\u4e32\u3002\u6839\u64da\u4e0d\u540c\u7684\u9700\u6c42\uff0c<code>format<\/code>\u7684\u5167\u5bb9\u6703\u6709\u6240\u4e0d\u540c\u3002<\/p>\n<h2 id=\"%e6%97%a5%e6%9c%9f%e8%bd%89%e6%8f%9b-YOzIxSpPxR\">\u65e5\u671f\u8f49\u63db<\/h2>\n<p>\u7576<code>value<\/code>\u70ba\u65e5\u671f\u578b\u614b\u6642\uff0c<code>to_char<\/code>\u51fd\u6578\u53ef\u4ee5\u7528\u4f86\u683c\u5f0f\u5316\u65e5\u671f\u3002\u4ee5\u4e0b\u662f\u4e00\u4e9b\u5e38\u898b\u7684\u65e5\u671f\u683c\u5f0f\uff1a<\/p>\n<ul>\n<li><code>YYYY<\/code> &#8211; \u56db\u4f4d\u6578\u5e74\u4efd<\/li>\n<li><code>MM<\/code> &#8211; \u6708\u4efd\uff0801-12\uff09<\/li>\n<li><code>DD<\/code> &#8211; \u65e5\u671f\uff0801-31\uff09<\/li>\n<li><code>HH24<\/code> &#8211; 24\u5c0f\u6642\u5236\u7684\u6642\uff0800-23\uff09<\/li>\n<li><code>MI<\/code> &#8211; \u5206\u9418\uff0800-59\uff09<\/li>\n<li><code>SS<\/code> &#8211; \u79d2\uff0800-59\uff09<\/li>\n<\/ul>\n<p>\u4f8b\u5982\uff0c\u82e5\u8981\u5c07\u7576\u524d\u65e5\u671f\u683c\u5f0f\u5316\u70ba\u201cYYYY-MM-DD\u201d\u7684\u5f62\u5f0f\uff0c\u53ef\u4ee5\u4f7f\u7528\u4ee5\u4e0bSQL\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\u985e\u4f3c\u65bc\u201c2023-10-01\u201d\u7684\u7d50\u679c\u3002<\/p>\n<h2 id=\"%e6%95%b8%e5%ad%97%e8%bd%89%e6%8f%9b-YOzIxSpPxR\">\u6578\u5b57\u8f49\u63db<\/h2>\n<p>\u9664\u4e86\u65e5\u671f\uff0c<code>to_char<\/code>\u51fd\u6578\u4e5f\u53ef\u4ee5\u7528\u4f86\u683c\u5f0f\u5316\u6578\u5b57\u3002\u5e38\u898b\u7684\u6578\u5b57\u683c\u5f0f\u5305\u62ec\uff1a<\/p>\n<ul>\n<li><code>9<\/code> &#8211; \u6578\u5b57\u4f54\u4f4d\u7b26<\/li>\n<li><code>0<\/code> &#8211; \u6578\u5b57\u4f54\u4f4d\u7b26\uff0c\u82e5\u6578\u5b57\u4e0d\u8db3\u5247\u75280\u586b\u5145<\/li>\n<li><code>.<\/code> &#8211; \u5c0f\u6578\u9ede<\/li>\n<li><code>,<\/code> &#8211; \u5343\u4f4d\u5206\u9694\u7b26<\/li>\n<\/ul>\n<p>\u4f8b\u5982\uff0c\u82e5\u8981\u5c07\u6578\u5b571234567.89\u683c\u5f0f\u5316\u70ba\u201c1,234,567.89\u201d\uff0c\u53ef\u4ee5\u4f7f\u7528\u4ee5\u4e0bSQL\u8a9e\u53e5\uff1a<\/p>\n<pre><code>SELECT to_char(1234567.89, '9,999,999.99') AS formatted_number FROM dual;<\/code><\/pre>\n<p>\u9019\u5c07\u8fd4\u56de\u201c1,234,567.89\u201d\u7684\u7d50\u679c\u3002<\/p>\n<h2 id=\"%e4%bd%bf%e7%94%a8%e7%af%84%e4%be%8b-YOzIxSpPxR\">\u4f7f\u7528\u7bc4\u4f8b<\/h2>\n<p>\u4ee5\u4e0b\u662f\u4e00\u4e9b<code>to_char<\/code>\u51fd\u6578\u7684\u5be6\u969b\u61c9\u7528\u7bc4\u4f8b\uff1a<\/p>\n<h3 id=\"%e7%af%84%e4%be%8b1%ef%bc%9a%e6%a0%bc%e5%bc%8f%e5%8c%96%e6%97%a5%e6%9c%9f-YOzIxSpPxR\">\u7bc4\u4f8b1\uff1a\u683c\u5f0f\u5316\u65e5\u671f<\/h3>\n<pre><code>SELECT to_char(SYSDATE, 'YYYY\/MM\/DD HH24:MI:SS') AS formatted_date FROM dual;<\/code><\/pre>\n<p>\u9019\u5c07\u8fd4\u56de\u7576\u524d\u65e5\u671f\u548c\u6642\u9593\uff0c\u683c\u5f0f\u70ba\u201cYYYY\/MM\/DD HH24:MI:SS\u201d\u3002<\/p>\n<h3 id=\"%e7%af%84%e4%be%8b2%ef%bc%9a%e6%a0%bc%e5%bc%8f%e5%8c%96%e6%95%b8%e5%ad%97-YOzIxSpPxR\">\u7bc4\u4f8b2\uff1a\u683c\u5f0f\u5316\u6578\u5b57<\/h3>\n<pre><code>SELECT to_char(9876543.21, '9,999,999.99') AS formatted_number FROM dual;<\/code><\/pre>\n<p>\u9019\u5c07\u8fd4\u56de\u201c9,876,543.21\u201d\u7684\u7d50\u679c\u3002<\/p>\n<h2 id=\"%e7%b8%bd%e7%b5%90-YOzIxSpPxR\">\u7e3d\u7d50<\/h2>\n<p>Oracle\u7684<code>to_char<\/code>\u51fd\u6578\u662f\u4e00\u500b\u5f37\u5927\u7684\u5de5\u5177\uff0c\u80fd\u5920\u9748\u6d3b\u5730\u5c07\u65e5\u671f\u548c\u6578\u5b57\u8f49\u63db\u70ba\u5b57\u7b26\u578b\u614b\uff0c\u4e26\u6839\u64da\u9700\u6c42\u9032\u884c\u683c\u5f0f\u5316\u3002\u7121\u8ad6\u662f\u5728\u5831\u544a\u751f\u6210\u9084\u662f\u6578\u64da\u5c55\u793a\u4e2d\uff0c<code>to_char<\/code>\u90fd\u80fd\u63d0\u4f9b\u6975\u5927\u7684\u4fbf\u5229\u3002\u5c0d\u65bc\u9700\u8981\u8655\u7406\u5927\u91cf\u6578\u64da\u7684\u958b\u767c\u8005\u548c\u6578\u64da\u5206\u6790\u5e2b\u4f86\u8aaa\uff0c\u638c\u63e1\u9019\u500b\u51fd\u6578\u7684\u7528\u6cd5\u662f\u975e\u5e38\u91cd\u8981\u7684\u3002<\/p>\n<p>\u5982\u679c\u60a8\u5c0d\u65bc<code>to_char<\/code>\u51fd\u6578\u7684\u4f7f\u7528\u6709\u9032\u4e00\u6b65\u7684\u9700\u6c42\uff0c\u6216\u662f\u9700\u8981\u5c0b\u627e\u5408\u9069\u7684<code><a href=\"https:\/\/server.hk\">VPS<\/a><\/code>\u89e3\u6c7a\u65b9\u6848\uff0c\u6b61\u8fce\u8a2a\u554f\u6211\u5011\u7684\u7db2\u7ad9\u4ee5\u7372\u53d6\u66f4\u591a\u8cc7\u8a0a\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u4e86\u89e3Oracle\u4e2dto_char\u51fd\u6570\u7684\u7528\u6cd5\uff0c\u638c\u63e1\u65e5\u671f\u548c\u6570\u5b57\u683c\u5f0f\u5316\u6280\u5de7\uff0c\u63d0\u5347\u6570\u636e\u5904\u7406\u6548\u7387\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-94432","post","type-post","status-publish","format-standard","hentry","category-database"],"_links":{"self":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/94432","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=94432"}],"version-history":[{"count":1,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/94432\/revisions"}],"predecessor-version":[{"id":94433,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/94432\/revisions\/94433"}],"wp:attachment":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/media?parent=94432"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/categories?post=94432"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/tags?post=94432"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}