{"id":94498,"date":"2024-10-19T19:16:18","date_gmt":"2024-10-19T11:16:18","guid":{"rendered":"https:\/\/server.hk\/cnblog\/94498\/"},"modified":"2024-10-19T19:16:19","modified_gmt":"2024-10-19T11:16:19","slug":"oracle-to_date%e5%87%bd%e6%95%b8%e7%9a%84%e7%94%a8%e6%b3%95","status":"publish","type":"post","link":"https:\/\/server.hk\/cnblog\/94498\/","title":{"rendered":"Oracle to_date()\u51fd\u6578\u7684\u7528\u6cd5"},"content":{"rendered":"<h1 id=\"oracle-to_date%e5%87%bd%e6%95%b8%e7%9a%84%e7%94%a8%e6%b3%95-vfNeHfIjWr\">Oracle to_date()\u51fd\u6578\u7684\u7528\u6cd5<\/h1>\n<p>\u5728Oracle\u8cc7\u6599\u5eab\u4e2d\uff0c\u65e5\u671f\u548c\u6642\u9593\u7684\u8655\u7406\u662f\u975e\u5e38\u91cd\u8981\u7684\uff0c\u5c24\u5176\u662f\u5728\u9032\u884c\u6578\u64da\u67e5\u8a62\u548c\u5831\u544a\u6642\u3002Oracle\u63d0\u4f9b\u4e86\u591a\u7a2e\u51fd\u6578\u4f86\u8655\u7406\u65e5\u671f\uff0c\u5176\u4e2d\u6700\u5e38\u7528\u7684\u51fd\u6578\u4e4b\u4e00\u5c31\u662f <code>to_date()<\/code> \u51fd\u6578\u3002\u9019\u7bc7\u6587\u7ae0\u5c07\u6df1\u5165\u63a2\u8a0e <code>to_date()<\/code> \u51fd\u6578\u7684\u7528\u6cd5\u53ca\u5176\u61c9\u7528\u7bc4\u4f8b\u3002<\/p>\n<h2 id=\"to_date%e5%87%bd%e6%95%b8%e6%a6%82%e8%bf%b0-vfNeHfIjWr\">to_date()\u51fd\u6578\u6982\u8ff0<\/h2>\n<p><code>to_date()<\/code> \u51fd\u6578\u7684\u4e3b\u8981\u529f\u80fd\u662f\u5c07\u5b57\u4e32\u8f49\u63db\u70ba\u65e5\u671f\u683c\u5f0f\u3002\u9019\u5c0d\u65bc\u5f9e\u8cc7\u6599\u5eab\u4e2d\u63d0\u53d6\u65e5\u671f\u8cc7\u6599\u6642\u975e\u5e38\u6709\u7528\uff0c\u56e0\u70ba\u8cc7\u6599\u5eab\u4e2d\u7684\u65e5\u671f\u901a\u5e38\u4ee5\u5b57\u4e32\u5f62\u5f0f\u5b58\u5132\u3002\u4f7f\u7528 <code>to_date()<\/code> \u51fd\u6578\u53ef\u4ee5\u78ba\u4fdd\u8cc7\u6599\u7684\u6b63\u78ba\u6027\u548c\u4e00\u81f4\u6027\u3002<\/p>\n<h2 id=\"%e5%87%bd%e6%95%b8%e8%aa%9e%e6%b3%95-vfNeHfIjWr\">\u51fd\u6578\u8a9e\u6cd5<\/h2>\n<pre><code>to_date(char, format)<\/code><\/pre>\n<ul>\n<li><strong>char<\/strong>: \u8981\u8f49\u63db\u7684\u5b57\u4e32\uff0c\u5fc5\u9808\u662f\u6709\u6548\u7684\u65e5\u671f\u5b57\u4e32\u3002<\/li>\n<li><strong>format<\/strong>: \u6307\u5b9a\u5b57\u4e32\u7684\u65e5\u671f\u683c\u5f0f\uff0c\u9019\u662f\u53ef\u9078\u7684\u3002\u5982\u679c\u4e0d\u63d0\u4f9b\uff0cOracle\u5c07\u4f7f\u7528\u9810\u8a2d\u7684\u65e5\u671f\u683c\u5f0f\u3002<\/li>\n<\/ul>\n<h2 id=\"%e6%97%a5%e6%9c%9f%e6%a0%bc%e5%bc%8f-vfNeHfIjWr\">\u65e5\u671f\u683c\u5f0f<\/h2>\n<p>\u5728\u4f7f\u7528 <code>to_date()<\/code> \u51fd\u6578\u6642\uff0c\u4e86\u89e3\u65e5\u671f\u683c\u5f0f\u662f\u975e\u5e38\u91cd\u8981\u7684\u3002\u4ee5\u4e0b\u662f\u4e00\u4e9b\u5e38\u7528\u7684\u65e5\u671f\u683c\u5f0f\u7b26\u865f\uff1a<\/p>\n<ul>\n<li><code>YYYY<\/code>: \u56db\u4f4d\u6578\u7684\u5e74\u4efd<\/li>\n<li><code>MM<\/code>: \u5169\u4f4d\u6578\u7684\u6708\u4efd\uff0801-12\uff09<\/li>\n<li><code>DD<\/code>: \u5169\u4f4d\u6578\u7684\u65e5\u671f\uff0801-31\uff09<\/li>\n<li><code>HH24<\/code>: 24\u5c0f\u6642\u5236\u7684\u6642\uff0800-23\uff09<\/li>\n<li><code>MI<\/code>: \u5206\u9418\uff0800-59\uff09<\/li>\n<li><code>SS<\/code>: \u79d2\uff0800-59\uff09<\/li>\n<\/ul>\n<h2 id=\"%e4%bd%bf%e7%94%a8%e7%af%84%e4%be%8b-vfNeHfIjWr\">\u4f7f\u7528\u7bc4\u4f8b<\/h2>\n<p>\u4ee5\u4e0b\u662f\u4e00\u4e9b\u4f7f\u7528 <code>to_date()<\/code> \u51fd\u6578\u7684\u7bc4\u4f8b\uff1a<\/p>\n<h3 id=\"%e7%af%84%e4%be%8b1-%e5%9f%ba%e6%9c%ac%e7%94%a8%e6%b3%95-vfNeHfIjWr\">\u7bc4\u4f8b1: \u57fa\u672c\u7528\u6cd5<\/h3>\n<pre><code>SELECT to_date('2023-10-01', 'YYYY-MM-DD') AS converted_date FROM dual;<\/code><\/pre>\n<p>\u9019\u500b\u67e5\u8a62\u5c07\u5b57\u4e32 &#8216;2023-10-01&#8217; \u8f49\u63db\u70ba\u65e5\u671f\u683c\u5f0f\uff0c\u7d50\u679c\u5c07\u986f\u793a\u70ba 2023\u5e7410\u67081\u65e5\u3002<\/p>\n<h3 id=\"%e7%af%84%e4%be%8b2-%e5%8c%85%e5%90%ab%e6%99%82%e9%96%93%e7%9a%84%e6%97%a5%e6%9c%9f-vfNeHfIjWr\">\u7bc4\u4f8b2: \u5305\u542b\u6642\u9593\u7684\u65e5\u671f<\/h3>\n<pre><code>SELECT to_date('2023-10-01 14:30:00', 'YYYY-MM-DD HH24:MI:SS') AS converted_datetime FROM dual;<\/code><\/pre>\n<p>\u5728\u9019\u500b\u7bc4\u4f8b\u4e2d\uff0c\u6211\u5011\u5c07\u5b57\u4e32 &#8216;2023-10-01 14:30:00&#8217; \u8f49\u63db\u70ba\u5305\u542b\u6642\u9593\u7684\u65e5\u671f\u683c\u5f0f\u3002<\/p>\n<h3 id=\"%e7%af%84%e4%be%8b3-%e4%bd%bf%e7%94%a8%e9%a0%90%e8%a8%ad%e6%a0%bc%e5%bc%8f-vfNeHfIjWr\">\u7bc4\u4f8b3: \u4f7f\u7528\u9810\u8a2d\u683c\u5f0f<\/h3>\n<pre><code>ALTER SESSION SET NLS_DATE_FORMAT = 'YYYY-MM-DD';\nSELECT to_date('2023-10-01') AS converted_date FROM dual;<\/code><\/pre>\n<p>\u5728\u9019\u500b\u7bc4\u4f8b\u4e2d\uff0c\u6211\u5011\u9996\u5148\u8a2d\u7f6e\u4e86\u6703\u8a71\u7684\u9810\u8a2d\u65e5\u671f\u683c\u5f0f\uff0c\u7136\u5f8c\u5c07\u5b57\u4e32 &#8216;2023-10-01&#8217; \u8f49\u63db\u70ba\u65e5\u671f\u683c\u5f0f\u3002<\/p>\n<h2 id=\"%e6%b3%a8%e6%84%8f%e4%ba%8b%e9%a0%85-vfNeHfIjWr\">\u6ce8\u610f\u4e8b\u9805<\/h2>\n<p>\u5728\u4f7f\u7528 <code>to_date()<\/code> \u51fd\u6578\u6642\uff0c\u5fc5\u9808\u78ba\u4fdd\u5b57\u4e32\u7684\u683c\u5f0f\u8207\u6307\u5b9a\u7684\u683c\u5f0f\u76f8\u7b26\u3002\u5982\u679c\u683c\u5f0f\u4e0d\u5339\u914d\uff0c\u5c07\u6703\u5f15\u767c\u932f\u8aa4\u3002\u6b64\u5916\uff0c\u4f7f\u7528\u8005\u61c9\u8a72\u6ce8\u610f\u4e0d\u540c\u7684\u5730\u5340\u53ef\u80fd\u6709\u4e0d\u540c\u7684\u65e5\u671f\u683c\u5f0f\uff0c\u9019\u5728\u8655\u7406\u570b\u969b\u5316\u61c9\u7528\u6642\u5c24\u70ba\u91cd\u8981\u3002<\/p>\n<h2 id=\"%e7%b8%bd%e7%b5%90-vfNeHfIjWr\">\u7e3d\u7d50<\/h2>\n<p>Oracle\u7684 <code>to_date()<\/code> \u51fd\u6578\u662f\u4e00\u500b\u5f37\u5927\u7684\u5de5\u5177\uff0c\u53ef\u4ee5\u5e6b\u52a9\u958b\u767c\u8005\u548c\u6578\u64da\u5206\u6790\u5e2b\u6709\u6548\u5730\u8655\u7406\u65e5\u671f\u548c\u6642\u9593\u8cc7\u6599\u3002\u901a\u904e\u6b63\u78ba\u4f7f\u7528\u6b64\u51fd\u6578\uff0c\u53ef\u4ee5\u78ba\u4fdd\u8cc7\u6599\u7684\u6e96\u78ba\u6027\u548c\u4e00\u81f4\u6027\uff0c\u5f9e\u800c\u63d0\u9ad8\u6578\u64da\u67e5\u8a62\u7684\u6548\u7387\u3002\u5982\u679c\u60a8\u5c0d\u65bc <a href=\"https:\/\/server.hk\">\u9999\u6e2fVPS<\/a> \u670d\u52d9\u6709\u8208\u8da3\uff0c\u8acb\u8a2a\u554f\u6211\u5011\u7684\u7db2\u7ad9\u4ee5\u7372\u53d6\u66f4\u591a\u8cc7\u8a0a\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u4e86\u89e3Oracle to_date()\u51fd\u6578\u7684\u7528\u6cd5\uff0c\u5b78\u7fd2\u5982\u4f55\u5c07\u5b57\u4e32\u8f49\u63db\u70ba\u65e5\u671f\u683c\u5f0f\uff0c\u63d0\u5347\u6578\u64da\u8655\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-94498","post","type-post","status-publish","format-standard","hentry","category-database"],"_links":{"self":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/94498","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=94498"}],"version-history":[{"count":1,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/94498\/revisions"}],"predecessor-version":[{"id":94499,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/94498\/revisions\/94499"}],"wp:attachment":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/media?parent=94498"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/categories?post=94498"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/tags?post=94498"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}