{"id":15708,"date":"2023-12-04T21:55:53","date_gmt":"2023-12-04T13:55:53","guid":{"rendered":"https:\/\/wx.kaifamiao.info\/?p=15708"},"modified":"2023-12-04T21:57:13","modified_gmt":"2023-12-04T13:57:13","slug":"oracle-zhong-yin-shi-you-biao-he-xian-shi-you-biao","status":"publish","type":"post","link":"http:\/\/wx.kaifamiao.info\/index.php\/2023\/12\/04\/oracle-zhong-yin-shi-you-biao-he-xian-shi-you-biao\/","title":{"rendered":"Oracle \u4e2d\u9690\u5f0f\u6e38\u6807\u548c\u663e\u5f0f\u6e38\u6807\u4e4b\u95f4\u6709\u4ec0\u4e48\u533a\u522b\uff1f"},"content":{"rendered":"<p>\u5728 Oracle \u4e2d\uff0c\u9690\u5f0f\u6e38\u6807\u548c\u663e\u5f0f\u6e38\u6807\u662f\u4e24\u79cd\u4e0d\u540c\u7c7b\u578b\u7684\u6e38\u6807\uff0c\u5b83\u4eec\u7684\u533a\u522b\u5728\u4e8e\u58f0\u660e\u548c\u4f7f\u7528\u65b9\u5f0f\uff1a<\/p>\n<ol>\n<li><strong>\u9690\u5f0f\u6e38\u6807\uff08Implicit Cursors\uff09\uff1a<\/strong>\n<ul>\n<li>\u9690\u5f0f\u6e38\u6807\u662f\u7531 Oracle \u81ea\u52a8\u7ba1\u7406\u7684\u6e38\u6807\uff0c\u4e0d\u9700\u8981\u663e\u5f0f\u5730\u58f0\u660e\u6216\u63a7\u5236\u3002\u5f53\u6267\u884c DML\uff08\u6570\u636e\u64cd\u7eb5\u8bed\u8a00\uff09\u8bed\u53e5\uff08\u5982 INSERT\u3001UPDATE\u3001DELETE\uff09\u65f6\uff0cOracle \u81ea\u52a8\u521b\u5efa\u9690\u5f0f\u6e38\u6807\u6765\u5904\u7406\u8fd9\u4e9b\u8bed\u53e5\u3002<\/li>\n<li>\u5bf9\u4e8e SELECT \u8bed\u53e5\uff0c\u5982\u679c\u6ca1\u6709\u663e\u5f0f\u5730\u4f7f\u7528\u6e38\u6807\u6765\u5904\u7406\u7ed3\u679c\u96c6\uff0cOracle \u4e5f\u4f1a\u81ea\u52a8\u5904\u7406\u7ed3\u679c\u96c6\uff0c\u8fd9\u4e5f\u88ab\u89c6\u4e3a\u9690\u5f0f\u6e38\u6807\u7684\u4e00\u79cd\u4f7f\u7528\u3002<\/li>\n<\/ul>\n<pre><code class=\"language-sql  line-numbers\">-- \u9690\u5f0f\u6e38\u6807\u7684\u4f8b\u5b50\uff08UPDATE \u8bed\u53e5\uff09\nUPDATE employees SET salary = salary * 1.1 WHERE department_id = 10;\n<\/code><\/pre>\n<\/li>\n<li><strong>\u663e\u5f0f\u6e38\u6807\uff08Explicit Cursors\uff09\uff1a<\/strong>\n<ul>\n<li>\u663e\u5f0f\u6e38\u6807\u662f\u7531\u7a0b\u5e8f\u5458\u663e\u5f0f\u5730\u58f0\u660e\u3001\u6253\u5f00\u3001\u5173\u95ed\u548c\u4f7f\u7528\u7684\u6e38\u6807\u3002\u901a\u8fc7\u663e\u5f0f\u6e38\u6807\uff0c\u53ef\u4ee5\u66f4\u7cbe\u786e\u5730\u63a7\u5236\u7ed3\u679c\u96c6\u7684\u5904\u7406\uff0c\u9010\u884c\u5904\u7406\u6570\u636e\u5e76\u6267\u884c\u76f8\u5e94\u7684\u64cd\u4f5c\u3002<\/li>\n<li>\u4f7f\u7528\u663e\u5f0f\u6e38\u6807\uff0c\u7a0b\u5e8f\u5458\u53ef\u4ee5\u5728 PL\/SQL \u4ee3\u7801\u4e2d\u58f0\u660e\u6e38\u6807\uff0c\u5e76\u901a\u8fc7\u6253\u5f00\u3001\u83b7\u53d6\u6570\u636e\u3001\u5173\u95ed\u6e38\u6807\u6765\u5904\u7406\u6570\u636e\u3002<\/li>\n<\/ul>\n<pre><code class=\"language-sql  line-numbers\">-- \u663e\u5f0f\u6e38\u6807\u7684\u4f8b\u5b50\nDECLARE\n   CURSOR emp_cursor IS\n       SELECT employee_id, last_name FROM employees WHERE department_id = 10;\n   emp_rec employees%ROWTYPE;\nBEGIN\n   OPEN emp_cursor;\n   LOOP\n       FETCH emp_cursor INTO emp_rec;\n       EXIT WHEN emp_cursor%NOTFOUND;\n       -- \u8fd9\u91cc\u53ef\u4ee5\u6267\u884c\u64cd\u4f5c\uff0c\u5982\u8f93\u51fa\u6216\u5176\u4ed6\u5904\u7406\n       DBMS_OUTPUT.PUT_LINE('Employee: ' || emp_rec.last_name);\n   END LOOP;\n   CLOSE emp_cursor;\nEND;\n<\/code><\/pre>\n<\/li>\n<\/ol>\n<p>\u603b\u7684\u6765\u8bf4\uff0c\u9690\u5f0f\u6e38\u6807\u662f\u7531 Oracle \u81ea\u52a8\u7ba1\u7406\u7684\uff0c\u800c\u663e\u5f0f\u6e38\u6807\u662f\u7a0b\u5e8f\u5458\u660e\u786e\u58f0\u660e\u548c\u63a7\u5236\u7684\u6e38\u6807\uff0c\u53ef\u4ee5\u7cbe\u786e\u5730\u5904\u7406\u6570\u636e\u5e76\u6267\u884c\u7279\u5b9a\u7684\u64cd\u4f5c\u3002\u663e\u5f0f\u6e38\u6807\u63d0\u4f9b\u4e86\u66f4\u591a\u7684\u63a7\u5236\u548c\u7075\u6d3b\u6027\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u5728 Oracle \u4e2d\uff0c\u9690\u5f0f\u6e38\u6807\u548c\u663e\u5f0f\u6e38\u6807\u662f\u4e24\u79cd\u4e0d\u540c\u7c7b\u578b\u7684\u6e38\u6807\uff0c\u5b83\u4eec\u7684\u533a\u522b\u5728\u4e8e\u58f0\u660e\u548c\u4f7f\u7528\u65b9\u5f0f\uff1a \u9690\u5f0f\u6e38\u6807\uff08Imp [&hellip;]<\/p>\n","protected":false},"author":11,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[120],"tags":[],"class_list":["post-15708","post","type-post","status-publish","format-standard","hentry","category-oracel"],"_links":{"self":[{"href":"http:\/\/wx.kaifamiao.info\/index.php\/wp-json\/wp\/v2\/posts\/15708","targetHints":{"allow":["GET"]}}],"collection":[{"href":"http:\/\/wx.kaifamiao.info\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/wx.kaifamiao.info\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/wx.kaifamiao.info\/index.php\/wp-json\/wp\/v2\/users\/11"}],"replies":[{"embeddable":true,"href":"http:\/\/wx.kaifamiao.info\/index.php\/wp-json\/wp\/v2\/comments?post=15708"}],"version-history":[{"count":1,"href":"http:\/\/wx.kaifamiao.info\/index.php\/wp-json\/wp\/v2\/posts\/15708\/revisions"}],"predecessor-version":[{"id":15709,"href":"http:\/\/wx.kaifamiao.info\/index.php\/wp-json\/wp\/v2\/posts\/15708\/revisions\/15709"}],"wp:attachment":[{"href":"http:\/\/wx.kaifamiao.info\/index.php\/wp-json\/wp\/v2\/media?parent=15708"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/wx.kaifamiao.info\/index.php\/wp-json\/wp\/v2\/categories?post=15708"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/wx.kaifamiao.info\/index.php\/wp-json\/wp\/v2\/tags?post=15708"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}