报表格式如下
输入是 开始月份(开始月份默认为1月),结束月份营业部名称 1月有效户数 …… X月有效户 合计合计PS:如果是输入1月和9月,则上面的统计就是1月到9月
表tabaa字段如下为
RQ 日期
YYB 营业部
LSH 流水号
YWLB 业务类别当YWLB为190时,为本月的有效用户上面的过程怎么写呢?请高手赐教
输入是 开始月份(开始月份默认为1月),结束月份营业部名称 1月有效户数 …… X月有效户 合计合计PS:如果是输入1月和9月,则上面的统计就是1月到9月
表tabaa字段如下为
RQ 日期
YYB 营业部
LSH 流水号
YWLB 业务类别当YWLB为190时,为本月的有效用户上面的过程怎么写呢?请高手赐教
create table table_name(
yyb_name varchar2(50),营业部名称
start_date number(8),--开始时间
end_date number(8),--结束时间
count_users number(10)--有效户数合计
)
create or replace procedure proc_name(f_month in number,l_month in number)
/**************
f_month为开始日期默认为年初话,如201001
l_month为结束日期
在这里用number类型了
**************/
is
insert into table_name--中间表
(yyb_name,营业部名称
start_date,--开始时间
end_date,--结束时间
count_users--有效户数合计)
select yyb,
f_month,
rq,
count(ywlb)
from your_table_name y
where y.rq <= l_month
and y.rq >= f_month
and y.ywlb = '190';
commit;
......
--你的其他需求
end;
前者的话
你的表结构什么写得也不清楚,我大体的代码写下create or replace procedure ...(start_month in varchar2,end_month in varchar2,cur out sys_refcursor)
as
sqlstr varchar2(4000):='select yyb';
begin
for cur1 in(select add_months(to_date(start_month,'yyyymm'),rownum-1)mon
from dual connect by rownum<=months_between(to_date(end_month,'yyyymm'),to_date(start_month,'yyyymm'))+1)
loop
sqlstr:=sqlstr||',count(decode(to_char(rq,''yyyymm''),'''||to_char(cur1.mon,'yyyymm')||''',1)) "'||to_char(cur1.mon,'yyyy"年"mm"月"')||'"';
end loop;
open cur for sqlstr||' from tabaa where twlb=''190''';
end;