使用minus对比两张表的数据

2017-05-04  本文已影响0人  study_monkey

CREATE OR REPLACE PACKAGE PKG_TEST IS

--*********************************************************************

--功能说明:使用minus比较相同结构的两张表的数据是否相同,如果minus为空,代表数据一致,count为0,则返回Y,否则返回N

--参数说明:

--输入 stat_date in varchar2 作为查询条件

--输出 data_result out varchar2 返回结果

--修改记录: update by study_monkey 2017.5.4

--删除测试PKG: DROP PACKAGE PKG_TEST;

--********************************************************************

procedure proc_compare_tbl_data(stat_date in varchar2,

data_result out varchar2)is

v_count pis_integer;

v_date_date DATE;

begin

v_date_date:=add_months(to_date(stat_date,'yyyymm'),1)-1;

select count(*) into v_count

from (

select r.stat_date,r.code,r.rvalue from tbl_test r

minus

select c.stat_date,c.code,c.rvalue from copy_tbl_test c

)where stat_date = v_date_date;

if v_count = 0 then

data_result = 'Y';

else

data_result = 'N';

end if;

exception

when others then

data_result :='N';

end  proc_compare_tbl_data;

end  PKG_TEST;

上一篇 下一篇

猜你喜欢

热点阅读