残锅 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
    关注
    评论

报告相同问题?

悬赏问题

  • ¥15 运筹学排序问题中的在线排序
  • ¥15 关于docker部署flink集成hadoop的yarn,请教个问题 flink启动yarn-session.sh连不上hadoop,这个整了好几天一直不行,求帮忙看一下怎么解决
  • ¥30 求一段fortran代码用IVF编译运行的结果
  • ¥15 深度学习根据CNN网络模型,搭建BP模型并训练MNIST数据集
  • ¥15 C++ 头文件/宏冲突问题解决
  • ¥15 用comsol模拟大气湍流通过底部加热(温度不同)的腔体
  • ¥50 安卓adb backup备份子用户应用数据失败
  • ¥20 有人能用聚类分析帮我分析一下文本内容嘛
  • ¥30 python代码,帮调试,帮帮忙吧
  • ¥15 #MATLAB仿真#车辆换道路径规划