{"id":5712,"date":"2024-11-14T10:06:57","date_gmt":"2024-11-14T02:06:57","guid":{"rendered":"https:\/\/fwq.ai\/blog\/5712\/"},"modified":"2024-11-14T10:06:57","modified_gmt":"2024-11-14T02:06:57","slug":"sql%e6%97%a5%e6%9c%9f%e6%a0%bc%e5%bc%8f%e5%8c%96%e6%80%8e%e4%b9%88%e8%ae%be%e7%bd%ae","status":"publish","type":"post","link":"https:\/\/fwq.ai\/blog\/5712\/","title":{"rendered":"sql\u65e5\u671f\u683c\u5f0f\u5316\u600e\u4e48\u8bbe\u7f6e"},"content":{"rendered":"<blockquote><p>\n  \u5728 sql \u4e2d\uff0c\u53ef\u4f7f\u7528 to_char() \u51fd\u6570\u683c\u5f0f\u5316\u65e5\u671f\u503c\uff0c\u5176\u8bed\u6cd5\u4e3a\uff1ato_char(\u65e5\u671f\u503c, \u683c\u5f0f\u5316\u5b57\u7b26\u4e32)\u3002\u683c\u5f0f\u5316\u5b57\u7b26\u4e32\u652f\u6301\u6307\u5b9a\u5e74\u4efd\u3001\u6708\u4efd\u3001\u65e5\u671f\u3001\u5c0f\u65f6\u3001\u5206\u949f\u3001\u79d2\u7b49\uff0c\u4f8b\u5982 yyyy\u3001mm\u3001dd \u7b49\u3002\u8fd8\u53ef\u4ee5\u76f4\u63a5\u5728 select \u8bed\u53e5\u4e2d\u4f7f\u7528\u5df2\u683c\u5f0f\u5316\u7684\u65e5\u671f\u503c\u3002\n<\/p><\/blockquote>\n<p><img decoding=\"async\" src=\"https:\/\/img.php.cn\/upload\/article\/202405\/30\/2024053021123546426.jpg\" class=\"aligncenter\" title=\"sql\u65e5\u671f\u683c\u5f0f\u5316\u600e\u4e48\u8bbe\u7f6e\u63d2\u56fe\" alt=\"sql\u65e5\u671f\u683c\u5f0f\u5316\u600e\u4e48\u8bbe\u7f6e\u63d2\u56fe\" \/><\/p>\n<p><strong>SQL \u65e5\u671f\u683c\u5f0f\u5316\u8bbe\u7f6e<\/strong><\/p>\n<p><strong>\u5982\u4f55\u8bbe\u7f6e SQL \u65e5\u671f\u683c\u5f0f\uff1f<\/strong><\/p>\n<p>\u5728 SQL \u4e2d\uff0c\u53ef\u4ee5\u4f7f\u7528 TO_CHAR() \u51fd\u6570\u6765\u683c\u5f0f\u5316\u65e5\u671f\u503c\u3002TO_CHAR() \u51fd\u6570\u7b2c\u4e00\u4e2a\u53c2\u6570\u6307\u5b9a\u8981\u8f6c\u6362\u7684\u65e5\u671f\u503c\uff0c\u7b2c\u4e8c\u4e2a\u53c2\u6570\u6307\u5b9a\u683c\u5f0f\u5316\u5b57\u7b26\u4e32\u3002<\/p>\n<p><strong>\u683c\u5f0f\u5316\u5b57\u7b26\u4e32\u8bed\u6cd5\uff1a<\/strong><\/p>\n<ul>\n<li>YYYY\uff1a\u5e74\u4efd\uff08\u4ee5\u56db\u4f4d\u6570\u5b57\u8868\u793a\uff09<\/li>\n<li>YY\uff1a\u5e74\u4efd\uff08\u4ee5\u4e24\u4f4d\u6570\u5b57\u8868\u793a\uff09<\/li>\n<li>MM\uff1a\u6708\u4efd\uff08\u4ee5\u4e24\u4f4d\u6570\u5b57\u8868\u793a\uff09<\/li>\n<li>DD\uff1a\u65e5\u671f\uff08\u4ee5\u4e24\u4f4d\u6570\u5b57\u8868\u793a\uff09<\/li>\n<li>HH\uff1a\u5c0f\u65f6\uff0824 \u5c0f\u65f6\u5236\uff0c\u4ee5\u4e24\u4f4d\u6570\u5b57\u8868\u793a\uff09<\/li>\n<li>MI\uff1a\u5206\u949f\uff08\u4ee5\u4e24\u4f4d\u6570\u5b57\u8868\u793a\uff09<\/li>\n<li>SS\uff1a\u79d2\uff08\u4ee5\u4e24\u4f4d\u6570\u5b57\u8868\u793a\uff09<\/li>\n<\/ul>\n<p><strong>\u793a\u4f8b\uff1a<\/strong><\/p>\n<pre>-- \u5c06 \"2023-03-08\" \u683c\u5f0f\u5316\u4e3a \"03\/08\/2023\"\nSELECT TO_CHAR('2023-03-08', 'MM\/DD\/YYYY') AS formatted_date;<\/pre>\n<p>  \u767b\u5f55\u540e\u590d\u5236   <\/p>\n<p><strong>\u7ed3\u679c\uff1a<\/strong><\/p>\n<pre>formatted_date\n--------------\n03\/08\/2023<\/pre>\n<p>  \u767b\u5f55\u540e\u590d\u5236   <\/p>\n<p><strong>\u5176\u4ed6\u9009\u9879\uff1a<\/strong><\/p>\n<p>\u9664\u4e86 TO_CHAR() \u51fd\u6570\u4e4b\u5916\uff0c\u8fd8\u53ef\u4ee5\u5728 SELECT \u8bed\u53e5\u4e2d\u76f4\u63a5\u4f7f\u7528\u5df2\u683c\u5f0f\u5316\u7684\u65e5\u671f\u503c\uff1a<\/p>\n<pre>-- \u4ee5 \"YYYY-MM-DD HH:MI:SS\" \u683c\u5f0f\u9009\u62e9\u65e5\u671f\nSELECT DATE('2023-03-08 13:37:45') AS formatted_date;<\/pre>\n<p>  \u767b\u5f55\u540e\u590d\u5236   <\/p>\n<p><strong>\u7ed3\u679c\uff1a<\/strong><\/p>\n<pre>formatted_date\n----------------\n2023-03-08 13:37:45<\/pre>\n<p>  \u767b\u5f55\u540e\u590d\u5236   <\/p>\n<p>\u4ee5\u4e0a\u5c31\u662fsql\u65e5\u671f\u683c\u5f0f\u5316\u600e\u4e48\u8bbe\u7f6e\u7684\u8be6\u7ec6\u5185\u5bb9\uff0c\u66f4\u591a\u8bf7\u5173\u6ce8\u7c73\u4e91\u7f51\u5176\u5b83\u76f8\u5173\u6587\u7ae0\uff01<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u5728 sql \u4e2d\uff0c\u53ef\u4f7f\u7528 to_char() \u51fd\u6570\u683c\u5f0f\u5316\u65e5\u671f\u503c\uff0c\u5176\u8bed\u6cd5\u4e3a\uff1ato_char(\u65e5\u671f\u503c, \u683c\u5f0f\u5316\u5b57\u7b26\u4e32)\u3002\u683c\u5f0f\u5316\u5b57\u7b26\u4e32\u652f\u6301\u6307\u5b9a\u5e74\u4efd\u3001\u6708\u4efd\u3001\u65e5\u671f\u3001\u5c0f\u65f6\u3001\u5206\u949f\u3001\u79d2\u7b49\uff0c\u4f8b\u5982 yyyy\u3001mm\u3001dd \u7b49\u3002\u8fd8\u53ef\u4ee5\u76f4\u63a5\u5728 select \u8bed\u53e5\u4e2d\u4f7f\u7528\u5df2\u683c\u5f0f\u5316\u7684\u65e5\u671f\u503c\u3002 SQL \u65e5\u671f\u683c\u5f0f\u5316\u8bbe\u7f6e \u5982\u4f55\u8bbe\u7f6e SQL \u65e5\u671f\u683c\u5f0f\uff1f \u5728 SQL \u4e2d\uff0c\u53ef\u4ee5\u4f7f\u7528 TO_CHAR() \u51fd\u6570\u6765\u683c\u5f0f\u5316\u65e5\u671f\u503c\u3002TO_CHAR() \u51fd\u6570\u7b2c\u4e00\u4e2a\u53c2\u6570\u6307\u5b9a\u8981\u8f6c\u6362\u7684\u65e5\u671f\u503c\uff0c\u7b2c\u4e8c\u4e2a\u53c2\u6570\u6307\u5b9a\u683c\u5f0f\u5316\u5b57\u7b26\u4e32\u3002 \u683c\u5f0f\u5316\u5b57\u7b26\u4e32\u8bed\u6cd5\uff1a YYYY\uff1a\u5e74\u4efd\uff08\u4ee5\u56db\u4f4d\u6570\u5b57\u8868\u793a\uff09 YY\uff1a\u5e74\u4efd\uff08\u4ee5\u4e24\u4f4d\u6570\u5b57\u8868\u793a\uff09 MM\uff1a\u6708\u4efd\uff08\u4ee5\u4e24\u4f4d\u6570\u5b57\u8868\u793a\uff09 DD\uff1a\u65e5\u671f\uff08\u4ee5\u4e24\u4f4d\u6570\u5b57\u8868\u793a\uff09 HH\uff1a\u5c0f\u65f6\uff0824 \u5c0f\u65f6\u5236\uff0c\u4ee5\u4e24\u4f4d\u6570\u5b57\u8868\u793a\uff09 MI\uff1a\u5206\u949f\uff08\u4ee5\u4e24\u4f4d\u6570\u5b57\u8868\u793a\uff09 SS\uff1a\u79d2\uff08\u4ee5\u4e24\u4f4d\u6570\u5b57\u8868\u793a\uff09 \u793a\u4f8b\uff1a &#8212; \u5c06 &#8220;2023-03-08&#8221; \u683c\u5f0f\u5316\u4e3a &#8220;03\/08\/2023&#8221; SELECT TO_CHAR(&#8216;2023-03-08&#8217;, &#8216;MM\/DD\/YYYY&#8217;) AS formatted_date; \u767b\u5f55\u540e\u590d\u5236 \u7ed3\u679c\uff1a formatted_date &#8212;&#8212;&#8212;&#8212;&#8211; 03\/08\/2023 \u767b\u5f55\u540e\u590d\u5236 \u5176\u4ed6\u9009\u9879\uff1a \u9664\u4e86 TO_CHAR() \u51fd\u6570\u4e4b\u5916\uff0c\u8fd8\u53ef\u4ee5\u5728 SELECT \u8bed\u53e5\u4e2d\u76f4\u63a5\u4f7f\u7528\u5df2\u683c\u5f0f\u5316\u7684\u65e5\u671f\u503c\uff1a &#8212; \u4ee5 [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[16],"tags":[],"class_list":["post-5712","post","type-post","status-publish","format-standard","hentry","category-16"],"_links":{"self":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/5712","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/comments?post=5712"}],"version-history":[{"count":0,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/5712\/revisions"}],"wp:attachment":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/media?parent=5712"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/categories?post=5712"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/tags?post=5712"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}