{"id":160149,"date":"2024-11-03T20:41:19","date_gmt":"2024-11-03T12:41:19","guid":{"rendered":"https:\/\/server.hk\/cnblog\/160149\/"},"modified":"2024-11-03T20:41:21","modified_gmt":"2024-11-03T12:41:21","slug":"oceanbase-%e6%95%99%e7%a8%8b%ef%bc%9aoceanbase-interval-year-to-month-%e6%95%b8%e6%93%9a%e9%a1%9e%e5%9e%8b","status":"publish","type":"post","link":"https:\/\/server.hk\/cnblog\/160149\/","title":{"rendered":"OceanBase \u6559\u7a0b\uff1aOceanBase INTERVAL YEAR TO MONTH \u6578\u64da\u985e\u578b"},"content":{"rendered":"<h1 id=\"oceanbase-%e6%95%99%e7%a8%8b%ef%bc%9aoceanbase-interval-year-to-month-%e6%95%b8%e6%93%9a%e9%a1%9e%e5%9e%8b-pTcRhXJkzg\">OceanBase \u6559\u7a0b\uff1aOceanBase INTERVAL YEAR TO MONTH \u6578\u64da\u985e\u578b<\/h1>\n<p>\u5728\u7576\u4eca\u7684\u6578\u64da\u5eab\u7ba1\u7406\u7cfb\u7d71\u4e2d\uff0cOceanBase \u4f5c\u70ba\u4e00\u500b\u9ad8\u6027\u80fd\u7684\u5206\u4f48\u5f0f\u6578\u64da\u5eab\uff0c\u8d8a\u4f86\u8d8a\u53d7\u5230\u958b\u767c\u8005\u548c\u4f01\u696d\u7684\u9752\u775e\u3002\u672c\u6587\u5c07\u6df1\u5165\u63a2\u8a0e OceanBase \u4e2d\u7684 INTERVAL YEAR TO MONTH \u6578\u64da\u985e\u578b\uff0c\u5e6b\u52a9\u8b80\u8005\u7406\u89e3\u5176\u7279\u6027\u53ca\u4f7f\u7528\u65b9\u6cd5\u3002<\/p>\n<h2 id=\"%e4%bb%80%e9%ba%bc%e6%98%af-interval-year-to-month%ef%bc%9f-pTcRhXJkzg\">\u4ec0\u9ebc\u662f INTERVAL YEAR TO MONTH\uff1f<\/h2>\n<p>INTERVAL YEAR TO MONTH \u662f\u4e00\u7a2e\u7528\u65bc\u8868\u793a\u6642\u9593\u9593\u9694\u7684\u6578\u64da\u985e\u578b\uff0c\u5c08\u9580\u7528\u4f86\u8868\u793a\u5e74\u548c\u6708\u7684\u7d44\u5408\u3002\u9019\u7a2e\u6578\u64da\u985e\u578b\u5728\u8655\u7406\u6642\u9593\u8a08\u7b97\u6642\u975e\u5e38\u6709\u7528\uff0c\u7279\u5225\u662f\u5728\u9700\u8981\u9032\u884c\u65e5\u671f\u52a0\u6e1b\u904b\u7b97\u7684\u60c5\u6cc1\u4e0b\u3002<\/p>\n<h2 id=\"interval-year-to-month-%e7%9a%84%e8%aa%9e%e6%b3%95-pTcRhXJkzg\">INTERVAL YEAR TO MONTH \u7684\u8a9e\u6cd5<\/h2>\n<p>\u5728 OceanBase \u4e2d\uff0cINTERVAL YEAR TO MONTH \u7684\u57fa\u672c\u8a9e\u6cd5\u5982\u4e0b\uff1a<\/p>\n<pre><code>INTERVAL 'n' YEAR TO MONTH<\/code><\/pre>\n<p>\u5176\u4e2d\uff0c<code>n<\/code> \u662f\u4e00\u500b\u6574\u6578\uff0c\u8868\u793a\u5e74\u548c\u6708\u7684\u6578\u91cf\u3002\u4f8b\u5982\uff0c<code>INTERVAL '2-6' YEAR TO MONTH<\/code> \u8868\u793a 2 \u5e74 6 \u500b\u6708\u7684\u6642\u9593\u9593\u9694\u3002<\/p>\n<h2 id=\"%e4%bd%bf%e7%94%a8%e7%af%84%e4%be%8b-pTcRhXJkzg\">\u4f7f\u7528\u7bc4\u4f8b<\/h2>\n<p>\u4ee5\u4e0b\u662f\u4e00\u4e9b\u4f7f\u7528 INTERVAL YEAR TO MONTH \u7684\u7bc4\u4f8b\uff1a<\/p>\n<h3 id=\"%e7%af%84%e4%be%8b-1%ef%bc%9a%e5%89%b5%e5%bb%ba%e8%a1%a8%e6%a0%bc-pTcRhXJkzg\">\u7bc4\u4f8b 1\uff1a\u5275\u5efa\u8868\u683c<\/h3>\n<pre><code>CREATE TABLE example_table (\n    id INT,\n    start_date DATE,\n    duration INTERVAL YEAR TO MONTH\n);<\/code><\/pre>\n<p>\u5728\u9019\u500b\u7bc4\u4f8b\u4e2d\uff0c\u6211\u5011\u5275\u5efa\u4e86\u4e00\u500b\u540d\u70ba <code>example_table<\/code> \u7684\u8868\u683c\uff0c\u5176\u4e2d\u5305\u542b\u4e00\u500b <code>duration<\/code> \u5217\uff0c\u8a72\u5217\u7684\u6578\u64da\u985e\u578b\u70ba INTERVAL YEAR TO MONTH\u3002<\/p>\n<h3 id=\"%e7%af%84%e4%be%8b-2%ef%bc%9a%e6%8f%92%e5%85%a5%e6%95%b8%e6%93%9a-pTcRhXJkzg\">\u7bc4\u4f8b 2\uff1a\u63d2\u5165\u6578\u64da<\/h3>\n<pre><code>INSERT INTO example_table (id, start_date, duration) \nVALUES (1, '2023-01-01', INTERVAL '1-3' YEAR TO MONTH);<\/code><\/pre>\n<p>\u9019\u6bb5\u4ee3\u78bc\u5c07\u4e00\u689d\u8a18\u9304\u63d2\u5165\u5230 <code>example_table<\/code> \u4e2d\uff0c\u8868\u793a\u5f9e 2023 \u5e74 1 \u6708 1 \u65e5\u958b\u59cb\uff0c\u6301\u7e8c 1 \u5e74 3 \u500b\u6708\u3002<\/p>\n<h3 id=\"%e7%af%84%e4%be%8b-3%ef%bc%9a%e8%a8%88%e7%ae%97%e7%b5%90%e6%9d%9f%e6%97%a5%e6%9c%9f-pTcRhXJkzg\">\u7bc4\u4f8b 3\uff1a\u8a08\u7b97\u7d50\u675f\u65e5\u671f<\/h3>\n<pre><code>SELECT start_date + duration AS end_date \nFROM example_table \nWHERE id = 1;<\/code><\/pre>\n<p>\u9019\u6bb5\u67e5\u8a62\u5c07\u8a08\u7b97\u51fa\u7d50\u675f\u65e5\u671f\uff0c\u901a\u904e\u5c07 <code>start_date<\/code> \u548c <code>duration<\/code> \u76f8\u52a0\u4f86\u7372\u5f97\u3002<\/p>\n<h2 id=\"interval-year-to-month-%e7%9a%84%e6%87%89%e7%94%a8%e5%a0%b4%e6%99%af-pTcRhXJkzg\">INTERVAL YEAR TO MONTH \u7684\u61c9\u7528\u5834\u666f<\/h2>\n<p>INTERVAL YEAR TO MONTH \u6578\u64da\u985e\u578b\u5728\u8a31\u591a\u5834\u666f\u4e2d\u90fd\u975e\u5e38\u6709\u7528\uff0c\u4f8b\u5982\uff1a<\/p>\n<ul>\n<li><strong>\u5408\u540c\u7ba1\u7406\uff1a<\/strong>\u5728\u5408\u540c\u4e2d\uff0c\u7d93\u5e38\u9700\u8981\u8a08\u7b97\u5408\u540c\u7684\u6709\u6548\u671f\uff0c\u4f7f\u7528 INTERVAL YEAR TO MONTH \u53ef\u4ee5\u65b9\u4fbf\u5730\u9032\u884c\u9019\u4e9b\u8a08\u7b97\u3002<\/li>\n<li><strong>\u8a02\u95b1\u670d\u52d9\uff1a<\/strong>\u5c0d\u65bc\u8a02\u95b1\u578b\u670d\u52d9\uff0c\u8a08\u7b97\u7528\u6236\u7684\u8a02\u95b1\u671f\u9650\u4e5f\u53ef\u4ee5\u4f7f\u7528\u9019\u7a2e\u6578\u64da\u985e\u578b\u3002<\/li>\n<li><strong>\u9805\u76ee\u7ba1\u7406\uff1a<\/strong>\u5728\u9805\u76ee\u7ba1\u7406\u4e2d\uff0c\u7d93\u5e38\u9700\u8981\u8ddf\u8e64\u9805\u76ee\u7684\u958b\u59cb\u548c\u7d50\u675f\u6642\u9593\uff0cINTERVAL YEAR TO MONTH \u53ef\u4ee5\u5e6b\u52a9\u7c21\u5316\u9019\u4e9b\u8a08\u7b97\u3002<\/li>\n<\/ul>\n<h2 id=\"%e7%b8%bd%e7%b5%90-pTcRhXJkzg\">\u7e3d\u7d50<\/h2>\n<p>OceanBase \u7684 INTERVAL YEAR TO MONTH \u6578\u64da\u985e\u578b\u70ba\u958b\u767c\u8005\u63d0\u4f9b\u4e86\u4e00\u7a2e\u9748\u6d3b\u4e14\u9ad8\u6548\u7684\u65b9\u5f0f\u4f86\u8655\u7406\u6642\u9593\u9593\u9694\u7684\u8a08\u7b97\u3002\u901a\u904e\u672c\u6587\u7684\u4ecb\u7d39\uff0c\u76f8\u4fe1\u8b80\u8005\u5c0d\u9019\u4e00\u6578\u64da\u985e\u578b\u6709\u4e86\u66f4\u6df1\u5165\u7684\u4e86\u89e3\u3002\u5982\u679c\u60a8\u6b63\u5728\u5c0b\u627e\u9ad8\u6027\u80fd\u7684 <a href=\"https:\/\/server.hk\">VPS<\/a> \u89e3\u6c7a\u65b9\u6848\uff0cServer.HK \u63d0\u4f9b\u591a\u7a2e\u9078\u64c7\uff0c\u6eff\u8db3\u60a8\u7684\u9700\u6c42\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u4e86\u89e3 OceanBase \u4e2d\u7684 INTERVAL YEAR TO MONTH \u6578\u64da\u985e\u578b\uff0c\u638c\u63e1\u5176\u7528\u6cd5\u53ca\u61c9\u7528\u6280\u5de7\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-160149","post","type-post","status-publish","format-standard","hentry","category-database"],"_links":{"self":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/160149","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=160149"}],"version-history":[{"count":1,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/160149\/revisions"}],"predecessor-version":[{"id":160150,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/160149\/revisions\/160150"}],"wp:attachment":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/media?parent=160149"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/categories?post=160149"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/tags?post=160149"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}