天天看点

对象数据类型1(行对象表与列对象表)

一 对象类型概述       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;

       /