{"id":5016,"date":"2024-11-14T08:49:15","date_gmt":"2024-11-14T00:49:15","guid":{"rendered":"https:\/\/fwq.ai\/blog\/5016\/"},"modified":"2024-11-14T08:49:15","modified_gmt":"2024-11-14T00:49:15","slug":"oracle%e6%b8%b8%e6%a0%87%e6%80%8e%e4%b9%88%e8%8e%b7%e5%be%97%e9%95%bf%e5%ba%a6","status":"publish","type":"post","link":"https:\/\/fwq.ai\/blog\/5016\/","title":{"rendered":"oracle\u6e38\u6807\u600e\u4e48\u83b7\u5f97\u957f\u5ea6"},"content":{"rendered":"<blockquote><p>\n  oracle \u6e38\u6807\u7684\u957f\u5ea6\u53ef\u4ee5\u901a\u8fc7\u4ee5\u4e0b\u65b9\u6cd5\u83b7\u5f97\uff1a\u4f7f\u7528 sql \u51fd\u6570 select count(*) \u8fd4\u56de\u6e38\u6807\u6307\u5411\u7684\u8868\u7684\u7cbe\u786e\u884c\u6570\u3002\u4f7f\u7528\u5c5e\u6027 select count(*) from sys.cursor_usage \u83b7\u53d6\u6e38\u6807\u7684\u4f30\u8ba1\u957f\u5ea6\u3002\u4f7f\u7528\u6e38\u6807\u5c5e\u6027 dbms_sql.rowcount \u8fd4\u56de\u6e38\u6807\u4e2d\u5f53\u524d\u53ef\u7528\u7684\u884c\u6570\u3002\u4f7f\u7528\u6e38\u6807\u5305\u4e2d\u7684\u51fd\u6570 cursor_info. \u83b7\u53d6\u5217\u6570\u3001\u884c\u6570\u3001\u5df2\u83b7\u53d6\u884c\u6570\u548c\u7f13\u51b2\u533a\u884c\u6570\u7b49\u4fe1\u606f\u3002\n<\/p><\/blockquote>\n<p><img decoding=\"async\" src=\"https:\/\/img.php.cn\/upload\/article\/202405\/21\/2024052110481927726.jpg\" class=\"aligncenter\" title=\"oracle\u6e38\u6807\u600e\u4e48\u83b7\u5f97\u957f\u5ea6\u63d2\u56fe\" alt=\"oracle\u6e38\u6807\u600e\u4e48\u83b7\u5f97\u957f\u5ea6\u63d2\u56fe\" \/><\/p>\n<p><strong>\u5982\u4f55\u83b7\u5f97 Oracle \u6e38\u6807\u7684\u957f\u5ea6<\/strong><\/p>\n<p>Oracle \u6e38\u6807\u662f\u4e00\u4e2a\u6307\u5411\u7ed3\u679c\u96c6\u7684\u6307\u9488\uff0c\u7528\u4e8e\u5728\u5e94\u7528\u7a0b\u5e8f\u548c\u6570\u636e\u5e93\u4e4b\u95f4\u4f20\u8f93\u6570\u636e\u3002\u4ee5\u4e0b\u662f\u5982\u4f55\u83b7\u5f97 Oracle \u6e38\u6807\u7684\u957f\u5ea6\uff1a<\/p>\n<p><strong>\u4f7f\u7528 SQL \u51fd\u6570<\/strong><\/p>\n<pre>SELECT COUNT(*) FROM [table_name] WHERE [condition];<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p>\u5c06 [table_name] \u66ff\u6362\u4e3a\u6e38\u6807\u6307\u5411\u7684\u8868\u540d\u79f0\uff0c\u5c06 [condition] \u66ff\u6362\u4e3a\u7528\u4e8e\u9650\u5236\u7ed3\u679c\u7684\u4efb\u4f55\u6761\u4ef6\u3002\u6b64\u65b9\u6cd5\u8fd4\u56de\u6e38\u6807\u7684\u7cbe\u786e\u957f\u5ea6\u3002<\/p>\n<p><strong>\u4f7f\u7528\u5c5e\u6027<\/strong><\/p>\n<pre>SELECT COUNT(*) AS row_count FROM sys.cursor_usage WHERE cursor_id = &lt;cursor_id&gt;;<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p>\u5c06 \u66ff\u6362\u4e3a\u6e38\u6807\u7684 ID\u3002\u6b64\u65b9\u6cd5\u8fd4\u56de\u6e38\u6807\u7684\u4f30\u8ba1\u957f\u5ea6\uff0c\u56e0\u4e3a\u5b83\u662f\u6839\u636e\u6e38\u6807\u4e0a\u6b21\u8bbf\u95ee\u65f6\u7684\u8fd0\u884c\u65f6\u7edf\u8ba1\u4fe1\u606f\u8ba1\u7b97\u7684\u3002 <\/p>\n<p><strong>\u4f7f\u7528\u6e38\u6807\u5c5e\u6027<\/strong><\/p>\n<pre>DECLARE\n  my_cursor CURSOR FOR SELECT * FROM [table_name];\nBEGIN\n  OPEN my_cursor;\n  DBMS_OUTPUT.PUT_LINE('Number of rows in cursor: ' || DBMS_SQL.ROWCOUNT);\nEND;<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p>\u6b64\u65b9\u6cd5\u8fd4\u56de\u6e38\u6807\u4e2d\u5f53\u524d\u53ef\u7528\u7684\u884c\u6570\uff0c\u4f46\u9700\u8981\u6ce8\u610f\u7684\u662f\uff0c\u5728\u6e38\u6807\u6253\u5f00\u540e\uff0c\u884c\u6570\u53ef\u80fd\u4f1a\u53d1\u751f\u53d8\u5316\u3002<\/p>\n<p><strong>\u4f7f\u7528\u6e38\u6807\u5305\u4e2d\u7684\u51fd\u6570<\/strong><\/p>\n<pre>SELECT CURSOR_INFO.&lt;function_name&gt; FROM sys.cursor_info WHERE cursor_id = &lt;cursor_id&gt;;<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p>\u5176\u4e2d \u53ef\u4ee5\u662f\u4ee5\u4e0b\u4efb\u610f\u4e00\u4e2a\uff1a <\/p>\n<ul>\n<li>column_count\uff1a\u8fd4\u56de\u6e38\u6807\u4e2d\u5217\u7684\u6570\u76ee\u3002<\/li>\n<li>row_count\uff1a\u8fd4\u56de\u6e38\u6807\u4e2d\u884c\u7684\u4f30\u8ba1\u6570\u76ee\u3002<\/li>\n<li>fetched_count\uff1a\u8fd4\u56de\u6e38\u6807\u4e2d\u5df2\u83b7\u53d6\u7684\u884c\u6570\u3002<\/li>\n<li>buffer_size\uff1a\u8fd4\u56de\u6e38\u6807\u7f13\u51b2\u533a\u7684\u884c\u6570\u3002<\/li>\n<\/ul>\n<p>\u4ee5\u4e0a\u5c31\u662f\u6e38\u6807\u600e\u4e48\u83b7\u5f97\u957f\u5ea6\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 \u6e38\u6807\u7684\u957f\u5ea6\u53ef\u4ee5\u901a\u8fc7\u4ee5\u4e0b\u65b9\u6cd5\u83b7\u5f97\uff1a\u4f7f\u7528 sql \u51fd\u6570 select count(*) \u8fd4\u56de\u6e38\u6807\u6307\u5411\u7684\u8868\u7684\u7cbe\u786e\u884c\u6570\u3002\u4f7f\u7528\u5c5e\u6027 select count(*) from sys.cursor_usage \u83b7\u53d6\u6e38\u6807\u7684\u4f30\u8ba1\u957f\u5ea6\u3002\u4f7f\u7528\u6e38\u6807\u5c5e\u6027 dbms_sql.rowcount \u8fd4\u56de\u6e38\u6807\u4e2d\u5f53\u524d\u53ef\u7528\u7684\u884c\u6570\u3002\u4f7f\u7528\u6e38\u6807\u5305\u4e2d\u7684\u51fd\u6570 cursor_info. \u83b7\u53d6\u5217\u6570\u3001\u884c\u6570\u3001\u5df2\u83b7\u53d6\u884c\u6570\u548c\u7f13\u51b2\u533a\u884c\u6570\u7b49\u4fe1\u606f\u3002 \u5982\u4f55\u83b7\u5f97 Oracle \u6e38\u6807\u7684\u957f\u5ea6 Oracle \u6e38\u6807\u662f\u4e00\u4e2a\u6307\u5411\u7ed3\u679c\u96c6\u7684\u6307\u9488\uff0c\u7528\u4e8e\u5728\u5e94\u7528\u7a0b\u5e8f\u548c\u6570\u636e\u5e93\u4e4b\u95f4\u4f20\u8f93\u6570\u636e\u3002\u4ee5\u4e0b\u662f\u5982\u4f55\u83b7\u5f97 Oracle \u6e38\u6807\u7684\u957f\u5ea6\uff1a \u4f7f\u7528 SQL \u51fd\u6570 SELECT COUNT(*) FROM [table_name] WHERE [condition]; \u767b\u5f55\u540e\u590d\u5236 \u5c06 [table_name] \u66ff\u6362\u4e3a\u6e38\u6807\u6307\u5411\u7684\u8868\u540d\u79f0\uff0c\u5c06 [condition] \u66ff\u6362\u4e3a\u7528\u4e8e\u9650\u5236\u7ed3\u679c\u7684\u4efb\u4f55\u6761\u4ef6\u3002\u6b64\u65b9\u6cd5\u8fd4\u56de\u6e38\u6807\u7684\u7cbe\u786e\u957f\u5ea6\u3002 \u4f7f\u7528\u5c5e\u6027 SELECT COUNT(*) AS row_count FROM sys.cursor_usage WHERE cursor_id = &lt;cursor_id&gt;; \u767b\u5f55\u540e\u590d\u5236 \u5c06 \u66ff\u6362\u4e3a\u6e38\u6807\u7684 ID\u3002\u6b64\u65b9\u6cd5\u8fd4\u56de\u6e38\u6807\u7684\u4f30\u8ba1\u957f\u5ea6\uff0c\u56e0\u4e3a\u5b83\u662f\u6839\u636e\u6e38\u6807\u4e0a\u6b21\u8bbf\u95ee\u65f6\u7684\u8fd0\u884c\u65f6\u7edf\u8ba1\u4fe1\u606f\u8ba1\u7b97\u7684\u3002 \u4f7f\u7528\u6e38\u6807\u5c5e\u6027 DECLARE [&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-5016","post","type-post","status-publish","format-standard","hentry","category-16"],"_links":{"self":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/5016","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=5016"}],"version-history":[{"count":0,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/5016\/revisions"}],"wp:attachment":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/media?parent=5016"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/categories?post=5016"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/tags?post=5016"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}