PL SQL中的記錄

2021-08-30 09:15:01 字數 1240 閱讀 8841

--記錄,類似於物件(先定義乙個記錄,然後定義乙個該記錄型別的引用)

--普通定義方式

declare

type student is record(

sid number,

sname varchar(20),

sclass varchar(10)

);stu student;

begin

select sno,sname,sclass into stu from student where sno=1001;

dbms_output.put_line('學號 姓名 班級');

dbms_output.put_line(stu.sid||' '||stu.sname||' '||stu.sclass);

end;

/

--%type方式 該方式定義的記錄屬性的資料型別和資料長度均和表中對應的字段一直

declare

type t_stu is record(

sid student.sno%type,

sname student.sname%type,

sclass student.sclass%type

);v_stu t_stu;

begin

select sno,sname,sclass into v_stu from student where sno=1001;

dbms_output.put_line('學號 姓名 班級');

dbms_output.put_line(v_stu.sid||' '||v_stu.sname||' '||v_stu.sclass);

end;

/

--定義表裡所有的字段為記錄型別,rwotype,訪問其中欄位為表的欄位名稱

declare

v_stu student%rowtype;

begin

select sno,sname,sclass into v_stu from student where sno=1001;

dbms_output.put_line('學號 姓名 班級');

dbms_output.put_line(v_stu.sno||' '||v_stu.sname||' '||v_stu.sclass);

end;

/

pl sql記錄型別

1.定義plsql記錄 可以自定義記錄型別和記錄變數。也可以使用 rowtype屬性定義記錄變數。自定義plsql記錄 需要分別定義記錄型別和記錄變數。例如 declare type emp record type is record 定義記錄型別 name emp.ename type,記錄成員 ...

plsql記錄型別

1 基於表的記錄 2 基於游標的記錄 3 使用者自定義的記錄 使用 rowtype屬性,可以建立基於表和基於游標的記錄.plsql 提供使用者定義的記錄型別,使用它可以完全控制記錄結構,建立的通用語法 b type type name is record field1 datatype not nu...

pl sql記錄型別

1.定義plsql記錄 可以自定義記錄型別和記錄變數。也可以使用 rowtype屬性定義記錄變數。自定義plsql記錄 需要分別定義記錄型別和記錄變數。例如 declare type emp record type is record 定義記錄型別 name emp.ename type,記錄成員 ...