{"id":1060,"date":"2020-09-08T10:43:45","date_gmt":"2020-09-08T02:43:45","guid":{"rendered":"http:\/\/www.gbase8.cn\/?p=1060"},"modified":"2022-05-16T14:22:43","modified_gmt":"2022-05-16T06:22:43","slug":"gbase-8a%e8%87%aa%e5%ae%9a%e4%b9%89%e5%87%bd%e6%95%b0%e6%a0%b7%e4%be%8b","status":"publish","type":"post","link":"https:\/\/www.gbase8.cn\/en\/1060","title":{"rendered":"\u5357\u5927\u901a\u7528GBase 8a\u81ea\u5b9a\u4e49\u51fd\u6570UDF\u6837\u4f8b\uff0c\u6d89\u53ca\u8868\u4e0d\u80fd\u662f\u968f\u673a\u8868\uff0c\u5fc5\u987b\u662f\u590d\u5236\u8868"},"content":{"rendered":"<p>GBase 8a\u6570\u636e\u5e93\u96c6\u7fa4\uff0c\u652f\u6301\u81ea\u5b9a\u4e49\u51fd\u6570\uff0c\u6765\u5b9e\u73b0\u516c\u7528\u7684\u529f\u80fd\u3002\u5176\u652f\u6301\u6807\u51c6\u76840-\u591a\u4e2a\u8f93\u5165\u53c2\u6570\u548c\u4e00\u4e2a\u8fd4\u56de\u503c\u3002\u5982\u679c\u6ca1\u6709\u8fd4\u56de\u503c\uff0c\u5efa\u8bae\u4f7f\u7528\u5b58\u50a8\u8fc7\u7a0b\u3002<\/p>\n\n\n\n<p>\u5982\u679c\u5728\u81ea\u5b9a\u4e49\u51fd\u6570\u91cc\u4f7f\u7528\u4e86\u8868\uff0c\u5219\u5fc5\u987b\u662f\u3010\u590d\u5236\u8868\u3011\uff0c\u4e0d\u80fd\u662f\u968f\u5373\u8868\u3002<\/p>\n\n\n\n<div id=\"ez-toc-container\" class=\"ez-toc-v2_0_84 counter-hierarchy ez-toc-counter ez-toc-grey ez-toc-container-direction\">\n<p class=\"ez-toc-title\" style=\"cursor:inherit\">Directory Navigation<\/p>\n<label for=\"ez-toc-cssicon-toggle-item-6a2aea2f078e1\" class=\"ez-toc-cssicon-toggle-label\"><span class=\"\"><span class=\"eztoc-hide\" style=\"display:none;\">Toggle<\/span><span class=\"ez-toc-icon-toggle-span\"><svg style=\"fill: #999;color:#999\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\" class=\"list-377408\" width=\"20px\" height=\"20px\" viewbox=\"0 0 24 24\" fill=\"none\"><path d=\"M6 6H4v2h2V6zm14 0H8v2h12V6zM4 11h2v2H4v-2zm16 0H8v2h12v-2zM4 16h2v2H4v-2zm16 0H8v2h12v-2z\" fill=\"currentColor\"><\/path><\/svg><svg style=\"fill: #999;color:#999\" class=\"arrow-unsorted-368013\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"10px\" height=\"10px\" viewbox=\"0 0 24 24\" version=\"1.2\" baseprofile=\"tiny\"><path d=\"M18.2 9.3l-6.2-6.3-6.2 6.3c-.2.2-.3.4-.3.7s.1.5.3.7c.2.2.4.3.7.3h11c.3 0 .5-.1.7-.3.2-.2.3-.5.3-.7s-.1-.5-.3-.7zM5.8 14.7l6.2 6.3 6.2-6.3c.2-.2.3-.5.3-.7s-.1-.5-.3-.7c-.2-.2-.4-.3-.7-.3h-11c-.3 0-.5.1-.7.3-.2.2-.3.5-.3.7s.1.5.3.7z\"\/><\/svg><\/span><\/span><\/label><input type=\"checkbox\"  id=\"ez-toc-cssicon-toggle-item-6a2aea2f078e1\"  aria-label=\"Toggle\" \/><nav><ul class='ez-toc-list ez-toc-list-level-1' ><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-1\" href=\"https:\/\/www.gbase8.cn\/en\/1060\/#%E8%87%AA%E5%AE%9A%E4%B9%89%E5%87%BD%E6%95%B0%E6%A0%B7%E4%BE%8B\" >\u81ea\u5b9a\u4e49\u51fd\u6570\u6837\u4f8b<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-2\" href=\"https:\/\/www.gbase8.cn\/en\/1060\/#%E6%89%A7%E8%A1%8C%E7%BB%93%E6%9E%9C\" >\u6267\u884c\u7ed3\u679c<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-3\" href=\"https:\/\/www.gbase8.cn\/en\/1060\/#%E6%B3%A8%E6%84%8F\" >\u6ce8\u610f<\/a><ul class='ez-toc-list-level-4' ><li class='ez-toc-heading-level-4'><a class=\"ez-toc-link ez-toc-heading-4\" href=\"https:\/\/www.gbase8.cn\/en\/1060\/#%E5%A6%82%E7%94%A8%E5%88%B0%E4%BA%86%E8%A1%A8%EF%BC%8C%E5%88%99%E5%BF%85%E9%A1%BB%E6%98%AF%E5%A4%8D%E5%88%B6%E8%A1%A8\" >\u5982\u7528\u5230\u4e86\u8868\uff0c\u5219\u5fc5\u987b\u662f\u590d\u5236\u8868<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-4'><a class=\"ez-toc-link ez-toc-heading-5\" href=\"https:\/\/www.gbase8.cn\/en\/1060\/#%E5%A6%82%E7%94%A8%E5%88%B0%E4%BA%86%E5%A4%8D%E5%88%B6%E8%A1%A8%EF%BC%8C%E5%88%99%E7%9B%B4%E6%8E%A5select%E5%BF%85%E9%A1%BB%E5%8A%A0%E4%B8%8Afrom\" >\u5982\u7528\u5230\u4e86\u590d\u5236\u8868\uff0c\u5219\u76f4\u63a5select\u5fc5\u987b\u52a0\u4e0afrom<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-4'><a class=\"ez-toc-link ez-toc-heading-6\" href=\"https:\/\/www.gbase8.cn\/en\/1060\/#%E6%B5%8B%E8%AF%95%E8%87%AA%E5%AE%9A%E4%B9%89%E5%87%BD%E6%95%B0%E6%A0%B7%E4%BE%8B\" >\u6d4b\u8bd5\u81ea\u5b9a\u4e49\u51fd\u6570\u6837\u4f8b<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-4'><a class=\"ez-toc-link ez-toc-heading-7\" href=\"https:\/\/www.gbase8.cn\/en\/1060\/#%E6%B5%8B%E8%AF%95%E8%A1%A8\" >\u6d4b\u8bd5\u8868<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-4'><a class=\"ez-toc-link ez-toc-heading-8\" href=\"https:\/\/www.gbase8.cn\/en\/1060\/#%E6%B5%8B%E8%AF%95%E7%BB%93%E6%9E%9C\" >\u6d4b\u8bd5\u7ed3\u679c<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-4'><a class=\"ez-toc-link ez-toc-heading-9\" href=\"https:\/\/www.gbase8.cn\/en\/1060\/#%E6%94%B9%E6%88%90%E5%A4%8D%E5%88%B6%E8%A1%A8\" >\u6539\u6210\u590d\u5236\u8868<\/a><\/li><\/ul><\/li><\/ul><\/nav><\/div>\n<h3 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"%E8%87%AA%E5%AE%9A%E4%B9%89%E5%87%BD%E6%95%B0%E6%A0%B7%E4%BE%8B\"><\/span>\u81ea\u5b9a\u4e49\u51fd\u6570\u6837\u4f8b<span class=\"ez-toc-section-end\"><\/span><\/h3>\n\n\n\n<pre class=\"wp-block-code\"><code>drop function if exists f_test;\ndelimiter \/\/\ncreate function f_test(inDate datetime) returns datetime\nbegin\n  return date_add(inDate, interval 1 day);\nend \/\/\ndelimiter ;\n<\/code><\/pre>\n\n\n\n<p>\u5176\u4e2df_test\u662f\u81ea\u5b9a\u4e49\u51fd\u6570\u540d\u5b57<br>\u5c0f\u62ec\u53f7\u91cc\u662f\u8f93\u5165\u53c2\u6570\uff0c inDate \u662f\u65e5\u671f\u7c7b\u578b<br>returns \u540e\u9762\u662f\u8fd4\u56de\u7c7b\u578b datetime<br>\u51fd\u6570\u4ee5BEGIN\u548cEND\u7ed3\u5c3e<br>\u8ba1\u7b97\u7ed3\u679c\uff0c\u4ee5return \u8fd4\u56de<\/p>\n\n\n\n<h3 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"%E6%89%A7%E8%A1%8C%E7%BB%93%E6%9E%9C\"><\/span>\u6267\u884c\u7ed3\u679c<span class=\"ez-toc-section-end\"><\/span><\/h3>\n\n\n\n<pre class=\"wp-block-code\"><code>gbase&gt; select now(),f_test(now());\n+---------------------+---------------------+\n| now()               | f_test(now())       |\n+---------------------+---------------------+\n| 2020-09-03 21:12:50 | 2020-09-04 21:12:50 |\n+---------------------+---------------------+\n1 row in set (Elapsed: 00:00:00.00)\n<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"%E6%B3%A8%E6%84%8F\"><\/span>\u6ce8\u610f<span class=\"ez-toc-section-end\"><\/span><\/h3>\n\n\n\n<h4 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"%E5%A6%82%E7%94%A8%E5%88%B0%E4%BA%86%E8%A1%A8%EF%BC%8C%E5%88%99%E5%BF%85%E9%A1%BB%E6%98%AF%E5%A4%8D%E5%88%B6%E8%A1%A8\"><\/span>\u5982\u7528\u5230\u4e86\u8868\uff0c\u5219\u5fc5\u987b\u662f\u590d\u5236\u8868<span class=\"ez-toc-section-end\"><\/span><\/h4>\n\n\n\n<p>\u5982\u679c\u4f60\u5728\u81ea\u5b9a\u4e49\u51fd\u6570\u91cc\u4f7f\u7528\u4e86\u8868\uff0c\u90a3\u4e48\u5fc5\u987b\u662f\u590d\u5236\u8868\uff0c\u5426\u5219\u4f1a\u62a5\u8868\u627e\u4e0d\u5230\u7684\u9519\u8bef\u4fe1\u606f\uff1aDETAIL: Table 'testdb.t1' doesn't exist\u3002<\/p>\n\n\n\n<p>\u5224\u65ad\u662f\u81ea\u5b9a\u4e49\u51fd\u6570\uff0c\u7406\u8bba\u4e0a\u5728\u4efb\u4f55\u8282\u70b9\u6267\u884c\uff0c\u76f8\u540c\u7684\u8f93\u5165\u5e94\u8be5\u8fd4\u56de\u76f8\u540c\u7684\u7ed3\u679c(\u9664\u975e\u4f60\u6545\u610f\u91cc\u9762\u968f\u673a\u6570\uff09\uff0c\u5176\u4e2d\u7684\u6d89\u53ca\u7684\u8868\u4e5f\u5e94\u8be5\u8fd4\u56de\u76f8\u540c\u7ed3\u679c\u3002\u4f46\u5982\u679c\u662f\u968f\u673a\u5206\u5e03\u8868\uff0c\u90a3\u4e48\u76f8\u540c\u7684SQL\u5728\u6bcf\u4e2a\u8282\u70b9\u6267\u884c\u65f6\uff0c\u8fd4\u56de\u7ed3\u679c\u3010\u6781\u5927\u53ef\u80fd\u3011\u662f\u4e0d\u4e00\u81f4\u7684\u3002\u6240\u4ee5\u4e3a\u4e86\u4fdd\u8bc1\u4e00\u81f4\u6027\uff0c\u8981\u6c42\u590d\u5236\u8868\uff0c\u6bcf\u4e2a\u8282\u70b9\u7684\u6570\u636e\u5b8c\u5168\u4e00\u81f4\u4e86\u3002<\/p>\n\n\n\n<p>\u5efa\u8bae\u7528\u5b58\u50a8\u8fc7\u7a0b\u6765\u5b9e\u73b0\u6d89\u53ca\u5206\u5e03\u8868\u7684\u81ea\u5b9a\u4e49\u529f\u80fd\u3002<\/p>\n\n\n\n<h4 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"%E5%A6%82%E7%94%A8%E5%88%B0%E4%BA%86%E5%A4%8D%E5%88%B6%E8%A1%A8%EF%BC%8C%E5%88%99%E7%9B%B4%E6%8E%A5select%E5%BF%85%E9%A1%BB%E5%8A%A0%E4%B8%8Afrom\"><\/span>\u5982\u7528\u5230\u4e86\u590d\u5236\u8868\uff0c\u5219\u76f4\u63a5select\u5fc5\u987b\u52a0\u4e0afrom<span class=\"ez-toc-section-end\"><\/span><\/h4>\n\n\n\n<p>\u5982\u679c\u6ca1\u6709\u7528\u5230\u8868\uff0c\u5219\u53ef\u4ee5\u76f4\u63a5 select XXXX(); \u5982\u679c\u7528\u5230\u4e86\uff0c\u5219\u5fc5\u987b\u7528 select XXX from \u8868\u540d\uff0c \u5982\u679c\u5c31\u8fd4\u56de\u4e00\u884c\uff0c\u53ef\u4ee5\u7528select XXX() from dual<\/p>\n\n\n\n<p>\u5426\u5219\u4f1a\u62a5\u9519<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>gbase> select udfKQIScore('123');\r\nERROR 1149 (42000): (GBA-02SC-1001) The query includes syntax that is not supported by the gcluster.<\/code><\/pre>\n\n\n\n<h4 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"%E6%B5%8B%E8%AF%95%E8%87%AA%E5%AE%9A%E4%B9%89%E5%87%BD%E6%95%B0%E6%A0%B7%E4%BE%8B\"><\/span>\u6d4b\u8bd5\u81ea\u5b9a\u4e49\u51fd\u6570\u6837\u4f8b<span class=\"ez-toc-section-end\"><\/span><\/h4>\n\n\n\n<pre class=\"wp-block-code\"><code>drop function if exists f_test2;\ndelimiter \/\/\ncreate function f_test2(v_id int) returns varchar\nbegin\n  select num into @v from t1 where id=v_id;\n  return @v;\nend \/\/\ndelimiter ;<\/code><\/pre>\n\n\n\n<h4 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"%E6%B5%8B%E8%AF%95%E8%A1%A8\"><\/span>\u6d4b\u8bd5\u8868<span class=\"ez-toc-section-end\"><\/span><\/h4>\n\n\n\n<pre class=\"wp-block-code\"><code>gbase&gt; show create table t1;\n+-------+----------------------------------------------------------------------------------------------------------------------------------------------------------+\n| Table | Create Table                                                                                                                                             |\n+-------+----------------------------------------------------------------------------------------------------------------------------------------------------------+\n| t1    | CREATE TABLE \"t1\" (\n  \"id\" bigint(20) DEFAULT NULL,\n  \"num\" decimal(20,0) DEFAULT NULL\n) ENGINE=EXPRESS DEFAULT CHARSET=utf8 TABLESPACE='sys_tablespace' |\n+-------+----------------------------------------------------------------------------------------------------------------------------------------------------------+\n1 row in set (Elapsed: 00:00:00.00)\n<\/code><\/pre>\n\n\n\n<h4 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"%E6%B5%8B%E8%AF%95%E7%BB%93%E6%9E%9C\"><\/span>\u6d4b\u8bd5\u7ed3\u679c<span class=\"ez-toc-section-end\"><\/span><\/h4>\n\n\n\n<p>\u76f4\u63a5\u62a5\u8868\u4e0d\u5b58\u5728\u7684\u9519\u8bef<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>gbase&gt; select f_test2(1) from t1;\nERROR 1708 (HY000): &#91;10.0.2.101:5050](GBA-02AD-0005)Failed to query in gnode:\nDETAIL: Table 'testdb.t1' doesn't exist\nSQL: SELECT \/*10.0.2.101_250_22_2020-09-23_18:07:16*\/ \/*+ TID('3014950') *\/ \"testdb\".\"f_test2\"(1) AS `f_test2(1)` FROM `testdb`.`t1_n1` `testdb.t1`\n<\/code><\/pre>\n\n\n\n<h4 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"%E6%94%B9%E6%88%90%E5%A4%8D%E5%88%B6%E8%A1%A8\"><\/span>\u6539\u6210\u590d\u5236\u8868<span class=\"ez-toc-section-end\"><\/span><\/h4>\n\n\n\n<p>\u4e00\u5207\u6b63\u5e38\u4e86\u3002<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>gbase&gt; rename table t1 to t1_dis;\nQuery OK, 0 rows affected (Elapsed: 00:00:00.38)\n\ngbase&gt; create table t1 replicated as select * from t1_dis;\nQuery OK, 0 rows affected (Elapsed: 00:00:00.45)\n\ngbase&gt; show create table t1;\n+-------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------+\n| Table | Create Table                                                                                                                                                         |\n+-------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------+\n| t1    | CREATE TABLE \"t1\" (\n  \"id\" bigint(20) DEFAULT NULL,\n  \"num\" decimal(20,0) DEFAULT NULL\n) ENGINE=EXPRESS REPLICATED  DEFAULT CHARSET=utf8 TABLESPACE='sys_tablespace' |\n+-------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------+\n1 row in set (Elapsed: 00:00:00.00)\n\ngbase&gt; select f_test2(1) from t1;\nEmpty set, 1 warning (Elapsed: 00:00:00.03)\n\ngbase&gt; select * from t1;\n\\Empty set (Elapsed: 00:00:00.02)\n\ngbase&gt; insert into t1 values(1,121212);\nQuery OK, 1 row affected (Elapsed: 00:00:00.35)\n\ngbase&gt; select f_test2(1) from t1;\n+------------+\n| f_test2(1) |\n+------------+\n| 121212     |\n+------------+\n1 row in set (Elapsed: 00:00:00.02)\n<\/code><\/pre>\n\n\n\n<p>\u81ea\u5b9a\u4e49\u5b58\u50a8\u8fc7\u7a0b\u6837\u4f8b\uff0c\u8bf7\u53c2\u8003<\/p>\n\n\n\n<p><a href=\"http:\/\/www.gbase8.cn\/en\/?p=226\">GBase 8a\u96c6\u7fa4\u5b58\u50a8\u8fc7\u7a0b\u6837\u4f8b\uff0c\u52a8\u6001\u5b58\u50a8\u8fc7\u7a0b<\/a><\/p>\n\n\n\n<p>\u5176\u5b83\u6570\u636e\u5e93\u5185\u7f6e\u51fd\u6570\uff0c\u8bf7\u53c2\u8003 <\/p>\n\n\n\n<p><a href=\"http:\/\/www.gbase8.cn\/en\/?tag=%e5%87%bd%e6%95%b0\">http:\/\/www.gbase8.cn\/?tag=%e5%87%bd%e6%95%b0<\/a><\/p>","protected":false},"excerpt":{"rendered":"<p>\u5357\u5927\u901a\u7528GBase 8a\u6570\u636e\u5e93\u96c6\u7fa4\uff0c\u652f\u6301\u81ea\u5b9a\u4e49\u51fd\u6570\uff0c\u6765\u5b9e\u73b0\u516c\u7528\u7684\u529f\u80fd\u3002\u5176\u652f\u6301\u6807\u51c6\u76840-\u591a\u4e2a\u8f93\u5165\u53c2\u6570\u548c\u4e00\u4e2a\u8fd4\u56de\u503c\u3002\u5982\u679c\u6ca1\u6709\u8fd4\u56de\u503c\uff0c\u5efa\u8bae\u4f7f\u7528\u5b58\u50a8\u8fc7\u7a0b\u3002<\/p>","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[3],"tags":[36,91],"class_list":["post-1060","post","type-post","status-publish","format-standard","hentry","category-gbase8a","tag-36","tag-udf"],"_links":{"self":[{"href":"https:\/\/www.gbase8.cn\/en\/wp-json\/wp\/v2\/posts\/1060","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.gbase8.cn\/en\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.gbase8.cn\/en\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.gbase8.cn\/en\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.gbase8.cn\/en\/wp-json\/wp\/v2\/comments?post=1060"}],"version-history":[{"count":7,"href":"https:\/\/www.gbase8.cn\/en\/wp-json\/wp\/v2\/posts\/1060\/revisions"}],"predecessor-version":[{"id":9390,"href":"https:\/\/www.gbase8.cn\/en\/wp-json\/wp\/v2\/posts\/1060\/revisions\/9390"}],"wp:attachment":[{"href":"https:\/\/www.gbase8.cn\/en\/wp-json\/wp\/v2\/media?parent=1060"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.gbase8.cn\/en\/wp-json\/wp\/v2\/categories?post=1060"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.gbase8.cn\/en\/wp-json\/wp\/v2\/tags?post=1060"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}