将相同类型的记录与=和!=进行比较

时间:2016-01-15 19:17:58

标签: oracle plsql record

有没有办法比较Oracle中自定义的记录结构?我正在尝试=!=但我唯一得到的是编译时错误

  

PLS-00306:调用' ='

时参数的数量或类型错误      

PLS-00306:调用'!='

时参数的数量或类型错误

实施例

type my_type is record (
  a varchar2(6),
  b varchar2(6)
);

rec1 my_type;
rec2 my_type;

begin
  if rec1 = rec2 then
    null;
  end if;

  if rec1 != rec2 then
    null;
  end if;
end;

1 个答案:

答案 0 :(得分:2)

Per the doc:

**Record Comparisons**
Records cannot be tested natively for nullity, equality, or inequality. These BOOLEAN expressions are illegal:

My_Record IS NULL
My_Record_1 = My_Record_2
My_Record_1 > My_Record_2

You must write your own functions to implement such tests. For information about writing functions, see Chapter 8, "PL/SQL Subprograms."