Bulk Collect 使用說明

oracle bulk collect into 實現批量插入

  • 語法:
    fetch 遊標 bulk collect into 目標 [limit num]

*** 不加limit 默認取遊標中全部數據插入到目標中,如果加上limit,則限制數據量

  • 示例
    表結構:
    image

declare 
 type tb_type is table of   sales%rowtype;  --聲明一個表類型  tb_type
 cursor mycursor is select productname from sales;  --定義一個遊標
 my_tb tb_type;  --定義一個表類型變量
 type name_list_type is table of sales.productname%type;  --定義一個表類型
 name_list name_list_type;  --定義一個表類型變量(只有一列)
 begin
   open mycursor;   
    loop
    fetch mycursor bulk collect into name_list limit 3;  --用 bulk collect into 實現批量插入, 加 limit num  可以限定插入行數
    for it in 1..name_list.count loop
      dbms_output.put_line(name_list(it));  --這裏訪問數組使用  數組(索引)
    end loop;
      dbms_output.put_line('-----------');
    exit when mycursor%notfound; 
    end loop;
    close mycursor;
 end;
  • 結果

籃球
足球
羽毛球
·-----------
乒乓球
泰迪熊
·-----------

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章