一 對象類型概述 oracle中的對象資料類型與其他面向對象設計語言中的對象類似,它也包含屬性和方法。我們也可以這樣了解,對象類型就是類。對象類型的方法用于描述對象要執行的操作。自定義方法時,可以定義構造方法,member方法,static方法,map方法及order方法。
對象表:指包含對象類型的列的表;包含行對象和列對象兩種對象表,其中行對象表是指在對象表中擁有整個行的對象,而列對象表則是指字段的類型可以是其他基本類型,也可以是對象類型,至少有一個字段的類型為對象類型。對象表中的每一行都是一個對象。
二 定義對象類型文法 Create [or replace] type <對象名> as object (屬性名1 資料類型1, … , 屬性名n 資料類型n)
三 行對象表執行個體
create or replace type scott.type_t as object(id int,name
varchar2(50)); /
執行了以上指令之後,會建立名稱為
type_t的對象類型,該對象類型包含兩個屬性:id和name。建立了對象類型之後,就可以使用該對象類型了。
建立type_t 對象類型在oracle日志表現為: 68 create or replace type type_t as
object(id int,name varchar2(50));;
create table scott.test_table_obj of scott.type_t;
建立行對象表在oracle日志表現為:39 create table test_table_obj of type_t;
insert into scott.test_table_obj values(1,'瑪麗');
插入行對象資料在oracle日志表現為:57 insert into "SCOTT"."TEST_TABLE_OBJ"("ID")
values ('1');-----oracle
日志不支援對象資料類型,導緻添加日志語句不全。
update scott.test_table_obj p set p.name='羅傑' where p.id=1;
更改行對象資料在oracle日志表現為:137 update "SCOTT"."TEST_TABLE_OBJ" a set
a."NAME" = '羅傑' where a."ID" = '1' and a."NAME" = '瑪麗' and a.ROWID =
'AABrn5AAJAAAlQ+AAA';
select * from scott.test_table_obj;
或者使用select value(p) from scott.test_table_obj p;
delete from scott.test_table_obj p where p.id=1;
删除行對象資料在oracle日志表現為:
94 delete from "SCOTT"."TEST_TABLE_OBJ" a where a."ID" = '1' and
a.ROWID = 'AABrn5AAJAAAlQ+AAB';
四 列對象表執行個體
create or replace type scott.test_t as object (val_str varchar2(30), val_date date,val_lob clob, val_file bfile,val_obj type_t,val_raw raw(10) ); /
建立對象類型在oracle日志表現為:151 create or replace type scott.test_t as object (val_str varchar2(30), val_date date,val_lob clob, val_file bfile,val_obj type_t,val_raw raw(10) );;
create table scott.test_object(val_int number, val_flt float,val scott.test_t);
建立列對象表在oracle日志表現為:83 create table scott.test_object(val_int number, val_flt float,val scott.test_t);
insert into scott.test_object values(1,1.201,scott.test_t('marry',to_date('1987-9-12 8:00:00','yyyy-mm-dd hh24:mi:ss'),empty_clob(),null,scott.type_t(2,'hello'),hextoraw('a')));
添加列對象表資料在oracle日志表現為:100 insert into "SCOTT"."TEST_OBJECT"("VAL_INT","VAL_FLT","VAL") values ('1','1.201',Unsupported Type);
update scott.test_object p set p.val_int=10,p.val.val_str='佳諾',p.val.val_obj.id=1 where p.val_int=1 and p.val.val_obj.id=2;
更改列對象表資料在oracle日志表現為:199 update "SCOTT"."TEST_OBJECT" a set a."VAL_INT" = '10', a."VAL" = Unsupported Type where a."VAL_INT" = '1' and a."VAL_FLT" = '1.201' and a."VAL" = Unsupported Type and a.ROWID = 'AABroQAAJAAAlQoAAA';
删除列對象表資料
delete from scott.test_object p where p.val_int=10 and p.val.val_obj.id=1;
删除列對象表資料在oracle日志表現為:154 delete from "SCOTT"."TEST_OBJECT" a where a."VAL_INT" = '10' and a."VAL_FLT" = '1.201' and a."VAL" = Unsupported Type and a.ROWID = 'AABroTAAJAAAlQoAAA';
DECLARE
v_int number;
v_flt float;
test scott.test_t;
BEGIN
select val_int,val_flt,val into v_int,v_flt ,test from scott.test_object;
dbms_output.put_line('val_int :'||v_int||', val_flt:'||v_flt||', val_str:'||test.val_str||', id:'||test.val_obj.id);
END;
/