本帖最后由 dan 于 2020-3-7 21:03 编辑
1、概念及使用
类似于java中的bean,可用于定义某表的字段集合。
定义格式 type recordName is Record(
字段名称 字段类型,
字段名称 字段类型
);
使用步骤: 1)声明结构体 2)定义结构体变量 3)使用。2、例: --前提:create table goods (id number primary key,gname varchar2(20) default '' not null); --在匿名块中使用record,也可定义在过程、函数、包中。 declare --声明结构体 type rec_goods is record( id goods.id%type, --中间用逗号分开 gname goods.gname%type ); --以分号结束 --定义结构体变量 v_goods rec_goods; cursor cur_goods is select from goods; begin open cur_goods; loop fetch cur_goods into v_goods; --使用结构体变量 exit when cur_goods%notfound; dbms_output.put_line('编号='||v_goods.id||' 名称='||v_goods.gname); end loop; close cur_goods; end; ---------------------------------------- 编号=1 名称=banana 编号=2 名称=tv2 编号=3 名称=tv3 编号=4 名称=tv4 ---------------------------------------- |