Oracle_Record

--record
--聲明方式:基於table,基於Cursor,用戶自定義
--基於table
declare
my_record t_mt_ctry%rowtype;
begin
--TODO
end;

--基於Cursor
declare
cursor my_cursor is
select * from t_mt_ctry;
my_record my_cursor%rowtype;
begin
--TODO
end;

--用戶自定義
declare
Type my_record is record(
id t_mt_ctry.id%type;
name varchar2(200);
)
my_record my_record;
begin
--TODO
end;

--Record level processing
/*
#1,咱們可在把一個記錄的內容拷貝到另外一個記錄,只要這些記錄是基於相同的記錄
類型或者兼容的%rowtype記錄類型便可(這些記錄類型具備相同數量的字段,
字段的數據類型相同或者能夠隱式的互相轉換)

#2,咱們能夠用賦值操做給記錄賦一個NULL值。
#3,咱們能夠在參數列表中定義記錄類型,並傳遞記錄參數。
#4,咱們的函數接口能夠返回記錄類型。


NOTE:
#1,咱們不能用 IS NULL語法來判斷一個記錄的全部字段都是NULL。相反,咱們必須
對每一個字段使用IS NULL操做符。
#2,咱們不能對兩個濟洛路做比較-好比,咱們不能比較記錄(它們的字段值)是相等仍是
不相等,或者一個記錄是比另外一個記錄大或是小。咱們只能比較每個字段。
*/

declare
my_record t_mt_ctry%rowtype;
my_record2 t_mt_ctry%rowtype;
my_record3 my_record2%type;
begin
select * into my_record from t_mt_ctry where cd='CN';
my_record2 := my_record;
my_record :=null;
 
dbms_output.put_line(my_record.id || '---' || my_record.cd);
dbms_output.put_line(my_record2.id || '---' || my_record2.cd);
dbms_output.put_line(my_record3.id || '---' || my_record3.cd);

/*

output:
---
CB0301BD60B94618990768E23FD513A5---CN
---

*/

end;



--Field level processing
declare
cursor my_cursor is
select * from t_mt_ctry;
my_record my_cursor%rowtype;
begin
open my_cursor;
loop
fetch my_cursor into my_record;
dbms_output.put_line(my_record.id || '---' || my_record.cd);
exit when my_cursor%notfound;
end loop;
close my_cursor;

end;
相關文章
相關標籤/搜索
本站公眾號
   歡迎關注本站公眾號,獲取更多信息