{"id":160073,"date":"2024-11-03T20:03:21","date_gmt":"2024-11-03T12:03:21","guid":{"rendered":"https:\/\/server.hk\/cnblog\/160073\/"},"modified":"2024-11-03T20:03:22","modified_gmt":"2024-11-03T12:03:22","slug":"oceanbase-%e6%95%99%e7%a8%8b%ef%bc%9aoceanbase-cast","status":"publish","type":"post","link":"https:\/\/server.hk\/cnblog\/160073\/","title":{"rendered":"OceanBase \u6559\u7a0b\uff1aOceanBase CAST"},"content":{"rendered":"<h1 id=\"oceanbase-%e6%95%99%e7%a8%8b%ef%bc%9aoceanbase-cast-EIkOiHnjaC\">OceanBase \u6559\u7a0b\uff1aOceanBase CAST<\/h1>\n<p>\u5728\u7576\u4eca\u7684\u6578\u64da\u5eab\u6280\u8853\u4e2d\uff0cOceanBase \u4f5c\u70ba\u4e00\u500b\u9ad8\u6027\u80fd\u7684\u5206\u4f48\u5f0f\u6578\u64da\u5eab\u7cfb\u7d71\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\u4e8b\u52d9\u8655\u7406\uff0c\u9084\u5177\u5099\u826f\u597d\u7684\u64f4\u5c55\u6027\u548c\u5bb9\u932f\u80fd\u529b\u3002\u672c\u6587\u5c07\u91cd\u9ede\u4ecb\u7d39 OceanBase \u4e2d\u7684 CAST \u51fd\u6578\uff0c\u5e6b\u52a9\u8b80\u8005\u66f4\u597d\u5730\u7406\u89e3\u5176\u7528\u6cd5\u53ca\u61c9\u7528\u5834\u666f\u3002<\/p>\n<h2 id=\"%e4%bb%80%e9%ba%bc%e6%98%af-cast-%e5%87%bd%e6%95%b8%ef%bc%9f-EIkOiHnjaC\">\u4ec0\u9ebc\u662f CAST \u51fd\u6578\uff1f<\/h2>\n<p>CAST \u51fd\u6578\u662f\u4e00\u500b SQL \u51fd\u6578\uff0c\u7528\u65bc\u5c07\u4e00\u500b\u6578\u64da\u985e\u578b\u8f49\u63db\u70ba\u53e6\u4e00\u500b\u6578\u64da\u985e\u578b\u3002\u5728 OceanBase \u4e2d\uff0cCAST \u51fd\u6578\u7684\u4f7f\u7528\u975e\u5e38\u5ee3\u6cdb\uff0c\u7279\u5225\u662f\u5728\u6578\u64da\u985e\u578b\u4e0d\u5339\u914d\u7684\u60c5\u6cc1\u4e0b\u3002\u9019\u500b\u51fd\u6578\u7684\u57fa\u672c\u8a9e\u6cd5\u5982\u4e0b\uff1a<\/p>\n<pre><code>CAST(expression AS target_data_type)<\/code><\/pre>\n<p>\u5176\u4e2d\uff0c<code>expression<\/code> \u662f\u8981\u8f49\u63db\u7684\u503c\uff0c\u800c <code>target_data_type<\/code> \u5247\u662f\u5e0c\u671b\u8f49\u63db\u6210\u7684\u6578\u64da\u985e\u578b\u3002<\/p>\n<h2 id=\"cast-%e5%87%bd%e6%95%b8%e7%9a%84%e4%bd%bf%e7%94%a8%e7%a4%ba%e4%be%8b-EIkOiHnjaC\">CAST \u51fd\u6578\u7684\u4f7f\u7528\u793a\u4f8b<\/h2>\n<p>\u4ee5\u4e0b\u662f\u4e00\u4e9b\u4f7f\u7528 CAST \u51fd\u6578\u7684\u793a\u4f8b\uff0c\u5e6b\u52a9\u8b80\u8005\u66f4\u597d\u5730\u7406\u89e3\u5176\u61c9\u7528\uff1a<\/p>\n<h3 id=\"%e7%a4%ba%e4%be%8b-1%ef%bc%9a%e5%b0%87%e5%ad%97%e7%ac%a6%e4%b8%b2%e8%bd%89%e6%8f%9b%e7%82%ba%e6%95%b4%e6%95%b8-EIkOiHnjaC\">\u793a\u4f8b 1\uff1a\u5c07\u5b57\u7b26\u4e32\u8f49\u63db\u70ba\u6574\u6578<\/h3>\n<pre><code>SELECT CAST('123' AS INT) AS converted_value;<\/code><\/pre>\n<p>\u5728\u9019\u500b\u4f8b\u5b50\u4e2d\uff0c\u5b57\u7b26\u4e32 &#8216;123&#8217; \u88ab\u8f49\u63db\u70ba\u6574\u6578 123\uff0c\u7d50\u679c\u5c07\u986f\u793a\u70ba <code>converted_value<\/code>\u3002<\/p>\n<h3 id=\"%e7%a4%ba%e4%be%8b-2%ef%bc%9a%e5%b0%87%e6%95%b4%e6%95%b8%e8%bd%89%e6%8f%9b%e7%82%ba%e6%b5%ae%e9%bb%9e%e6%95%b8-EIkOiHnjaC\">\u793a\u4f8b 2\uff1a\u5c07\u6574\u6578\u8f49\u63db\u70ba\u6d6e\u9ede\u6578<\/h3>\n<pre><code>SELECT CAST(10 AS FLOAT) AS converted_value;<\/code><\/pre>\n<p>\u9019\u88e1\uff0c\u6574\u6578 10 \u88ab\u8f49\u63db\u70ba\u6d6e\u9ede\u6578 10.0\uff0c\u7d50\u679c\u540c\u6a23\u986f\u793a\u70ba <code>converted_value<\/code>\u3002<\/p>\n<h3 id=\"%e7%a4%ba%e4%be%8b-3%ef%bc%9a%e5%b0%87%e6%97%a5%e6%9c%9f%e8%bd%89%e6%8f%9b%e7%82%ba%e5%ad%97%e7%ac%a6%e4%b8%b2-EIkOiHnjaC\">\u793a\u4f8b 3\uff1a\u5c07\u65e5\u671f\u8f49\u63db\u70ba\u5b57\u7b26\u4e32<\/h3>\n<pre><code>SELECT CAST(CURRENT_DATE AS CHAR) AS converted_value;<\/code><\/pre>\n<p>\u5728\u9019\u500b\u4f8b\u5b50\u4e2d\uff0c\u7576\u524d\u65e5\u671f\u88ab\u8f49\u63db\u70ba\u5b57\u7b26\u4e32\u683c\u5f0f\uff0c\u7d50\u679c\u5c07\u986f\u793a\u70ba <code>converted_value<\/code>\u3002<\/p>\n<h2 id=\"cast-%e5%87%bd%e6%95%b8%e7%9a%84%e6%b3%a8%e6%84%8f%e4%ba%8b%e9%a0%85-EIkOiHnjaC\">CAST \u51fd\u6578\u7684\u6ce8\u610f\u4e8b\u9805<\/h2>\n<p>\u5728\u4f7f\u7528 CAST \u51fd\u6578\u6642\uff0c\u6709\u5e7e\u9ede\u9700\u8981\u7279\u5225\u6ce8\u610f\uff1a<\/p>\n<ul>\n<li><strong>\u6578\u64da\u985e\u578b\u517c\u5bb9\u6027\uff1a<\/strong>\u78ba\u4fdd\u8981\u8f49\u63db\u7684\u6578\u64da\u985e\u578b\u4e4b\u9593\u662f\u517c\u5bb9\u7684\uff0c\u5426\u5247\u53ef\u80fd\u6703\u5c0e\u81f4\u932f\u8aa4\u3002<\/li>\n<li><strong>\u7cbe\u5ea6\u640d\u5931\uff1a<\/strong>\u5728\u5c07\u6d6e\u9ede\u6578\u8f49\u63db\u70ba\u6574\u6578\u6642\uff0c\u53ef\u80fd\u6703\u51fa\u73fe\u7cbe\u5ea6\u640d\u5931\u7684\u60c5\u6cc1\uff0c\u9700\u8b39\u614e\u8655\u7406\u3002<\/li>\n<li><strong>NULL \u503c\u8655\u7406\uff1a<\/strong>\u5982\u679c\u8981\u8f49\u63db\u7684\u503c\u70ba NULL\uff0c\u5247\u8f49\u63db\u7d50\u679c\u4e5f\u5c07\u662f NULL\u3002<\/li>\n<\/ul>\n<h2 id=\"cast-%e5%87%bd%e6%95%b8%e7%9a%84%e6%87%89%e7%94%a8%e5%a0%b4%e6%99%af-EIkOiHnjaC\">CAST \u51fd\u6578\u7684\u61c9\u7528\u5834\u666f<\/h2>\n<p>CAST \u51fd\u6578\u5728\u5be6\u969b\u958b\u767c\u4e2d\u6709\u591a\u7a2e\u61c9\u7528\u5834\u666f\uff0c\u4f8b\u5982\uff1a<\/p>\n<ul>\n<li><strong>\u6578\u64da\u6e05\u6d17\uff1a<\/strong>\u5728\u6578\u64da\u6e05\u6d17\u904e\u7a0b\u4e2d\uff0c\u7d93\u5e38\u9700\u8981\u5c07\u4e0d\u540c\u985e\u578b\u7684\u6578\u64da\u9032\u884c\u8f49\u63db\uff0c\u4ee5\u4fbf\u9032\u884c\u7d71\u4e00\u8655\u7406\u3002<\/li>\n<li><strong>\u5831\u8868\u751f\u6210\uff1a<\/strong>\u5728\u751f\u6210\u5831\u8868\u6642\uff0c\u53ef\u80fd\u9700\u8981\u5c07\u6578\u64da\u683c\u5f0f\u9032\u884c\u8f49\u63db\uff0c\u4ee5\u4fbf\u65bc\u5c55\u793a\u548c\u5206\u6790\u3002<\/li>\n<li><strong>\u6578\u64da\u5eab\u9077\u79fb\uff1a<\/strong>\u5728\u6578\u64da\u5eab\u9077\u79fb\u904e\u7a0b\u4e2d\uff0c\u53ef\u80fd\u9700\u8981\u5c07\u67d0\u4e9b\u5b57\u6bb5\u7684\u6578\u64da\u985e\u578b\u9032\u884c\u8f49\u63db\uff0c\u4ee5\u7b26\u5408\u65b0\u6578\u64da\u5eab\u7684\u8981\u6c42\u3002<\/li>\n<\/ul>\n<h2 id=\"%e7%b8%bd%e7%b5%90-EIkOiHnjaC\">\u7e3d\u7d50<\/h2>\n<p>CAST \u51fd\u6578\u5728 OceanBase \u4e2d\u662f\u4e00\u500b\u975e\u5e38\u91cd\u8981\u7684\u5de5\u5177\uff0c\u80fd\u5920\u5e6b\u52a9\u958b\u767c\u8005\u9748\u6d3b\u5730\u8655\u7406\u6578\u64da\u985e\u578b\u8f49\u63db\u554f\u984c\u3002\u7121\u8ad6\u662f\u5728\u6578\u64da\u6e05\u6d17\u3001\u5831\u8868\u751f\u6210\u9084\u662f\u6578\u64da\u5eab\u9077\u79fb\u4e2d\uff0c\u6b63\u78ba\u4f7f\u7528 CAST \u51fd\u6578\u90fd\u80fd\u63d0\u9ad8\u5de5\u4f5c\u6548\u7387\u548c\u6578\u64da\u8655\u7406\u7684\u6e96\u78ba\u6027\u3002\u5982\u679c\u60a8\u5c0d\u65bc <a href=\"https:\/\/server.hk\">\u9999\u6e2f VPS<\/a> \u670d\u52d9\u611f\u8208\u8da3\uff0c\u6b61\u8fce\u8a2a\u554f\u6211\u5011\u7684\u7db2\u7ad9\u4ee5\u7372\u53d6\u66f4\u591a\u8cc7\u8a0a\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Discover the OceanBase CAST tutorial, a comprehensive guide to mastering data type conversion in OceanBase for efficient database management.<\/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-160073","post","type-post","status-publish","format-standard","hentry","category-database"],"_links":{"self":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/160073","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=160073"}],"version-history":[{"count":1,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/160073\/revisions"}],"predecessor-version":[{"id":160074,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/160073\/revisions\/160074"}],"wp:attachment":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/media?parent=160073"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/categories?post=160073"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/tags?post=160073"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}