残锅 2016-11-07 12:06 采纳率: 0%
浏览 876
已结题

ORCALE存储函数转换为MySQL存储函数

具体语句如下:
CREATE OR REPLACE
procedure yiliu_yeji as
cursor emp_cur is select to_char(mb.register_time,'yyyy-mm') as dd from member mb where mb.member_type = 0 group by to_char(mb.register_time,'yyyy-mm');
c_row emp_cur%rowtype;
tableCount number;
v_sql varchar2(2555);

begin_day date := to_date('2013-12-01', 'yyyy-mm-dd');
end_day date := sysdate;
begin

select count(1) into tableCount from all_tables where TABLE_NAME = 'DATA_BAK';
if tableCount=1 then
execute immediate 'drop table data_bak';
end if;

execute immediate 'create table data_bak as
select arpm.id,
arpm.nick_name,
arpm.real_name,
sum(case when mab.trade_Type = ''Buy'' then mab.amount when (mab.description like ''%????,?%'' and mab.trade_Type = ''Refund'') or (mab.description like ''%?????%'' and mab.trade_Type = ''Refund'') or (mab.description like ''%????%'' and mab.trade_Type = ''Refund'') or (mab.description like ''%?????%'' and mab.trade_Type = ''Refund'') or (mab.description like ''%?????%'' and mab.trade_Type = ''Refund'') then mab.amount else 0 end ) * -1 as "BB",
0 as "CC",
0 as "DD",
to_char(mab.trade_time, ''YYYY-MM-dd'') as "TT"

from member mb,
member arpm,
agency_relationship arp,
member_account ma,
member_account_bill mab
where mb.id = arp.customer_account
and mb.id = ma.member_id
and ma.id = mab.account_id
and mb.member_type = 0
and arpm.member_type = 2
and arpm.id = arp.parent_id
group by arpm.id,arpm.nick_name,arpm.real_name, to_char(mab.trade_time, ''YYYY-MM-dd'')';

while begin_day <= end_day loop
v_sql := 'INSERT INTO data_bak
select
m.id,
m.nick_name,
m.real_name,
0,
0,
0,
'''|| to_char(begin_day, 'yyyy-mm-dd') || ''' from member m where m.id not in (select db.id from data_bak db where db.tt = ' || to_char(begin_day, '''yyyy-mm-dd''') || ' group by db.id) and m.member_type = 2';

  execute immediate v_sql;
  begin_day := begin_day + 1;
  commit;

end loop;

for c_row in emp_cur loop

v_sql := ' insert into data_bak
select arpm.id,arpm.nick_name,arpm.real_name,0,count(mb.id),0, '''||c_row.dd || '-01''
from
member mb,
member arpm,
agency_relationship arp
where mb.id = arp.customer_account
and mb.member_type = 0
and arpm.member_type = 2
and arpm.id = arp.parent_id
and to_char(mb.register_time,''yyyy-mm'') = '''|| c_row.dd || '''
and exists (select * from member_account ma, member_account_bill mab where ma.id = mab.account_id and mab.trade_type = ''Buy'' and ma.member_id = mb.id and to_char(mab.trade_time, ''yyyy-mm'') = '''||c_row.dd ||''')
group by arpm.id,arpm.nick_name,arpm.real_name';

execute immediate v_sql;
commit;
v_sql := 'insert into data_bak
select arpm.id,
arpm.nick_name,
arpm.real_name,
0,
0 as "CC",
sum(case
when mab.trade_Type = ''Buy'' then
mab.amount
when (mab.description like ''%????,?%'' and mab.trade_Type = ''Refund'') or
(mab.description like ''%?????%'' and mab.trade_Type = ''Refund'') or
(mab.description like ''%????%'' and mab.trade_Type = ''Refund'') or
(mab.description like ''%?????%'' and mab.trade_Type = ''Refund'') or
(mab.description like ''%?????%'' and mab.trade_Type = ''Refund'') then
mab.amount
else
0
end) * -1 as "BB",
'''||c_row.dd || '-01''
from member mb,
member arpm,
agency_relationship arp,
member_account ma,
member_account_bill mab
where mb.id = arp.customer_account
and mb.id = ma.member_id
and ma.id = mab.account_id
and mb.member_type = 0
and arpm.member_type = 2
and arpm.id = arp.parent_id
and to_char(mb.register_time,''yyyy-mm'') = '''|| c_row.dd || '''
and to_char(mab.trade_time,''yyyy-mm'') = '''|| c_row.dd || '''
group by arpm.id, arpm.nick_name, arpm.real_name';

execute immediate v_sql;
commit;
end loop;

execute immediate 'insert into data_detail select to_char(sysdate, ''yyyy-mm-dd hh24:mi:ss'') from dual';
commit;

end;

提供资料也行,谢谢

  • 写回答

1条回答 默认 最新

  • dabocaiqq 2016-11-07 13:13
    关注
    评论

报告相同问题?

悬赏问题

  • ¥50 有数据,怎么建立模型求影响全要素生产率的因素
  • ¥50 有数据,怎么用matlab求全要素生产率
  • ¥15 TI的insta-spin例程
  • ¥15 完成下列问题完成下列问题
  • ¥15 C#算法问题, 不知道怎么处理这个数据的转换
  • ¥15 YoloV5 第三方库的版本对照问题
  • ¥15 请完成下列相关问题!
  • ¥15 drone 推送镜像时候 purge: true 推送完毕后没有删除对应的镜像,手动拷贝到服务器执行结果正确在样才能让指令自动执行成功删除对应镜像,如何解决?
  • ¥15 求daily translation(DT)偏差订正方法的代码
  • ¥15 js调用html页面需要隐藏某个按钮