{"id":5744,"date":"2024-11-14T10:52:50","date_gmt":"2024-11-14T02:52:50","guid":{"rendered":"https:\/\/fwq.ai\/blog\/5744\/"},"modified":"2024-11-14T10:52:50","modified_gmt":"2024-11-14T02:52:50","slug":"oracle%e6%b8%b8%e6%a0%87%e5%85%b3%e9%97%ad%e6%80%8e%e4%b9%88%e8%a7%a3%e5%86%b3","status":"publish","type":"post","link":"https:\/\/fwq.ai\/blog\/5744\/","title":{"rendered":"oracle\u6e38\u6807\u5173\u95ed\u600e\u4e48\u89e3\u51b3"},"content":{"rendered":"<blockquote><p>\n  \u89e3\u51b3 oracle \u6e38\u6807\u5173\u95ed\u95ee\u9898\u7684\u65b9\u6cd5\u5305\u62ec\uff1a\u4f7f\u7528 close \u8bed\u53e5\u663e\u5f0f\u5173\u95ed\u6e38\u6807\u3002\u5728 for update \u5b50\u53e5\u4e2d\u58f0\u660e\u6e38\u6807\uff0c\u4f7f\u5176\u5728\u4f5c\u7528\u57df\u7ed3\u675f\u540e\u81ea\u52a8\u5173\u95ed\u3002\u5728 using \u5b50\u53e5\u4e2d\u58f0\u660e\u6e38\u6807\uff0c\u4f7f\u5176\u5728\u5173\u8054\u7684 pl\/sql \u53d8\u91cf\u5173\u95ed\u65f6\u81ea\u52a8\u5173\u95ed\u3002\u4f7f\u7528\u5f02\u5e38\u5904\u7406\u786e\u4fdd\u5728\u4efb\u4f55\u5f02\u5e38\u60c5\u51b5\u4e0b\u5173\u95ed\u6e38\u6807\u3002\u4f7f\u7528\u8fde\u63a5\u6c60\u81ea\u52a8\u5173\u95ed\u6e38\u6807\u3002\u7981\u7528\u81ea\u52a8\u63d0\u4ea4\uff0c\u5ef6\u8fdf\u6e38\u6807\u5173\u95ed\u3002\n<\/p><\/blockquote>\n<p><img decoding=\"async\" src=\"https:\/\/img.php.cn\/upload\/article\/202405\/30\/2024053021514386411.jpg\" class=\"aligncenter\" title=\"oracle\u6e38\u6807\u5173\u95ed\u600e\u4e48\u89e3\u51b3\u63d2\u56fe\" alt=\"oracle\u6e38\u6807\u5173\u95ed\u600e\u4e48\u89e3\u51b3\u63d2\u56fe\" \/><\/p>\n<p><strong>Oracle \u6e38\u6807\u5173\u95ed\u89e3\u51b3\u65b9\u6848<\/strong><\/p>\n<p>\u5f53\u4f7f\u7528 Oracle \u6e38\u6807\u65f6\uff0c\u5fd8\u8bb0\u5173\u95ed\u6e38\u6807\u53ef\u80fd\u4f1a\u5bfc\u81f4\u8d44\u6e90\u6cc4\u6f0f\u548c\u6027\u80fd\u95ee\u9898\u3002\u4ee5\u4e0b\u662f\u89e3\u51b3 Oracle \u6e38\u6807\u5173\u95ed\u95ee\u9898\u7684\u6b65\u9aa4\uff1a<\/p>\n<p><strong>1. \u4f7f\u7528\u663e\u5f0f\u5173\u95ed<\/strong><\/p>\n<p>\u5728\u4f7f\u7528\u5b8c\u6210\u540e\uff0c\u4f7f\u7528 CLOSE \u8bed\u53e5\u663e\u5f0f\u5173\u95ed\u6e38\u6807\u3002<\/p>\n<pre>DECLARE my_cursor CURSOR FOR &lt;query&gt;;\n...\nCLOSE my_cursor;<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p><strong>2. \u4f7f\u7528 FOR UPDATE \u5b50\u53e5<\/strong><\/p>\n<p>\u5728 FOR UPDATE \u5b50\u53e5\u4e2d\u58f0\u660e\u7684\u6e38\u6807\u4f1a\u5728\u5176\u7ed3\u675f\u540e\u81ea\u52a8\u5173\u95ed\u3002<\/p>\n<pre>DECLARE my_cursor CURSOR FOR UPDATE OF &lt;table_name&gt;;\n...<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p><strong>3. \u4f7f\u7528 USING \u5b50\u53e5<\/strong><\/p>\n<p>\u5728 USING \u5b50\u53e5\u4e2d\u58f0\u660e\u7684\u6e38\u6807\u4f1a\u5728\u5176\u5173\u8054\u7684 PL\/SQL \u53d8\u91cf\u5173\u95ed\u65f6\u81ea\u52a8\u5173\u95ed\u3002<\/p>\n<pre>CREATE OR REPLACE PROCEDURE my_procedure\nIS\n  my_cursor SYS_REFCURSOR;\nBEGIN\n  OPEN my_cursor FOR &lt;query&gt;;\n  ...\nEND;<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p><strong>4. \u4f7f\u7528\u5f02\u5e38\u5904\u7406<\/strong><\/p>\n<p>\u5728\u6e38\u6807\u58f0\u660e\u4e2d\u4f7f\u7528\u5f02\u5e38\u5904\u7406\u53ef\u4ee5\u786e\u4fdd\u5728\u4efb\u4f55\u5f02\u5e38\u60c5\u51b5\u4e0b\u90fd\u5173\u95ed\u6e38\u6807\u3002<\/p>\n<pre>BEGIN\n  DECLARE my_cursor CURSOR FOR &lt;query&gt;;\n  BEGIN\n    ...\n  EXCEPTION\n    WHEN OTHERS THEN\n      CLOSE my_cursor;\n      RAISE;\n  END;\nEND;<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p><strong>5. \u4f7f\u7528\u8fde\u63a5\u6c60<\/strong><\/p>\n<p>\u8fde\u63a5\u6c60\u7ba1\u7406\u6e38\u6807\u751f\u547d\u5468\u671f\uff0c\u5e76\u5728\u8fde\u63a5\u91ca\u653e\u65f6\u81ea\u52a8\u5173\u95ed\u6e38\u6807\u3002<\/p>\n<p><strong>6. \u7981\u7528\u81ea\u52a8\u63d0\u4ea4<\/strong><\/p>\n<p>\u4ee5\u624b\u52a8\u63d0\u4ea4\u6a21\u5f0f\u8fd0\u884c\uff0c\u53ef\u4ee5\u5ef6\u8fdf\u6e38\u6807\u7684\u5173\u95ed\uff0c\u76f4\u5230\u63d0\u4ea4\u6216\u56de\u6eda\u4e3a\u6b62\u3002<\/p>\n<pre>SET AUTOCOMMIT OFF;<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p>\u901a\u8fc7\u5b9e\u73b0\u8fd9\u4e9b\u89e3\u51b3\u65b9\u6848\uff0c\u53ef\u4ee5\u6709\u6548\u5730\u7ba1\u7406 Oracle \u6e38\u6807\u7684\u5173\u95ed\uff0c\u9632\u6b62\u8d44\u6e90\u6cc4\u6f0f\u548c\u6027\u80fd\u95ee\u9898\u3002<\/p>\n<p>\u4ee5\u4e0a\u5c31\u662f\u6e38\u6807\u5173\u95ed\u600e\u4e48\u89e3\u51b3\u7684\u8be6\u7ec6\u5185\u5bb9\uff0c\u66f4\u591a\u8bf7\u5173\u6ce8\u7c73\u4e91\u7f51\u5176\u5b83\u76f8\u5173\u6587\u7ae0\uff01<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u89e3\u51b3 oracle \u6e38\u6807\u5173\u95ed\u95ee\u9898\u7684\u65b9\u6cd5\u5305\u62ec\uff1a\u4f7f\u7528 close \u8bed\u53e5\u663e\u5f0f\u5173\u95ed\u6e38\u6807\u3002\u5728 for update \u5b50\u53e5\u4e2d\u58f0\u660e\u6e38\u6807\uff0c\u4f7f\u5176\u5728\u4f5c\u7528\u57df\u7ed3\u675f\u540e\u81ea\u52a8\u5173\u95ed\u3002\u5728 using \u5b50\u53e5\u4e2d\u58f0\u660e\u6e38\u6807\uff0c\u4f7f\u5176\u5728\u5173\u8054\u7684 pl\/sql \u53d8\u91cf\u5173\u95ed\u65f6\u81ea\u52a8\u5173\u95ed\u3002\u4f7f\u7528\u5f02\u5e38\u5904\u7406\u786e\u4fdd\u5728\u4efb\u4f55\u5f02\u5e38\u60c5\u51b5\u4e0b\u5173\u95ed\u6e38\u6807\u3002\u4f7f\u7528\u8fde\u63a5\u6c60\u81ea\u52a8\u5173\u95ed\u6e38\u6807\u3002\u7981\u7528\u81ea\u52a8\u63d0\u4ea4\uff0c\u5ef6\u8fdf\u6e38\u6807\u5173\u95ed\u3002 Oracle \u6e38\u6807\u5173\u95ed\u89e3\u51b3\u65b9\u6848 \u5f53\u4f7f\u7528 Oracle \u6e38\u6807\u65f6\uff0c\u5fd8\u8bb0\u5173\u95ed\u6e38\u6807\u53ef\u80fd\u4f1a\u5bfc\u81f4\u8d44\u6e90\u6cc4\u6f0f\u548c\u6027\u80fd\u95ee\u9898\u3002\u4ee5\u4e0b\u662f\u89e3\u51b3 Oracle \u6e38\u6807\u5173\u95ed\u95ee\u9898\u7684\u6b65\u9aa4\uff1a 1. \u4f7f\u7528\u663e\u5f0f\u5173\u95ed \u5728\u4f7f\u7528\u5b8c\u6210\u540e\uff0c\u4f7f\u7528 CLOSE \u8bed\u53e5\u663e\u5f0f\u5173\u95ed\u6e38\u6807\u3002 DECLARE my_cursor CURSOR FOR &lt;query&gt;; &#8230; CLOSE my_cursor; \u767b\u5f55\u540e\u590d\u5236 2. \u4f7f\u7528 FOR UPDATE \u5b50\u53e5 \u5728 FOR UPDATE \u5b50\u53e5\u4e2d\u58f0\u660e\u7684\u6e38\u6807\u4f1a\u5728\u5176\u7ed3\u675f\u540e\u81ea\u52a8\u5173\u95ed\u3002 DECLARE my_cursor CURSOR FOR UPDATE OF &lt;table_name&gt;; &#8230; \u767b\u5f55\u540e\u590d\u5236 3. \u4f7f\u7528 USING \u5b50\u53e5 [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[16],"tags":[],"class_list":["post-5744","post","type-post","status-publish","format-standard","hentry","category-16"],"_links":{"self":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/5744","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/comments?post=5744"}],"version-history":[{"count":0,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/5744\/revisions"}],"wp:attachment":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/media?parent=5744"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/categories?post=5744"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/tags?post=5744"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}