国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 數(shù)據(jù)庫 > Oracle > 正文

oracle下巧用bulk collect實(shí)現(xiàn)cursor批量fetch

2024-08-29 13:28:23
字體:
供稿:網(wǎng)友

在一般的情況下,使用批量fetch的幾率并不是很多,但是Oracle提供了這個(gè)功能我們最好能熟悉一下,說不定什么時(shí)候會(huì)用上它。

  復(fù)制代碼 代碼如下:

  declare
  cursor c1 is select * from t_depart;
  v_depart t_depart%rowtype ;
  type v_code_type is table of t_depart.depart_code%type ;
  v_code v_code_type ;
  type v_name_type is table of t_depart.depart_name%type ;
  v_name v_name_type ;
  begin
  open c1;
  fetch c1 bulk collect into v_code , v_name ;
  for i in 1..v_code.count loop
  dbms_output.put_line(v_code(i)||' '||v_name(i));
  end loop;
  close c1;
  end;

  通過上面的這個(gè)列子大家可以發(fā)現(xiàn)如果列很多的話,為每一列定義一個(gè)集合似乎有些繁瑣,可以把集合和%rowtype結(jié)合起來一起使用簡化程序!

  復(fù)制代碼 代碼如下:

  declare
  cursor c1 is select * from t_depart;
  type v_depart_type is table of t_depart%rowtype ;
  v_depart v_depart_type ;
  begin
  open c1;
  fetch c1 bulk collect into v_depart ;
  for i in 1..v_depart.count loop
  dbms_output.put_line(v_depart(i).depart_code||' '||
  v_depart(i).depart_name);
  end loop;
  close c1;
  end;

  在輸出結(jié)果時(shí)既可以使用集合的count屬性和可以使用first和last,在引用%rowtype類型的內(nèi)容時(shí)還有一個(gè)需要注意的地方是v_depart(i).depart_code,而不是v_depart.depart_code(i),當(dāng)然沒有這樣的寫法,即使有意義也并不一樣。

  復(fù)制代碼 代碼如下:

  declare
  cursor c1 is select * from t_depart;
  type v_depart_type is table of t_depart%rowtype ;
  v_depart v_depart_type ;
  begin
  open c1;
  fetch c1 bulk collect into v_depart ;
  for i in v_depart.first..v_depart.last loop
  dbms_output.put_line(v_depart(i).depart_code||' '||
  v_depart(i).depart_name);
  end loop;
  close c1;
  end;

發(fā)表評(píng)論 共有條評(píng)論
用戶名: 密碼:
驗(yàn)證碼: 匿名發(fā)表
主站蜘蛛池模板: 仪征市| 邯郸县| 福清市| 海阳市| 四会市| 玉环县| 雷波县| 莲花县| 通许县| 神农架林区| 宜丰县| 雷波县| 台中县| 浦城县| 清镇市| 武城县| 儋州市| 西藏| 常熟市| 浦东新区| 五莲县| 竹溪县| 商河县| 岳普湖县| 塔城市| 开化县| 拜城县| 什邡市| 阳曲县| 仲巴县| 肃北| 微山县| 柳州市| 思南县| 蓬溪县| 大理市| 临武县| 嵊州市| 青海省| 南乐县| 康定县|