oracle 4中循環的寫法

create or replace function JC_TESTFUC(sname in varchar2) return nvarchar2 is
  type t_list is table of abc%rowtype index by binary_integer;
  nstr varchar2(3000);
   i integer:=0;
  s_date number;
  e_date number;
  temp_l number;
  t_infos t_list;
begin
  if sname = 'case1' then
    dbms_output.put_line('I am case1');
  elsif sname = 'case2' then
    dbms_output.put_line('I am case2');
  elsif sname = 'loop' then
  
    loop
     insert into aa(sname) values(i);
     exit when i=10;
     i:=i+1;
    end loop;
  elsif sname='for' then
 
    for i in 1..10 loop
      insert into aa(sname) values('for insert '||i);
    end loop;
  elsif sname='while' then
     while i<10 loop
       insert into aa(sname) values('while insert '||i);
       i:=i+1;
      end loop;
  elsif sname = 'forall' then
     --  此種方法優化了PL/SQL引擎,效率最快,可作爲批量導入的考慮

    -- 不過需要使用 bulk collect 纔可以,還有待研究
     select * bulk collect into t_infos  from abc  where rownum<10000;

     s_date :=dbms_utility.get_time;
     dbms_output.put_line('s_date '||s_date);
     forall i in 1..t_infos.count
       insert into aa(sname) values(t_infos(i).tname);
     e_date := dbms_utility.get_time;
     temp_l := e_date - s_date;
     dbms_output.put_line(temp_l);
  end if;

  return nstr;
end JC_TESTFUC;

發佈了12 篇原創文章 · 獲贊 2 · 訪問量 3萬+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章