1、概念及使用
類似於C中的自定義類型,可用於定義某表的字段集合。
定義格式 type recordName is Record(
字段名稱 字段類型,
字段名稱 字段類型
);
使用步驟: 1)聲明結構體 2)定義結構體變量 3)使用。
2、例:
--在匿名塊中使用record,也可定義在過程、函數、包中。
declare
--聲明結構體
type re_stu is record(
rname student.name%type, --中間用逗號分開
rage student.age%type --最后一個字段沒有符號
); --以分號結束
--定義結構體變量
rw_stu re_stu;
cursor c_stu is select name,age from student;
begin
open c_stu;
loop
fetch c_stu into rw_stu; --使用結構體變量
exit when c_stu%notfound;
dbms_output.put_line('姓名='||rw_stu.rname||' 年齡='||rw_stu.rage);
end loop;
close c_stu;
end;