{"id":112,"date":"2021-05-07T20:11:48","date_gmt":"2021-05-07T12:11:48","guid":{"rendered":"http:\/\/blog.ohmmx.com\/?p=112"},"modified":"2021-05-07T20:11:48","modified_gmt":"2021-05-07T12:11:48","slug":"%e5%88%9b%e5%bb%ba%e4%b8%80%e4%b8%aa%e5%b8%a6%e4%ba%8b%e5%8a%a1%e5%92%8c%e9%94%99%e8%af%af%e6%97%a5%e5%bf%97%e7%9a%84%e5%ad%98%e5%82%a8%e8%bf%87%e7%a8%8b","status":"publish","type":"post","link":"http:\/\/blog.ohmmx.com\/?p=112","title":{"rendered":"\u521b\u5efa\u4e00\u4e2a\u5e26\u4e8b\u52a1\u548c\u9519\u8bef\u65e5\u5fd7\u7684\u5b58\u50a8\u8fc7\u7a0b"},"content":{"rendered":"\n<p>\u9996\u5148\u521b\u5efa\u65e5\u5fd7\u8868\u7528\u4e8e\u8bb0\u5f55\u5b58\u50a8\u8fc7\u7a0b\u6267\u884c\u9519\u8bef\u4fe1\u606f<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>CREATE TABLE LOG_PROCEDURE\n(\n   ID                   BIGINT NOT NULL AUTO_INCREMENT,\n   PRCD_NAME            VARCHAR(64) NOT NULL,\n   MYSQL_ERRNO          VARCHAR(8),\n   RETURN_STATE         VARCHAR(8),\n   MESSAGE              TEXT,\n   CREATE_TIMESTAMP     DATETIME DEFAULT CURRENT_TIMESTAMP,\n   MODIFY_TIMESTAMP     DATETIME DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,\n   PRIMARY KEY (ID)\n);<\/code><\/pre>\n\n\n\n<p>\u7136\u540e\u521b\u5efa\u4e00\u5f20\u6d4b\u8bd5\u6570\u636e\u8868\uff0c\u7528\u4e8e\u6d4b\u8bd5\u5b58\u50a8\u8fc7\u7a0b<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>CREATE TABLE DATA_TEST\n(\n   ID                   BIGINT NOT NULL AUTO_INCREMENT,\n   COL_A                VARCHAR(64),\n   PRIMARY KEY (ID)\n);<\/code><\/pre>\n\n\n\n<p>\u521b\u5efa\u5b58\u50a8\u8fc7\u7a0b\uff0c\u5728\u5b58\u50a8\u8fc7\u7a0b\u4e8b\u52a1\u4e2d\u548c\u4e8b\u52a1\u540e\u5206\u522b\u5f80\u6d4b\u8bd5\u6570\u636e\u8868\u91cc\u5b58\u5165\u4e00\u6761\u8bb0\u5f55\uff0c\u4e8b\u52a1\u4e2d\u53e6\u5916\u8bd5\u56fe\u5f80\u4e00\u5f20\u4e0d\u5b58\u5728\u7684\u8868\u91cc\u5b58\u5165\u4e00\u6761\u8bb0\u5f55\u3002<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>DELIMITER $$\nDROP PROCEDURE IF EXISTS PRCD_TEST$$\nCREATE PROCEDURE PRCD_TEST (\n\t\/** \u5b9a\u4e49IN,OUT *\/\n)\nBEGIN\n\t\/** \u5b9a\u4e49\u53d8\u91cf *\/\n\n\t\/** \u5b9a\u4e49\u9519\u8bef\u6355\u83b7 *\/\n\tDECLARE EXIT HANDLER FOR SQLEXCEPTION, SQLWARNING\n\tBEGIN\n\t\t\/** \u83b7\u53d6\u9519\u8bef\u5185\u5bb9 *\/\n\t\tGET DIAGNOSTICS CONDITION 1 @p1 = MYSQL_ERRNO, @p2 = RETURNED_SQLSTATE, @p3 = MESSAGE_TEXT;\n\t\tROLLBACK;\n\n\t\t\/** \u9519\u8bef\u4fe1\u606f\u5b58\u5165\u65e5\u5fd7\u8868 *\/\n\t\tINSERT INTO LOG_PROCEDURE(PRCD_NAME, MYSQL_ERRNO, RETURN_STATE, MESSAGE)\n\t\t\tVALUES ('PRCD_TEST', @p1, @p2, @p3);\n\n\t\t\/** \u5931\u8d25\u540e *\/\n\t\tINSERT INTO DATA_TEST(COL_A) VALUE('INSERT_FAILED');\n\tEND;\n\n\t\/** \u5f00\u542f\u4e8b\u52a1 *\/\n\tSTART TRANSACTION;\n\n\t\/** \u6267\u884c\u5185\u5bb9 *\/\n\tINSERT INTO DATA_TEST(COL_A) VALUE('TEST_01');\n\tINSERT INTO NOT_EXIST_TABLE(ID) VALUE('ERROR');\n\tINSERT INTO DATA_TEST(COL_A) VALUE('TEST_02');\n\n\t\/** \u63d0\u4ea4\u4e8b\u52a1 *\/\n\tCOMMIT;\n\n\t\/** \u6210\u529f\u540e *\/\n\tINSERT INTO DATA_TEST(COL_A) VALUE('INSERT_SUCCESS');\nEND$$\nDELIMITER ;<\/code><\/pre>\n\n\n\n<p>\u8c03\u7528\u5b58\u50a8\u8fc7\u7a0b<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>CALL PRCD_TEST();<\/code><\/pre>\n\n\n\n<p>\u6267\u884c\u7ed3\u679c<\/p>\n\n\n\n<p>\u9519\u8bef\u65e5\u5fd7\u8868 LOG_PROCEDURE  \u91cc\u7684\u8bb0\u5f55<\/p>\n\n\n\n<figure class=\"wp-block-table\"><table><tbody><tr><td>ID<\/td><td>PRCD_NAME<\/td><td>MYSQL_ERRNO<\/td><td>RETURN_STATE<\/td><td>MESSAGE<\/td><\/tr><tr><td>1<\/td><td>PRCD_TEST<\/td><td>1146<\/td><td>42S02<\/td><td>Table &#8216;schema.not_exist_table&#8217; doesn&#8217;t exist<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<p>\u518d\u770b\u770b\u6d4b\u8bd5\u6570\u636e\u8868<\/p>\n\n\n\n<figure class=\"wp-block-table\"><table><tbody><tr><td>ID<\/td><td>COL_A<\/td><\/tr><tr><td>2<\/td><td>INSERT_FAILED<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<p>\u7b80\u5355\u8bf4\u660e\u4e00\u4e0b\u6267\u884c\u8fc7\u7a0b\uff1a<\/p>\n\n\n\n<ol class=\"wp-block-list\"><li>\u5f00\u542f\u4e8b\u52a1<\/li><li>\u5f80\u6d4b\u8bd5\u6570\u636e\u8868\u91cc\u5b58\u5165TEST_01\uff08ID\uff1a1\uff09<\/li><li>\u5f80NOT_EXIST_TABLE\u5b58\u5165\u8bb0\u5f55\uff08\u5f02\u5e38\uff09<\/li><li>SQLEXCEPTION\u88ab\u6355\u83b7\uff0c\u83b7\u53d6\u9519\u8bef\u4fe1\u606f<\/li><li>\u4e8b\u52a1\u56de\u6eda<\/li><li>\u5c06\u83b7\u53d6\u5230\u7684\u9519\u8bef\u4fe1\u606f\u5b58\u5165\u9519\u8bef\u65e5\u5fd7\u8868<\/li><li>\u5f80\u6d4b\u8bd5\u6570\u636e\u8868\u91cc\u5b58\u5165INSERT_FAILED\uff08ID\uff1a2\uff09<\/li><\/ol>\n\n\n\n<p>\u6240\u4ee5\u6d4b\u8bd5\u6570\u636e\u8868\u91cc\u7684\u8bb0\u5f55ID\u662f2\u800c\u4e0d\u662f1<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u9996\u5148\u521b\u5efa\u65e5\u5fd7\u8868\u7528\u4e8e\u8bb0\u5f55\u5b58\u50a8\u8fc7\u7a0b\u6267\u884c\u9519\u8bef\u4fe1\u606f \u7136\u540e\u521b\u5efa\u4e00\u5f20\u6d4b\u8bd5\u6570\u636e\u8868\uff0c\u7528\u4e8e\u6d4b\u8bd5\u5b58\u50a8 &hellip; <a href=\"http:\/\/blog.ohmmx.com\/?p=112\">\u7ee7\u7eed\u9605\u8bfb <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[17],"tags":[9,30,8],"class_list":["post-112","post","type-post","status-publish","format-standard","hentry","category-17","tag-mysql","tag-30","tag-8"],"_links":{"self":[{"href":"http:\/\/blog.ohmmx.com\/index.php?rest_route=\/wp\/v2\/posts\/112","targetHints":{"allow":["GET"]}}],"collection":[{"href":"http:\/\/blog.ohmmx.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/blog.ohmmx.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/blog.ohmmx.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/blog.ohmmx.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=112"}],"version-history":[{"count":1,"href":"http:\/\/blog.ohmmx.com\/index.php?rest_route=\/wp\/v2\/posts\/112\/revisions"}],"predecessor-version":[{"id":113,"href":"http:\/\/blog.ohmmx.com\/index.php?rest_route=\/wp\/v2\/posts\/112\/revisions\/113"}],"wp:attachment":[{"href":"http:\/\/blog.ohmmx.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=112"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/blog.ohmmx.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=112"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/blog.ohmmx.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=112"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}