oracle存储过程如何动态修改表名关联查询
想请问下各位,我现在有个表前面是以'sms_dx_demo_'开头的,每天的记录会根据每天的日期存放在一张表里,比如今天22号,就会放在sms_dx_demo_22表中,...
想请问下各位,我现在有个表前面是以'sms_dx_demo_'开头的,每天的记录会根据每天的日期存放在一张表里,比如今天22号,就会放在sms_dx_demo_22表中,现在我这边有个存储过程,我需要每天跑一次,然后每天这个表名都会动态变化,请问横线表名部分怎么拼装,谢谢!
day varchar2(2); ------日期---- 短信表后缀select to_char(sysdate-1,'dd') into day from dual;
------ 统计xxxx成功量selectsum(sms.send_count) into sa_send_cnt from core_school sc
inner join sms_mt_send sms on sc.school_id = sms.school_id
inner join 'sms_mt_send_detail'||day detail on sms.mt_send_id = detail.mt_send_id
where sms.data_src in (1,2,3) and (detail.errorcode ='0'or detail.errorcode isnull) ; 展开
day varchar2(2); ------日期---- 短信表后缀select to_char(sysdate-1,'dd') into day from dual;
------ 统计xxxx成功量selectsum(sms.send_count) into sa_send_cnt from core_school sc
inner join sms_mt_send sms on sc.school_id = sms.school_id
inner join 'sms_mt_send_detail'||day detail on sms.mt_send_id = detail.mt_send_id
where sms.data_src in (1,2,3) and (detail.errorcode ='0'or detail.errorcode isnull) ; 展开
2个回答
展开全部
用动态sql拼接语句就好了!
VSQL varchar2(2000)
day varchar2(2);
begin
day:= to_char(sysdate-1,'dd');
VSQL:=' selectsum(sms.send_count) into sa_send_cnt from core_school sc
inner join sms_mt_send sms on sc.school_id = sms.school_id
inner join sms_mt_send_detail_'||day||' detail on sms.mt_send_id = detail.mt_send_id
where sms.data_src in (1,2,3) and (detail.errorcode ='0'or detail.errorcode isnull) ';
execute immdiate VSQL;
end
VSQL varchar2(2000)
day varchar2(2);
begin
day:= to_char(sysdate-1,'dd');
VSQL:=' selectsum(sms.send_count) into sa_send_cnt from core_school sc
inner join sms_mt_send sms on sc.school_id = sms.school_id
inner join sms_mt_send_detail_'||day||' detail on sms.mt_send_id = detail.mt_send_id
where sms.data_src in (1,2,3) and (detail.errorcode ='0'or detail.errorcode isnull) ';
execute immdiate VSQL;
end
本回答被提问者和网友采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
你前面说的和后面的SQL好像没有什么关联
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询