易截截图软件、单文件、免安装、纯绿色、仅160KB

Oracle扩展PL/SQL简介(六)

8.    bulk collect /forall
使用bulk collect可以成块地读取数据,它可使SQL引擎在返回输出结果给PL/SQL引擎之前大批绑定输出集合。这样可以一次性地把数据动态地装载到集合中,但bulk collect需要大量内存。bulk collect可用于select into、fetch into和returning into语句中。
●    select into中使用bulk collect
declare
  type t_email is table of employees.email%type;
  v_email_list t_email;
begin
  select email bulk collect
    into v_email_list
    from employees
   where department_id = 50;
  dbms_output.put_line('获取email地址数:' || v_email_list.count);
end;
/
获取email地址数:45
●    fetch into 中使用bulk collect
declare
  type t_emp is table of employees%rowtype;
  v_emp_list t_emp;
  cursor c_emp is
    select * from employees where department_id = 50;
begin
  open c_emp;
  --在fetch into中使用bulk collect
  fetch c_emp bulk collect
    into v_emp_list;
  dbms_output.put_line('获取雇员总数:' || v_emp_list.count);
end;
/
获取雇员总数:45
●    在returning into中使用bulk collect
通过使用returning子句bulk collect可返回值给调用过程,不需要额外获取fetch语句。
--创建测试表
create table emptemp as select * from employees where department_id=50;
--执行过程
declare
  type t_id_list is table of number;
  type t_name_list is table of varchar2(32);
  ids   t_id_list;
  names t_name_list;
begin
  delete from emptemp
   where commission_pct is null
  returning employee_id, first_name bulk collect into ids, names;
  dbms_output.put_line('Deleted ' || sql%rowcount || ' rows:');
  for i in ids.first .. ids.last loop
    dbms_output.put_line('Employees #' || ids(i) || ': ' || names(i));
  end loop;
  commit;
exception
  when others then
    rollback;
end;


相关文档:

oracle 表空间操作

oracle表空间操作详解
  1
  2
  3作者:   来源:    更新日期:2006-01-04 
  5
  6 
  7建立表空间
  8
  9CREATE TABLESPACE data01
 10DATAFILE '/ora ......

Oracle系列:记录Record

 Oracle系列:记录(Record)
一,什么是记录(Record)?
 由单行多列的标量构成的复合结构。可以看做是一种用户自定义数据类型。组成类似于多维数组。
将一个或多个标量封装成一个对象进行操作。是一种临时复合对象类型。
 
 记录可以直接赋值。RECORD1 :=RECORD2;
 记录不可以整体比较. ......

Oracle Cursor

 1,什么是游标?
 ①从表中检索出结果集,从中每次指向一条记录进行交互的机制。
   
 ②关系数据库中的操作是在完整的行集合上执行的。
  由 SELECT 语句返回的行集合包括满足该语句的 WHERE 子句所列条件的所有行。由该语句返回完整的行集合叫做结果集。
   &n ......

Oracle 三种集合数据类型的比较

 Oracle 三种集合数据类型的比较:
PL/SQL中没有数组的概念,他的集合数据类型和数组是相似的。在7.3以前的版本中只有一种集合,称为PL/SQL表,在这之后又有两种集合数据类型:嵌套表和varray。其中varray集合中的元素是有数量限制的,index_by表和嵌套表是没有这个限制的。index-by表是稀疏的,也就是说下标可以不连续 ......
© 2009 ej38.com All Rights Reserved. 关于E健网联系我们 | 站点地图 | 赣ICP备09004571号