{"id":160555,"date":"2024-11-03T23:04:19","date_gmt":"2024-11-03T15:04:19","guid":{"rendered":"https:\/\/server.hk\/cnblog\/160555\/"},"modified":"2024-11-03T23:04:20","modified_gmt":"2024-11-03T15:04:20","slug":"oceanbase-%e6%95%99%e7%a8%8b%ef%bc%9aoceanbase-%e6%97%a5%e6%9c%9f%e5%80%bc","status":"publish","type":"post","link":"https:\/\/server.hk\/cnblog\/160555\/","title":{"rendered":"OceanBase \u6559\u7a0b\uff1aOceanBase \u65e5\u671f\u503c"},"content":{"rendered":"<h1 id=\"oceanbase-%e6%95%99%e7%a8%8b%ef%bc%9aoceanbase-%e6%97%a5%e6%9c%9f%e5%80%bc-xdcoPfKadJ\">OceanBase \u6559\u7a0b\uff1aOceanBase \u65e5\u671f\u503c<\/h1>\n<p>\u5728\u7576\u4eca\u7684\u6578\u64da\u5eab\u7ba1\u7406\u7cfb\u7d71\u4e2d\uff0c\u65e5\u671f\u548c\u6642\u9593\u7684\u8655\u7406\u662f\u81f3\u95dc\u91cd\u8981\u7684\u3002OceanBase \u4f5c\u70ba\u4e00\u500b\u9ad8\u6027\u80fd\u7684\u5206\u4f48\u5f0f\u6578\u64da\u5eab\uff0c\u63d0\u4f9b\u4e86\u5f37\u5927\u7684\u65e5\u671f\u503c\u8655\u7406\u529f\u80fd\u3002\u672c\u6587\u5c07\u6df1\u5165\u63a2\u8a0e OceanBase \u4e2d\u7684\u65e5\u671f\u503c\uff0c\u5305\u62ec\u5176\u6578\u64da\u985e\u578b\u3001\u64cd\u4f5c\u65b9\u6cd5\u53ca\u5be6\u969b\u61c9\u7528\u793a\u4f8b\u3002<\/p>\n<h2 id=\"oceanbase-%e6%97%a5%e6%9c%9f%e5%80%bc%e7%9a%84%e6%95%b8%e6%93%9a%e9%a1%9e%e5%9e%8b-xdcoPfKadJ\">OceanBase \u65e5\u671f\u503c\u7684\u6578\u64da\u985e\u578b<\/h2>\n<p>\u5728 OceanBase \u4e2d\uff0c\u65e5\u671f\u548c\u6642\u9593\u7684\u6578\u64da\u985e\u578b\u4e3b\u8981\u5305\u62ec\uff1a<\/p>\n<ul>\n<li><strong>DATE<\/strong>\uff1a\u7528\u65bc\u5b58\u5132\u65e5\u671f\uff0c\u683c\u5f0f\u70ba &#8216;YYYY-MM-DD&#8217;\u3002<\/li>\n<li><strong>DATETIME<\/strong>\uff1a\u7528\u65bc\u5b58\u5132\u65e5\u671f\u548c\u6642\u9593\uff0c\u683c\u5f0f\u70ba &#8216;YYYY-MM-DD HH:MM:SS&#8217;\u3002<\/li>\n<li><strong>TIMESTAMP<\/strong>\uff1a\u7528\u65bc\u5b58\u5132\u6642\u9593\u6233\uff0c\u901a\u5e38\u7528\u65bc\u8a18\u9304\u4e8b\u4ef6\u767c\u751f\u7684\u5177\u9ad4\u6642\u9593\u3002<\/li>\n<li><strong>TIME<\/strong>\uff1a\u7528\u65bc\u5b58\u5132\u6642\u9593\uff0c\u683c\u5f0f\u70ba &#8216;HH:MM:SS&#8217;\u3002<\/li>\n<\/ul>\n<p>\u9019\u4e9b\u6578\u64da\u985e\u578b\u4f7f\u5f97\u7528\u6236\u80fd\u5920\u9748\u6d3b\u5730\u8655\u7406\u5404\u7a2e\u65e5\u671f\u548c\u6642\u9593\u7684\u9700\u6c42\u3002<\/p>\n<h2 id=\"%e6%97%a5%e6%9c%9f%e5%80%bc%e7%9a%84%e5%9f%ba%e6%9c%ac%e6%93%8d%e4%bd%9c-xdcoPfKadJ\">\u65e5\u671f\u503c\u7684\u57fa\u672c\u64cd\u4f5c<\/h2>\n<p>\u5728 OceanBase \u4e2d\uff0c\u5c0d\u65e5\u671f\u503c\u7684\u64cd\u4f5c\u4e3b\u8981\u5305\u62ec\u63d2\u5165\u3001\u67e5\u8a62\u3001\u66f4\u65b0\u548c\u522a\u9664\u3002\u4ee5\u4e0b\u662f\u4e00\u4e9b\u57fa\u672c\u7684 SQL \u64cd\u4f5c\u793a\u4f8b\uff1a<\/p>\n<h3 id=\"%e6%8f%92%e5%85%a5%e6%97%a5%e6%9c%9f%e5%80%bc-xdcoPfKadJ\">\u63d2\u5165\u65e5\u671f\u503c<\/h3>\n<pre><code>INSERT INTO events (event_name, event_date) VALUES ('\u65b0\u5e74\u6d3e\u5c0d', '2023-01-01');<\/code><\/pre>\n<h3 id=\"%e6%9f%a5%e8%a9%a2%e6%97%a5%e6%9c%9f%e5%80%bc-xdcoPfKadJ\">\u67e5\u8a62\u65e5\u671f\u503c<\/h3>\n<pre><code>SELECT * FROM events WHERE event_date &gt; '2023-01-01';<\/code><\/pre>\n<h3 id=\"%e6%9b%b4%e6%96%b0%e6%97%a5%e6%9c%9f%e5%80%bc-xdcoPfKadJ\">\u66f4\u65b0\u65e5\u671f\u503c<\/h3>\n<pre><code>UPDATE events SET event_date = '2023-12-25' WHERE event_name = '\u8056\u8a95\u6d3e\u5c0d';<\/code><\/pre>\n<h3 id=\"%e5%88%aa%e9%99%a4%e6%97%a5%e6%9c%9f%e5%80%bc-xdcoPfKadJ\">\u522a\u9664\u65e5\u671f\u503c<\/h3>\n<pre><code>DELETE FROM events WHERE event_date &lt; '2023-01-01';<\/code><\/pre>\n<h2 id=\"%e6%97%a5%e6%9c%9f%e5%80%bc%e7%9a%84%e5%87%bd%e6%95%b8-xdcoPfKadJ\">\u65e5\u671f\u503c\u7684\u51fd\u6578<\/h2>\n<p>OceanBase \u63d0\u4f9b\u4e86\u591a\u7a2e\u5167\u5efa\u51fd\u6578\u4f86\u8655\u7406\u65e5\u671f\u503c\uff0c\u9019\u4e9b\u51fd\u6578\u53ef\u4ee5\u5e6b\u52a9\u7528\u6236\u9032\u884c\u66f4\u8907\u96dc\u7684\u65e5\u671f\u8a08\u7b97\u548c\u683c\u5f0f\u5316\u3002\u4ee5\u4e0b\u662f\u4e00\u4e9b\u5e38\u7528\u7684\u65e5\u671f\u51fd\u6578\uff1a<\/p>\n<ul>\n<li><strong>CURDATE()<\/strong>\uff1a\u8fd4\u56de\u7576\u524d\u65e5\u671f\u3002<\/li>\n<li><strong>NOW()<\/strong>\uff1a\u8fd4\u56de\u7576\u524d\u7684\u65e5\u671f\u548c\u6642\u9593\u3002<\/li>\n<li><strong>DATEDIFF(date1, date2)<\/strong>\uff1a\u8a08\u7b97\u5169\u500b\u65e5\u671f\u4e4b\u9593\u7684\u5929\u6578\u5dee\u3002<\/li>\n<li><strong>DATE_FORMAT(date, format)<\/strong>\uff1a\u6839\u64da\u6307\u5b9a\u683c\u5f0f\u8fd4\u56de\u65e5\u671f\u3002<\/li>\n<\/ul>\n<p>\u4f8b\u5982\uff0c\u4f7f\u7528 DATEDIFF \u51fd\u6578\u8a08\u7b97\u5169\u500b\u4e8b\u4ef6\u4e4b\u9593\u7684\u5929\u6578\uff1a<\/p>\n<pre><code>SELECT DATEDIFF('2023-12-25', '2023-01-01') AS days_difference;<\/code><\/pre>\n<h2 id=\"%e5%af%a6%e9%9a%9b%e6%87%89%e7%94%a8%e7%a4%ba%e4%be%8b-xdcoPfKadJ\">\u5be6\u969b\u61c9\u7528\u793a\u4f8b<\/h2>\n<p>\u5728\u5be6\u969b\u61c9\u7528\u4e2d\uff0c\u65e5\u671f\u503c\u7684\u8655\u7406\u53ef\u4ee5\u7528\u65bc\u591a\u7a2e\u5834\u666f\uff0c\u4f8b\u5982\u4e8b\u4ef6\u7ba1\u7406\u3001\u5831\u544a\u751f\u6210\u548c\u6578\u64da\u5206\u6790\u3002\u4ee5\u4e0b\u662f\u4e00\u500b\u7c21\u55ae\u7684\u4e8b\u4ef6\u7ba1\u7406\u7cfb\u7d71\u7684\u793a\u4f8b\uff1a<\/p>\n<pre><code>CREATE TABLE events (\n    id INT AUTO_INCREMENT PRIMARY KEY,\n    event_name VARCHAR(255) NOT NULL,\n    event_date DATE NOT NULL\n);\n\nINSERT INTO events (event_name, event_date) VALUES ('\u6703\u8b70', '2023-11-01');\nINSERT INTO events (event_name, event_date) VALUES ('\u7814\u8a0e\u6703', '2023-11-15');\n\nSELECT * FROM events WHERE event_date &gt; CURDATE();<\/code><\/pre>\n<p>\u9019\u6bb5\u4ee3\u78bc\u5275\u5efa\u4e86\u4e00\u500b\u4e8b\u4ef6\u8868\uff0c\u4e26\u63d2\u5165\u4e86\u5169\u500b\u4e8b\u4ef6\u3002\u96a8\u5f8c\uff0c\u67e5\u8a62\u6240\u6709\u672a\u4f86\u7684\u4e8b\u4ef6\u3002<\/p>\n<h2 id=\"%e7%b5%90%e8%ab%96-xdcoPfKadJ\">\u7d50\u8ad6<\/h2>\n<p>OceanBase \u63d0\u4f9b\u4e86\u9748\u6d3b\u4e14\u5f37\u5927\u7684\u65e5\u671f\u503c\u8655\u7406\u529f\u80fd\uff0c\u7121\u8ad6\u662f\u5728\u6578\u64da\u63d2\u5165\u3001\u67e5\u8a62\u9084\u662f\u8a08\u7b97\u65b9\u9762\uff0c\u90fd\u80fd\u6eff\u8db3\u7528\u6236\u7684\u9700\u6c42\u3002\u901a\u904e\u638c\u63e1\u9019\u4e9b\u57fa\u672c\u64cd\u4f5c\u548c\u51fd\u6578\uff0c\u958b\u767c\u8005\u53ef\u4ee5\u66f4\u6709\u6548\u5730\u7ba1\u7406\u548c\u5206\u6790\u6642\u9593\u76f8\u95dc\u7684\u6578\u64da\u3002<\/p>\n<p>\u5982\u9700\u4e86\u89e3\u66f4\u591a\u6709\u95dc <a href=\"https:\/\/server.hk\">VPS<\/a> \u53ca\u5176\u4ed6\u670d\u52d9\u7684\u4fe1\u606f\uff0c\u8acb\u8a2a\u554f\u6211\u5011\u7684\u7db2\u7ad9\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u5b66\u4e60\u5982\u4f55\u5728 OceanBase \u4e2d\u5904\u7406\u65e5\u671f\u503c\uff0c\u638c\u63e1\u65e5\u671f\u51fd\u6570\u548c\u683c\u5f0f\u5316\u6280\u5de7\uff0c\u63d0\u5347\u6570\u636e\u5e93\u64cd\u4f5c\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-160555","post","type-post","status-publish","format-standard","hentry","category-database"],"_links":{"self":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/160555","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=160555"}],"version-history":[{"count":1,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/160555\/revisions"}],"predecessor-version":[{"id":160556,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/160555\/revisions\/160556"}],"wp:attachment":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/media?parent=160555"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/categories?post=160555"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/tags?post=160555"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}