Oracle计算重复行的数量,重复行算作一条记录的方法

论坛 期权论坛 脚本     
已经匿名di用户   2022-4-26 15:53   1262   0

create or replace procedure panyh(v_cusid in varchar2, v_time in varchar2) as

v_con integer;

begin

delete from F_ORDERINFO_DETAIL_PAN t

where substr(t.order_date, 0, 4) = v_time

and customer_id = v_cusid;

commit;

insert into F_ORDERINFO_DETAIL_PAN

select t.*, 'Y'

from f_orderinfo_detail t

where substr(t.order_date, 0, 4) = v_time

AND T.CUSTOMER_ID = v_cusid;

commit;

update F_ORDERINFO_DETAIL_PAN set is_charge_flag='N' where order_type not in ('JBCX');

update F_ORDERINFO_DETAIL_PAN set is_charge_flag='N' where order_status not in ('查到');

for c1 in (select * from F_ORDERINFO_DETAIL_PAN t where substr(t.order_date,0,4)=v_time and t.order_type='JBCX' and t.order_status='查到' order by foi_orderno ) loop

select count(*)

into v_con

from F_ORDERINFO_DETAIL_PAN t

where t.order_date = c1.order_date

AND T.CUSTOMER_ID = v_cusid

and t.order_type = 'JBCX'

and t.order_status = '查到'

and t.foi_orderno=c1.foi_orderno

and t.foi_key in

(select foi_key

from F_ORDERINFO_DETAIL_PAN t

where to_date(foi_ordertime,'yyyy-mm-dd hh24:mi:ss') >=to_date(c1.foi_ordertime,'yyyy-mm-dd hh24:mi:ss')-30

and foi_ordertime

and foi_orderno not in (c1.foi_orderno)

and t.is_charge_flag='Y'

and t.order_type='JBCX'

and t.order_status='查到');

if v_con >0

then

update F_ORDERINFO_DETAIL_PAN t set t.is_charge_flag='N' where t.foi_orderno=c1.foi_orderno;

commit;

end if;

end loop;

end;

#######################

下面这个是我弟写的

create or replace procedure panyh5(v_cusid in varchar2, v_time in varchar2) as

v_count NUMBER;

begin

delete from F_ORDERINFO_DETAIL_PAN t

where substr(t.order_date, 0, 4) = v_time

and customer_id = v_cusid;

commit;

insert into F_ORDERINFO_DETAIL_PAN

select t.*, 'N'

from f_orderinfo_detail t

where substr(t.order_date, 0, 4) = v_time

AND T.CUSTOMER_ID = v_cusid;

commit;

update F_ORDERINFO_DETAIL_PAN a set is_charge_flag='Y'

where substr(order_date,0,4)=v_time and a.rowid in (

select min(b.rowid) from F_ORDERINFO_DETAIL_PAN b where b.foi_key=a.foi_key and substr(order_date,0,4)=v_time );

v_count := v_count + 1;

IF v_count >= 1000 THEN

commit;

end if;

commit;

end;

分享到 :
0 人收藏
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

积分:81
帖子:4969
精华:0
期权论坛 期权论坛
发布
内容

下载期权论坛手机APP