{"id":5345,"date":"2024-11-14T10:43:26","date_gmt":"2024-11-14T02:43:26","guid":{"rendered":"https:\/\/fwq.ai\/blog\/5345\/"},"modified":"2024-11-14T10:43:26","modified_gmt":"2024-11-14T02:43:26","slug":"oracle%e6%80%8e%e4%b9%88%e5%be%aa%e7%8e%af%e5%88%9b%e5%bb%ba%e6%b8%b8%e6%a0%87","status":"publish","type":"post","link":"https:\/\/fwq.ai\/blog\/5345\/","title":{"rendered":"oracle\u600e\u4e48\u5faa\u73af\u521b\u5efa\u6e38\u6807"},"content":{"rendered":"<blockquote><p>\n  oracle \u4e2d\uff0cfor loop \u5faa\u73af\u53ef\u52a8\u6001\u521b\u5efa\u6e38\u6807\uff0c \u6b65\u9aa4\u4e3a\uff1a1. \u5b9a\u4e49\u6e38\u6807\u7c7b\u578b\uff1b2. \u521b\u5efa\u5faa\u73af\uff1b3. \u52a8\u6001\u521b\u5efa\u6e38\u6807\uff1b4. \u6267\u884c\u6e38\u6807\uff1b5. \u5173\u95ed\u6e38\u6807\u3002\u793a\u4f8b\uff1a\u53ef\u5faa\u73af\u521b\u5efa\u6e38\u6807\uff0c\u663e\u793a\u524d 10 \u540d\u5458\u5de5\u59d3\u540d\u548c\u5de5\u8d44\u3002\n<\/p><\/blockquote>\n<p><img decoding=\"async\" src=\"https:\/\/img.php.cn\/upload\/article\/202405\/26\/2024052619571778713.jpg\" class=\"aligncenter\" title=\"oracle\u600e\u4e48\u5faa\u73af\u521b\u5efa\u6e38\u6807\u63d2\u56fe\" alt=\"oracle\u600e\u4e48\u5faa\u73af\u521b\u5efa\u6e38\u6807\u63d2\u56fe\" \/><\/p>\n<p><strong>Oracle \u4e2d\u5faa\u73af\u521b\u5efa\u6e38\u6807<\/strong><\/p>\n<p>\u5728 Oracle \u4e2d\uff0c\u53ef\u4ee5\u4f7f\u7528 FOR LOOP \u5faa\u73af\u521b\u5efa\u591a\u4e2a\u6e38\u6807\u3002\u8be5\u5faa\u73af\u5141\u8bb8\u7528\u6237\u52a8\u6001\u751f\u6210\u6e38\u6807\uff0c\u5e76\u6839\u636e\u4e0d\u540c\u7684\u6761\u4ef6\u6267\u884c\u4e0d\u540c\u7684\u67e5\u8be2\u3002<\/p>\n<p><strong>\u6b65\u9aa4\uff1a<\/strong><\/p>\n<ol>\n<li> <strong>\u5b9a\u4e49\u6e38\u6807\u7c7b\u578b\uff1a<\/strong>\u4f7f\u7528 TYPE \u8bed\u53e5\u5b9a\u4e49\u6e38\u6807\u7684\u7c7b\u578b\u3002<\/li>\n<li> <strong>\u521b\u5efa\u5faa\u73af\uff1a<\/strong>\u4f7f\u7528 FOR LOOP \u8bed\u53e5\u521b\u5efa\u5faa\u73af\u3002<\/li>\n<li> <strong>\u52a8\u6001\u521b\u5efa\u6e38\u6807\uff1a<\/strong>\u5728\u5faa\u73af\u4e2d\uff0c\u4f7f\u7528 OPEN \u8bed\u53e5\u52a8\u6001\u521b\u5efa\u6e38\u6807\u3002<\/li>\n<li> <strong>\u6267\u884c\u6e38\u6807\uff1a<\/strong>\u4f7f\u7528 FETCH \u8bed\u53e5\u4ece\u6e38\u6807\u4e2d\u83b7\u53d6\u6570\u636e\u3002<\/li>\n<li> <strong>\u5173\u95ed\u6e38\u6807\uff1a<\/strong>\u4f7f\u7528 CLOSE \u8bed\u53e5\u5173\u95ed\u6e38\u6807\u3002<\/li>\n<\/ol>\n<p><strong>\u793a\u4f8b\uff1a<\/strong><\/p>\n<p>\u4e0b\u9762\u662f\u4e00\u4e2a\u5faa\u73af\u521b\u5efa\u6e38\u6807\u7684\u793a\u4f8b\uff0c\u7528\u4e8e\u663e\u793a\u524d 10 \u540d\u5458\u5de5\u7684\u59d3\u540d\u548c\u5de5\u8d44\uff1a<\/p>\n<pre>DECLARE\n  TYPE CURSOR_TYPE IS REF CURSOR;\n\n  c CURSOR_TYPE;\nBEGIN\n  FOR i IN 1 .. 10 LOOP\n    OPEN c FOR\n      SELECT name, salary\n      FROM employees\n      WHERE rownum &lt;= i;\n\n    FETCH c INTO name, salary;\n\n    DBMS_OUTPUT.PUT_LINE(name || ' - ' || salary);\n\n    CLOSE c;\n  END LOOP;\nEND;<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p>\u4ee5\u4e0a\u5c31\u662f\u600e\u4e48\u5faa\u73af\u521b\u5efa\u6e38\u6807\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>oracle \u4e2d\uff0cfor loop \u5faa\u73af\u53ef\u52a8\u6001\u521b\u5efa\u6e38\u6807\uff0c \u6b65\u9aa4\u4e3a\uff1a1. \u5b9a\u4e49\u6e38\u6807\u7c7b\u578b\uff1b2. \u521b\u5efa\u5faa\u73af\uff1b3. \u52a8\u6001\u521b\u5efa\u6e38\u6807\uff1b4. \u6267\u884c\u6e38\u6807\uff1b5. \u5173\u95ed\u6e38\u6807\u3002\u793a\u4f8b\uff1a\u53ef\u5faa\u73af\u521b\u5efa\u6e38\u6807\uff0c\u663e\u793a\u524d 10 \u540d\u5458\u5de5\u59d3\u540d\u548c\u5de5\u8d44\u3002 Oracle \u4e2d\u5faa\u73af\u521b\u5efa\u6e38\u6807 \u5728 Oracle \u4e2d\uff0c\u53ef\u4ee5\u4f7f\u7528 FOR LOOP \u5faa\u73af\u521b\u5efa\u591a\u4e2a\u6e38\u6807\u3002\u8be5\u5faa\u73af\u5141\u8bb8\u7528\u6237\u52a8\u6001\u751f\u6210\u6e38\u6807\uff0c\u5e76\u6839\u636e\u4e0d\u540c\u7684\u6761\u4ef6\u6267\u884c\u4e0d\u540c\u7684\u67e5\u8be2\u3002 \u6b65\u9aa4\uff1a \u5b9a\u4e49\u6e38\u6807\u7c7b\u578b\uff1a\u4f7f\u7528 TYPE \u8bed\u53e5\u5b9a\u4e49\u6e38\u6807\u7684\u7c7b\u578b\u3002 \u521b\u5efa\u5faa\u73af\uff1a\u4f7f\u7528 FOR LOOP \u8bed\u53e5\u521b\u5efa\u5faa\u73af\u3002 \u52a8\u6001\u521b\u5efa\u6e38\u6807\uff1a\u5728\u5faa\u73af\u4e2d\uff0c\u4f7f\u7528 OPEN \u8bed\u53e5\u52a8\u6001\u521b\u5efa\u6e38\u6807\u3002 \u6267\u884c\u6e38\u6807\uff1a\u4f7f\u7528 FETCH \u8bed\u53e5\u4ece\u6e38\u6807\u4e2d\u83b7\u53d6\u6570\u636e\u3002 \u5173\u95ed\u6e38\u6807\uff1a\u4f7f\u7528 CLOSE \u8bed\u53e5\u5173\u95ed\u6e38\u6807\u3002 \u793a\u4f8b\uff1a \u4e0b\u9762\u662f\u4e00\u4e2a\u5faa\u73af\u521b\u5efa\u6e38\u6807\u7684\u793a\u4f8b\uff0c\u7528\u4e8e\u663e\u793a\u524d 10 \u540d\u5458\u5de5\u7684\u59d3\u540d\u548c\u5de5\u8d44\uff1a DECLARE TYPE CURSOR_TYPE IS REF CURSOR; c CURSOR_TYPE; BEGIN FOR i IN 1 .. [&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-5345","post","type-post","status-publish","format-standard","hentry","category-16"],"_links":{"self":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/5345","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=5345"}],"version-history":[{"count":0,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/5345\/revisions"}],"wp:attachment":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/media?parent=5345"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/categories?post=5345"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/tags?post=5345"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}