PL/SQL--复杂数据类型

来源:互联网 发布:手机直播源码破解版 编辑:程序博客网 时间:2024/05/16 18:57

PL/SQL–复杂数据类型

PLSQL 中常用的自定义类型就两种:记录类型、PLSQL 内存表类型(根据表中的数据字段的简单和复杂) 程度又可分别实现类似于简单数组和记录数组的功能

记录类型

declare   type emp_type is record  (last_name    varchar2(10),   first_name   varchar2(10),   salary       number(6)  not null default 0);  emp_param     emp_type; begin  select first_name, last_name, salary        into emp_param.first_name, emp_param.last_name, emp_param.salary       from employees       where employee_id = 100;       dbms_output.put_line(emp_param.first_name);end;

行类型

declare   emp_param     employees%rowtype; begin  select *     into emp_param    from employees    where employee_id = 100;  dbms_output.put_line(emp_param.email); end;

内存表

PLSQL 内存表即 Index By Table , 这种结构类似于数组,使用主键提供类似于数组那样的元素访问。 这种类型必须包括两部分:1 、使用 BINARY_INTEGER 类型构成的索引主键; 2 、另外一个简单类型或者用户自定义类型的字段作为具体的数组元素。

declare  type index_type     is table of employees.last_name%type    index by binary_integer;  index_param index_type;begin   for i in 100..106 loop    select last_name       into index_param(i)        from employees      where employee_id = i;  end loop;  for j in 100..index_param.count+99 loop    dbms_output.put_line(index_param(j));      end loop;end;
0 0