{"id":160529,"date":"2024-11-03T22:51:20","date_gmt":"2024-11-03T14:51:20","guid":{"rendered":"https:\/\/server.hk\/cnblog\/160529\/"},"modified":"2024-11-03T22:51:21","modified_gmt":"2024-11-03T14:51:21","slug":"oceanbase-%e6%95%99%e7%a8%8b%ef%bc%9aoceanbase-%e9%a1%9e%e5%9e%8b%e8%bd%89%e6%8f%9b","status":"publish","type":"post","link":"https:\/\/server.hk\/cnblog\/160529\/","title":{"rendered":"OceanBase \u6559\u7a0b\uff1aOceanBase \u985e\u578b\u8f49\u63db"},"content":{"rendered":"<h1 id=\"oceanbase-%e6%95%99%e7%a8%8b%ef%bc%9aoceanbase-%e9%a1%9e%e5%9e%8b%e8%bd%89%e6%8f%9b-cAbUXuHlup\">OceanBase \u6559\u7a0b\uff1aOceanBase \u985e\u578b\u8f49\u63db<\/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\u5b83\u4e0d\u50c5\u652f\u6301\u9ad8\u4e26\u767c\u7684\u8b80\u5beb\u64cd\u4f5c\uff0c\u9084\u5177\u5099\u826f\u597d\u7684\u64f4\u5c55\u6027\u548c\u5bb9\u932f\u80fd\u529b\u3002\u672c\u6587\u5c07\u6df1\u5165\u63a2\u8a0e OceanBase \u7684\u985e\u578b\u8f49\u63db\u529f\u80fd\uff0c\u5e6b\u52a9\u958b\u767c\u8005\u66f4\u597d\u5730\u7406\u89e3\u5982\u4f55\u5728 OceanBase \u4e2d\u9032\u884c\u6578\u64da\u985e\u578b\u7684\u8f49\u63db\u3002<\/p>\n<h2 id=\"%e4%bb%80%e9%ba%bc%e6%98%af%e9%a1%9e%e5%9e%8b%e8%bd%89%e6%8f%9b%ef%bc%9f-cAbUXuHlup\">\u4ec0\u9ebc\u662f\u985e\u578b\u8f49\u63db\uff1f<\/h2>\n<p>\u985e\u578b\u8f49\u63db\u662f\u6307\u5c07\u4e00\u7a2e\u6578\u64da\u985e\u578b\u7684\u503c\u8f49\u63db\u70ba\u53e6\u4e00\u7a2e\u6578\u64da\u985e\u578b\u7684\u904e\u7a0b\u3002\u5728 OceanBase \u4e2d\uff0c\u985e\u578b\u8f49\u63db\u53ef\u4ee5\u5728\u6578\u64da\u63d2\u5165\u3001\u67e5\u8a62\u548c\u66f4\u65b0\u6642\u767c\u751f\u3002\u9019\u4e00\u904e\u7a0b\u5c0d\u65bc\u78ba\u4fdd\u6578\u64da\u7684\u6b63\u78ba\u6027\u548c\u4e00\u81f4\u6027\u81f3\u95dc\u91cd\u8981\u3002<\/p>\n<h2 id=\"oceanbase-%e4%b8%ad%e7%9a%84%e9%a1%9e%e5%9e%8b%e8%bd%89%e6%8f%9b-cAbUXuHlup\">OceanBase \u4e2d\u7684\u985e\u578b\u8f49\u63db<\/h2>\n<p>OceanBase \u652f\u6301\u591a\u7a2e\u6578\u64da\u985e\u578b\uff0c\u5305\u62ec\u6574\u6578\u3001\u6d6e\u9ede\u6578\u3001\u5b57\u7b26\u4e32\u3001\u65e5\u671f\u7b49\u3002\u7576\u9032\u884c\u985e\u578b\u8f49\u63db\u6642\uff0c\u958b\u767c\u8005\u9700\u8981\u6ce8\u610f\u4ee5\u4e0b\u5e7e\u9ede\uff1a<\/p>\n<ul>\n<li>\u81ea\u52d5\u985e\u578b\u8f49\u63db\uff1a\u5728\u67d0\u4e9b\u60c5\u6cc1\u4e0b\uff0cOceanBase \u6703\u81ea\u52d5\u5c07\u6578\u64da\u985e\u578b\u8f49\u63db\u70ba\u76ee\u6a19\u985e\u578b\u3002\u4f8b\u5982\uff0c\u5c07\u6574\u6578\u63d2\u5165\u5230\u6d6e\u9ede\u6578\u985e\u578b\u7684\u5217\u4e2d\u6642\uff0cOceanBase \u6703\u81ea\u52d5\u9032\u884c\u8f49\u63db\u3002<\/li>\n<li>\u986f\u5f0f\u985e\u578b\u8f49\u63db\uff1a\u958b\u767c\u8005\u53ef\u4ee5\u4f7f\u7528 CAST \u6216 CONVERT \u51fd\u6578\u4f86\u986f\u5f0f\u5730\u9032\u884c\u985e\u578b\u8f49\u63db\u3002\u9019\u6a23\u53ef\u4ee5\u63d0\u9ad8\u4ee3\u78bc\u7684\u53ef\u8b80\u6027\u548c\u53ef\u7dad\u8b77\u6027\u3002<\/li>\n<\/ul>\n<h3 id=\"%e4%bd%bf%e7%94%a8-cast-%e5%87%bd%e6%95%b8%e9%80%b2%e8%a1%8c%e9%a1%9e%e5%9e%8b%e8%bd%89%e6%8f%9b-cAbUXuHlup\">\u4f7f\u7528 CAST \u51fd\u6578\u9032\u884c\u985e\u578b\u8f49\u63db<\/h3>\n<p>CAST \u51fd\u6578\u7684\u8a9e\u6cd5\u5982\u4e0b\uff1a<\/p>\n<pre><code>CAST(expression AS target_data_type)<\/code><\/pre>\n<p>\u4f8b\u5982\uff0c\u5c07\u5b57\u7b26\u4e32\u8f49\u63db\u70ba\u6574\u6578\uff1a<\/p>\n<pre><code>SELECT CAST('123' AS INT);<\/code><\/pre>\n<p>\u9019\u5c07\u8fd4\u56de\u6574\u6578 123\u3002<\/p>\n<h3 id=\"%e4%bd%bf%e7%94%a8-convert-%e5%87%bd%e6%95%b8%e9%80%b2%e8%a1%8c%e9%a1%9e%e5%9e%8b%e8%bd%89%e6%8f%9b-cAbUXuHlup\">\u4f7f\u7528 CONVERT \u51fd\u6578\u9032\u884c\u985e\u578b\u8f49\u63db<\/h3>\n<p>CONVERT \u51fd\u6578\u7684\u8a9e\u6cd5\u5982\u4e0b\uff1a<\/p>\n<pre><code>CONVERT(target_data_type, expression)<\/code><\/pre>\n<p>\u4f8b\u5982\uff0c\u5c07\u6d6e\u9ede\u6578\u8f49\u63db\u70ba\u5b57\u7b26\u4e32\uff1a<\/p>\n<pre><code>SELECT CONVERT(VARCHAR, 123.45);<\/code><\/pre>\n<p>\u9019\u5c07\u8fd4\u56de\u5b57\u7b26\u4e32 &#8216;123.45&#8217;\u3002<\/p>\n<h2 id=\"%e6%b3%a8%e6%84%8f%e4%ba%8b%e9%a0%85-cAbUXuHlup\">\u6ce8\u610f\u4e8b\u9805<\/h2>\n<p>\u5728\u9032\u884c\u985e\u578b\u8f49\u63db\u6642\uff0c\u958b\u767c\u8005\u9700\u8981\u6ce8\u610f\u4ee5\u4e0b\u5e7e\u9ede\uff1a<\/p>\n<ul>\n<li>\u6578\u64da\u4e1f\u5931\uff1a\u67d0\u4e9b\u985e\u578b\u8f49\u63db\u53ef\u80fd\u6703\u5c0e\u81f4\u6578\u64da\u4e1f\u5931\u3002\u4f8b\u5982\uff0c\u5c07\u6d6e\u9ede\u6578\u8f49\u63db\u70ba\u6574\u6578\u6642\uff0c\u5c0f\u6578\u90e8\u5206\u5c07\u88ab\u622a\u65b7\u3002<\/li>\n<li>\u683c\u5f0f\u932f\u8aa4\uff1a\u5728\u5c07\u5b57\u7b26\u4e32\u8f49\u63db\u70ba\u65e5\u671f\u6216\u6578\u5b57\u6642\uff0c\u5fc5\u9808\u78ba\u4fdd\u5b57\u7b26\u4e32\u7684\u683c\u5f0f\u6b63\u78ba\uff0c\u5426\u5247\u5c07\u6703\u5f15\u767c\u932f\u8aa4\u3002<\/li>\n<li>\u6027\u80fd\u5f71\u97ff\uff1a\u983b\u7e41\u7684\u985e\u578b\u8f49\u63db\u53ef\u80fd\u6703\u5f71\u97ff\u67e5\u8a62\u6027\u80fd\uff0c\u56e0\u6b64\u61c9\u8b39\u614e\u4f7f\u7528\u3002<\/li>\n<\/ul>\n<h2 id=\"%e5%af%a6%e9%9a%9b%e6%87%89%e7%94%a8%e6%a1%88%e4%be%8b-cAbUXuHlup\">\u5be6\u969b\u61c9\u7528\u6848\u4f8b<\/h2>\n<p>\u5047\u8a2d\u6211\u5011\u6709\u4e00\u500b\u7528\u6236\u8868\uff0c\u5305\u542b\u7528\u6236\u7684 ID\u3001\u59d3\u540d\u548c\u8a3b\u518a\u6642\u9593\u3002\u7528\u6236 ID \u662f\u6574\u6578\u985e\u578b\uff0c\u8a3b\u518a\u6642\u9593\u662f\u5b57\u7b26\u4e32\u985e\u578b\u3002\u7576\u6211\u5011\u9700\u8981\u67e5\u8a62\u7528\u6236\u7684\u8a3b\u518a\u6642\u9593\u4e26\u5c07\u5176\u8f49\u63db\u70ba\u65e5\u671f\u985e\u578b\u6642\uff0c\u53ef\u4ee5\u4f7f\u7528\u4ee5\u4e0b SQL \u8a9e\u53e5\uff1a<\/p>\n<pre><code>SELECT ID, NAME, CAST(REGISTRATION_TIME AS DATE) AS REGISTRATION_DATE FROM USERS;<\/code><\/pre>\n<p>\u9019\u6a23\u53ef\u4ee5\u65b9\u4fbf\u5730\u7372\u53d6\u7528\u6236\u7684\u8a3b\u518a\u65e5\u671f\uff0c\u4e26\u9032\u884c\u9032\u4e00\u6b65\u7684\u6578\u64da\u5206\u6790\u3002<\/p>\n<h2 id=\"%e7%b5%90%e8%ab%96-cAbUXuHlup\">\u7d50\u8ad6<\/h2>\n<p>OceanBase \u7684\u985e\u578b\u8f49\u63db\u529f\u80fd\u70ba\u958b\u767c\u8005\u63d0\u4f9b\u4e86\u9748\u6d3b\u7684\u6578\u64da\u8655\u7406\u80fd\u529b\u3002\u901a\u904e\u5408\u7406\u4f7f\u7528 CAST \u548c CONVERT \u51fd\u6578\uff0c\u958b\u767c\u8005\u53ef\u4ee5\u6709\u6548\u5730\u7ba1\u7406\u6578\u64da\u985e\u578b\uff0c\u78ba\u4fdd\u6578\u64da\u7684\u6b63\u78ba\u6027\u548c\u4e00\u81f4\u6027\u3002\u5728\u5be6\u969b\u958b\u767c\u4e2d\uff0c\u4e86\u89e3\u985e\u578b\u8f49\u63db\u7684\u7279\u6027\u548c\u6ce8\u610f\u4e8b\u9805\u5c07\u6709\u52a9\u65bc\u63d0\u9ad8\u61c9\u7528\u7a0b\u5e8f\u7684\u6027\u80fd\u548c\u7a69\u5b9a\u6027\u3002<\/p>\n<p>\u5982\u9700\u4e86\u89e3\u66f4\u591a\u95dc\u65bc <a href=\"https:\/\/server.hk\">VPS<\/a> \u548c <a href=\"https:\/\/server.hk\">\u9999\u6e2f\u4f3a\u670d\u5668<\/a> \u7684\u8cc7\u8a0a\uff0c\u8acb\u8a2a\u554f\u6211\u5011\u7684\u7db2\u7ad9\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u63a2\u7d22 OceanBase \u6559\u7a0b\uff0c\u5b78\u7fd2\u5982\u4f55\u9032\u884c\u985e\u578b\u8f49\u63db\uff0c\u63d0\u5347\u6578\u64da\u8655\u7406\u6548\u7387\uff0c\u638c\u63e1\u95dc\u9375\u6280\u5de7\uff0c\u512a\u5316\u6578\u64da\u5eab\u64cd\u4f5c\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-160529","post","type-post","status-publish","format-standard","hentry","category-database"],"_links":{"self":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/160529","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=160529"}],"version-history":[{"count":1,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/160529\/revisions"}],"predecessor-version":[{"id":160530,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/160529\/revisions\/160530"}],"wp:attachment":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/media?parent=160529"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/categories?post=160529"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/tags?post=160529"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}