Oracle中,写存储过程,如何比较两条记录是否相同,两条记录分别来自两张表,表结构相同

2025-03-22 17:17:06
推荐回答(2个)
回答1:

DECLARE
v_count pls_integer;
BEGIN
select count(*) into v_count
from
(
select * from tb1 where
minus
select * from tb2 where ...
);
if v_count=0 then
dbms_output.put_line ('2条数据完全相等');
else
dbms_output.put_line ('2条数据不完全相等');
end if
END;

回答2:

利用minus语法。
v_count number;
select count(*) into v_count from(
select * from tbl1 where ***
minus
select * from tbl2 where ****
)
if v_count=0 then
相同
else
不相同
end if;