{"id":226,"date":"2020-06-10T11:08:59","date_gmt":"2020-06-10T03:08:59","guid":{"rendered":"http:\/\/www.gbase8.cn\/?p=226"},"modified":"2023-04-23T16:38:19","modified_gmt":"2023-04-23T08:38:19","slug":"gbase-8a%e9%9b%86%e7%be%a4%e5%ad%98%e5%82%a8%e8%bf%87%e7%a8%8b%e6%a0%b7%e4%be%8b","status":"publish","type":"post","link":"https:\/\/www.gbase8.cn\/en\/226","title":{"rendered":"\u5357\u5927\u901a\u7528GBase 8a\u96c6\u7fa4\u5b58\u50a8\u8fc7\u7a0b\u6837\u4f8b\uff0c\u52a8\u6001\u5b58\u50a8\u8fc7\u7a0b"},"content":{"rendered":"<p>GBase 8a \u6570\u636e\u5e93\u53ef\u4ee5\u6267\u884c\u4e00\u4e2a\u62fc\u63a5\u7684\u5b57\u7b26\u4e32\uff0c\u5f53\u6210SQL\u6765\u6267\u884c\u3002\u901a\u8fc7parpare\u65b9\u5f0f\u7f16\u8bd1\uff0cexecute\u6267\u884c\uff0c\u518d\u901a\u8fc7DEALLOCATE\u91ca\u653e\u6389\u8d44\u6e90\u3002<\/p>\n\n\n\n<p>\u6ce8\u610f\uff1a\u5b58\u50a8\u8fc7\u7a0b\u5728\u6267\u884c\u65f6\uff0ccall \u8bed\u53e5\u4f1a\u88ab\u5ba1\u8ba1\u65e5\u5fd7\u8bb0\u5f55\uff0c\u4e00\u65e6\u6267\u884c\u5f00\u59cb\uff0c\u5728show processlist\u65f6\uff0c\u5c06\u53ea\u80fd\u770b\u5230\u5185\u90e8\u7684SQL,\u770b\u4e0d\u5230call\u8bed\u53e5\uff0c\u4e14\u8fd9\u4e9b\u5185\u90e8SQL\u4e0d\u4f1a\u88ab\u5ba1\u8ba1\u65e5\u5fd7\u8bb0\u5f55\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-6a2ad3e608c5a\" 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-6a2ad3e608c5a\"  aria-label=\"Toggle\" \/><nav><ul class='ez-toc-list ez-toc-list-level-1' ><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-1\" href=\"https:\/\/www.gbase8.cn\/en\/226\/#%E4%B8%80%E4%B8%AA%E9%80%9A%E7%94%A8%E7%9A%84%E5%AD%98%E5%82%A8%E8%A7%84%E7%A8%8B%E6%9D%A5%E6%89%A7%E8%A1%8CexecuteSQL\" >\u4e00\u4e2a\u901a\u7528\u7684\u5b58\u50a8\u89c4\u7a0b\u6765\u6267\u884cexecuteSQL<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-2\" href=\"https:\/\/www.gbase8.cn\/en\/226\/#%E6%89%A7%E8%A1%8C%E6%B5%8B%E8%AF%95\" >\u6267\u884c\u6d4b\u8bd5<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-3\" href=\"https:\/\/www.gbase8.cn\/en\/226\/#%E5%B8%A6%E5%BC%82%E5%B8%B8%E5%A4%84%E7%90%86%E7%9A%84%E5%AD%98%E5%82%A8%E8%A7%84%E7%A8%8B\" >\u5e26\u5f02\u5e38\u5904\u7406\u7684\u5b58\u50a8\u89c4\u7a0b<\/a><\/li><\/ul><\/nav><\/div>\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"%E4%B8%80%E4%B8%AA%E9%80%9A%E7%94%A8%E7%9A%84%E5%AD%98%E5%82%A8%E8%A7%84%E7%A8%8B%E6%9D%A5%E6%89%A7%E8%A1%8CexecuteSQL\"><\/span>\u4e00\u4e2a\u901a\u7528\u7684\u5b58\u50a8\u89c4\u7a0b\u6765\u6267\u884cexecuteSQL<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p>\u5176\u4e2d\u5b58\u50a8\u8fc7\u7a0b\u662f\u4e00\u4e2a\u6574\u4f53\uff0c\u6240\u4ee5\u5fc5\u987b\u7528delimiter \u6267\u884c\u4e00\u4e2a\u65b0\u7684\u5206\u5272\u7b26\u3002 \u5728\u5206\u9694\u7b26\u51fa\u73b0\u524d\uff0c\u6240\u6709\u7684\u5185\u5bb9\u4e3a\u4e00\u4e2a\u6574\u4f53\u3002 \u5982\u4e0b\u4f8b\u5b50\u7528\/\/\u4f5c\u4e3a\u5206\u5272\u3002<\/p>\n\n\n\n<p>\u5728\u5b58\u50a8\u8fc7\u7a0b\u7f16\u5199\u5b8c\u6210\u540e\uff0c\u52a0\u4e0a\/\/\u4f5c\u4e3a\u7ed3\u675f\u3002 \u7136\u540e\u6307\u5b9a\u65b0\u7684\u5206\u9694\u7b26\uff0c \u5982\u4e0b\u4f8b\u5b50\u6062\u590d\u4e86\u9ed8\u8ba4\u7684\u5206\u53f7\u4f5c\u4e3a\u5206\u5272\u3002<\/p>\n\n\n\n<pre class=\"wp-block-code has-small-font-size\"><code>drop procedure if exists executeSQL; \ndelimiter \/\/\ncreate procedure executeSQL(\n S_SQL_TMP VARCHAR(21000)\n)\nBEGIN\n  set @executeSQL_sql = S_SQL_TMP;\n  PREPARE executeSQL_s1 FROM @executeSQL_sql ;\n  EXECUTE executeSQL_s1;\n  DEALLOCATE PREPARE executeSQL_s1;\nEND\/\/\n\ndelimiter ;<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"%E6%89%A7%E8%A1%8C%E6%B5%8B%E8%AF%95\"><\/span>\u6267\u884c\u6d4b\u8bd5<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<pre class=\"wp-block-code\"><code>gbase&gt; call executeSQL('show tables');\n+------------------+\n| Tables_in_testdb |\n+------------------+\n| hr               |\n| human            |\n| t_ms             |\n| t_varchar        |\n| t_varchar2       |\n| testboolean      |\n| testload         |\n| tload            |\n| tload_2          |\n+------------------+\n9 rows in set (Elapsed: 00:00:00.00)\n\nQuery OK, 0 rows affected (Elapsed: 00:00:00.00)<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"%E5%B8%A6%E5%BC%82%E5%B8%B8%E5%A4%84%E7%90%86%E7%9A%84%E5%AD%98%E5%82%A8%E8%A7%84%E7%A8%8B\"><\/span>\u5e26\u5f02\u5e38\u5904\u7406\u7684\u5b58\u50a8\u89c4\u7a0b<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p> \u9519\u8bef\u5904\u7406\u5206\u4e3a\u7ee7\u7eedcontinue\u548c \u9000\u51faexit\u4e24\u7c7b\uff0c\u5982\u4e0b\u662fcontinue\u7684\u4f8b\u5b50\u3002\u83b7\u5f97\u5f02\u5e38\u4fe1\u606f\u7684\u4ee3\u7801\u53ef\u4ee5\u4f7f\u7528\uff0c\u5176\u5b83\u53ef\u4ee5\u5199\u5404\u79cd\u5904\u7406\u65b9\u6848\uff0c\u4e0b\u9762\u4e5f\u53ea\u662f\u4e00\u4e2a\u5199\u5165\u65e5\u5fd7\u7684\u4f8b\u5b50\u3002<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>drop procedure if exists executeSQL; \ndelimiter \/\/\ncreate procedure executeSQL(\n S_SQL_TMP VARCHAR(21000)\n)\nBEGIN\n    declare errno int; \n    declare msg text; \n    declare continue handler for sqlexception \n    begin \n        get diagnostics condition 1 errno = gbase_errno,msg = message_text;\n        create table if not exists err_msg(errno int, msg varchar(10000),d datetime);\n        insert into err_msg values (errno,msg,now());        \n    end;\n\n\n  set @sql = S_SQL_TMP;\n  PREPARE s1 FROM @sql;\n  EXECUTE s1;\n  DEALLOCATE PREPARE s1;\nEND\/\/\n\ndelimiter ;<\/code><\/pre>\n\n\n\n<p><\/p>\n\n\n\n<p>\u81ea\u5b9a\u4e49\u51fd\u6570\u7684\u6837\u4f8b\uff0c\u8bf7\u53c2\u8003<\/p>\n\n\n\n<p><a href=\"http:\/\/www.gbase8.cn\/en\/?p=1060\">GBase 8a\u81ea\u5b9a\u4e49\u51fd\u6570\u6837\u4f8b<\/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\u53ef\u4ee5\u6267\u884c\u4e00\u4e2a\u62fc\u63a5\u7684\u5b57\u7b26\u4e32\uff0c\u5f53\u6210SQL\u6765\u6267\u884c\u3002\u901a\u8fc7parpare\u65b9\u5f0f\u7f16\u8bd1\uff0cexecute\u6267\u884c\uff0c\u518d\u901a\u8fc7DEALLOCATE\u91ca\u653e\u6389\u8d44\u6e90\u3002<\/p>","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[7],"tags":[92],"class_list":["post-226","post","type-post","status-publish","format-standard","hentry","category-gbase8a","tag-92"],"_links":{"self":[{"href":"https:\/\/www.gbase8.cn\/en\/wp-json\/wp\/v2\/posts\/226","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=226"}],"version-history":[{"count":10,"href":"https:\/\/www.gbase8.cn\/en\/wp-json\/wp\/v2\/posts\/226\/revisions"}],"predecessor-version":[{"id":11689,"href":"https:\/\/www.gbase8.cn\/en\/wp-json\/wp\/v2\/posts\/226\/revisions\/11689"}],"wp:attachment":[{"href":"https:\/\/www.gbase8.cn\/en\/wp-json\/wp\/v2\/media?parent=226"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.gbase8.cn\/en\/wp-json\/wp\/v2\/categories?post=226"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.gbase8.cn\/en\/wp-json\/wp\/v2\/tags?post=226"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}