正 文

在Oracle9i Release 2中使用PL/SQL的集合增强


www.7dspace.com  更新日期:2005-11-7 3:02:20  七度空间


Oracle Release 2提供对PL/SQL集合的增强,它可以通过以前的发布版本进行代码维护。例如,你可以在Release 2中将PL/SQL集合用作一个单一的参数,从而避免了使用一长串的域作为参数。

另外一个优点是记录的集合现在可以是BULK COLLECTION INTO子句的目标。在Release 2以前,我们必须为返回的每个列创建一个集合。例如:

Declare
    type deptno_coll is table of dept.deptno%type;
    type dname_coll is table of dept.dname%type;
    type loc_coll is table of dept.loc%type;
    deptno_listdeptno_coll;
    dname_listdname_coll;
    loc_listloc_coll;
begin
    select * bulk collect into deptno_list,dname_list,loc_list from dept;
end;

在Release 2中,可以用下面的代码实现同样的功能:

Declare
    type dept_coll is table of dept%rowtype;
    dept_listdept_coll;
begin
    select * bulk collect into dept_list from dept;
end;

注意这里不再有对列名的引用。如果DEPT表的列的个数或者名字被修改,你也不需要对第二段示例代码进行改动。这段代码还比旧版本易于维护。然而,应用程序需要一个Release 2数据库来编译。

现在你可以使用记录以集合方式将一行数据插入到一个表中。在Release 2之前,你必须插入到表中一个PL/SQL记录然而再单独地确定每一列,作法如下:

Declare
    dept_rowdept%rowtype;
begin
    /* populate dept_row . . . */
    insert into dept values (dept_row.deptno,dept_row.dname,dept_row.loc);
end;

而在Release 2中你可以将插入语句简化为如下的语句:

    insert into dept values dept_row;

2页,页码:[1] [2] 

上一篇:在Windows中使用Oracle objects for OLE
下一篇:在Oracle 9i里对基于函数的索引进行仅索引扫描
作者:Scott Stephens  来源:开发者在线 ( 责任编辑:7dspace )
收藏此页】【打印】【关闭
站 内 搜 索
 

热 点 导 读
特 别 推 荐