{"id":251268,"date":"2022-09-03T08:56:37","date_gmt":"2022-09-03T00:56:37","guid":{"rendered":"https:\/\/lrxjmw.cn\/?p=251268"},"modified":"2022-08-29T08:57:18","modified_gmt":"2022-08-29T00:57:18","slug":"oracle-for-linux","status":"publish","type":"post","link":"https:\/\/lrxjmw.cn\/oracle-for-linux.html","title":{"rendered":"\u7b80\u5355\u4ecb\u7ecdOracle\u4e2dfor\u5faa\u73af\u7684\u4f7f\u7528\u65b9\u6cd5"},"content":{"rendered":"\n\n\n
\u5bfc\u8bfb<\/td>\n\u8fd9\u7bc7\u6587\u7ae0\u4ecb\u7ecd\u4e86Oracle\u4e2dfor\u5faa\u73af\u7684\u4f7f\u7528\u65b9\u6cd5\uff0c\u6587\u4e2d\u901a\u8fc7\u793a\u4f8b\u4ee3\u7801\u4ecb\u7ecd\u7684\u975e\u5e38\u8be6\u7ec6\u3002\u5bf9\u5927\u5bb6\u7684\u5b66\u4e60\u6216\u5de5\u4f5c\u5177\u6709\u4e00\u5b9a\u7684\u53c2\u8003\u501f\u9274\u4ef7\u503c\uff0c\u9700\u8981\u7684\u670b\u53cb\u53ef\u4ee5\u53c2\u8003\u4e0b<\/strong><\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n

Oracle for in loop \u5faa\u73af\u7684\u4e00\u4e9b\u5b9e\u4f8b,\u4ee5\u4f5c\u5b66\u4e60\u548c\u52a0\u5f3a\u4f7f\u7528\u719f\u7ec3\u5ea6\u53ca\u573a\u666f\u5e94\u7528.<\/p>\n

\u4e00\u4e9b\u6280\u5de7<\/strong><\/div>\n

for \u8bed\u53e5\u540e\u9762\u7684 loop end loop \u53ef\u4ee5\u7c7b\u6bd4\u6210 c#\/java \u7b49\u7f16\u7a0b\u8bed\u8a00 for \u8bed\u53e5\u540e\u9762\u7684\u8bed\u53e5\u5757\u7b26\u53f7(\u82b1\u62ec\u53f7{}), \u4ee5\u4fbf\u7406\u89e3\u548c\u4f7f\u7528.<\/p>\n

\u4e00\u4e9b\u5b9e\u4f8b<\/strong><\/div>\n
\u5faa\u73af\u8f93\u51fa\u6570\u503c<\/strong><\/span><\/div>\n
-- \u5faa\u73af\u8f93\u51fa\u6570\u503c\r\nbegin\r\n  for i in 1 .. 100 loop\r\n    sys.dbms_output.put_line(i);\r\n  end loop;\r\nend;<\/pre>\n
\u5faa\u73af\u7d2f\u52a0<\/strong><\/span><\/div>\n
-- \u5faa\u73af\u7d2f\u52a0\r\ndeclare\r\n  var_sum number := 0;\r\nbegin\r\n  for i in 1 .. 100 loop\r\n    var_sum := var_sum + i;\r\n  end loop;\r\n  sys.dbms_output.put_line(var_sum); -- 5050\r\nend;<\/pre>\n
\u6279\u91cf\u63d2\u5165<\/strong><\/span><\/div>\n
\r\n-- \u6279\u91cf\u63d2\u5165\r\nbegin\r\n  for i in 1 .. 100 loop\r\n    -- todo: insert into some_table(field1, field2, ..., fieldN) values(valie1, value2, ..., valueN);\r\n    sys.dbms_output.put_line('insert: ' || to_char(i));\r\n  end loop;\r\n  commit;\r\n  sys.dbms_output.put_line('\u591a\u6b21insert,\u7edf\u4e00commit');\r\nend;<\/pre>\n
\u6279\u91cf\u66f4\u65b0<\/strong><\/span><\/div>\n
\r\n-- \u6279\u91cf\u66f4\u65b0\r\nbegin\r\n  for i in 1 .. 100 loop\r\n    -- todo: update some_table set fieldN = valueN where fieldN = valueN;\r\n    sys.dbms_output.put_line('update: ' || to_char(i));\r\n  end loop;\r\n  commit;\r\n  sys.dbms_output.put_line('\u591a\u6b21update,\u7edf\u4e00commit');\r\nend;<\/pre>\n
\u5faa\u73af\u8f93\u51fa\u7528\u6237\u8868\u4fe1\u606f<\/strong><\/span><\/div>\n
-- \u67e5\u8be2\u4f60\u80fd\u7ba1\u7406\u7684\u6240\u6709\u7528\u6237\u4fe1\u606f\r\nselect user_id, username, created from all_users;\r\n \r\n-- \u5faa\u73af\u8f93\u51fa\u7528\u6237\u8868\u4fe1\u606f\r\nbegin\r\n  for cur_row in (select user_id, username, created from all_users) loop\r\n    sys.dbms_output.put_line(cur_row.username);\r\n  end loop;\r\nend;\r\n-- \u5f53\u5faa\u73af\u5bf9\u8c61\u662f\u6bd4\u8f83\u957f\u4e32\u7684SQL\u65f6,\u5efa\u8bae\u63d0\u53d6\u6e38\u6807,\u65b9\u4fbf\u540e\u7eed\u67e5\u770b\u548c\u7ef4\u62a4<\/pre>\n
\u5faa\u73af\u8f93\u51fa\u7528\u6237\u8868\u4fe1\u606f(\u6e38\u6807\u63d0\u53d6)<\/strong><\/span><\/div>\n
-- \u5faa\u73af\u8f93\u51fa\u7528\u6237\u8868\u4fe1\u606f(\u6e38\u6807\u63d0\u53d6)\r\ndeclare\r\n  -- \u63d0\u53d6\u6e38\u6807\u5bf9\u8c61,\u65b9\u4fbf\u5355\u72ec\u7ef4\u62a4SQL\r\n  cursor cursor_all_users is\r\n    select user_id, username, created from all_users;\r\n  -- \u6e38\u6807\u5b50\u9879(\u66f4\u591a\u7684\u65f6\u5019,\u8868\u662f\u52a8\u6001\u8868,\u6240\u4ee5\u8fd9\u53e5\u58f0\u660e\u4e5f\u53ef\u4ee5\u7701\u7565)\r\n  -- cursor_user all_users%rowtype;\r\nbegin\r\n  for cursor_user in cursor_all_users loop\r\n    dbms_output.put_line(cursor_user.username);\r\n  end loop;\r\nend;<\/pre>\n

\u4ee5\u4e0a\u5c31\u662f\u8fd9\u7bc7\u6587\u7ae0\u7684\u5168\u90e8\u5185\u5bb9\u4e86\uff0c\u5e0c\u671b\u672c\u6587\u7684\u5185\u5bb9\u5bf9\u5927\u5bb6\u7684\u5b66\u4e60\u6216\u8005\u5de5\u4f5c\u5177\u6709\u4e00\u5b9a\u7684\u53c2\u8003\u5b66\u4e60\u4ef7\u503c<\/p>\n","protected":false},"excerpt":{"rendered":"

Oracle for in loop \u5faa\u73af\u7684\u4e00\u4e9b\u5b9e\u4f8b,\u4ee5\u4f5c\u5b66\u4e60\u548c\u52a0\u5f3a\u4f7f\u7528\u719f\u7ec3\u5ea6\u53ca\u573a\u666f\u5e94\u7528. for \u8bed\u53e5\u540e\u9762\u7684 […]<\/p>\n","protected":false},"author":362,"featured_media":75099,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[55],"tags":[],"class_list":["post-251268","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-thread"],"acf":[],"_links":{"self":[{"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/posts\/251268","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/users\/362"}],"replies":[{"embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/comments?post=251268"}],"version-history":[{"count":2,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/posts\/251268\/revisions"}],"predecessor-version":[{"id":251270,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/posts\/251268\/revisions\/251270"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/media\/75099"}],"wp:attachment":[{"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/media?parent=251268"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/categories?post=251268"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/tags?post=251268"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}