是的,您可以使用 aMAP MEMBER FUNCTION
来支持比较类型的嵌套表。
--#1: Create object
create or replace type type1 is object
(
a integer,
b varchar2(100),
c date,
map member function compare return raw
);
/
--#2: Create map function for comparisons.
--Returns the concatenated RAW of all attributes.
--Note that this will consider NULLs to be equal!
create or replace type body type1 as
map member function compare return raw is
begin
return
utl_raw.cast_to_raw(to_char(a))||
utl_raw.cast_to_raw(b)||
utl_raw.cast_to_raw(to_char(c, 'DD-MON-YYYY HH24:MI:SS'));
end;
end;
/
--#3: Create nested table of the types
create or replace type type1_nt is table of type1;
/
--#4: Compare.
--You could use MULTISET, but it's easier to use regular operators like "<>" "and =".
declare
tt1 type1_nt := type1_nt(type1(0, 'A', date '2000-01-01'),
type1(0, 'A', date '2000-01-01'));
tt2 type1_nt := type1_nt(type1(0, 'B', date '2000-01-01'),
type1(0, 'B', date '2000-01-01'));
tt3 type1_nt := type1_nt(type1(0, 'B', date '2000-01-01'),
type1(0, 'B', date '2000-01-01'));
begin
if tt1 <> tt2 and tt2 = tt3 then
dbms_output.put_line('Pass');
else
dbms_output.put_line('Fail');
end if;
end;
/
我不知道这是否比手动比较每个属性更快。但我想差异不会很大。