oracle存储过程
写一存储过程做统计,涉及几张表,基础信息表,存放需要统计的地区信息,例如北京、天津、上海
需要处理的逻辑是,循环基础信息表,按照对应的地区名称统计tablea里的这个月,上个月、去年这月的数据。
出现的问题是基础信息表只有一家公司数据正确,多家公司统计出来的ASUM变成了集合。每个地区的数据都一样。
cursor bt is
select distinct (companycnname) from BASETOTAL;
begin
v_Date := to_DATE(strDate, 'yyyy-mm');
v_lastMonthDate := add_months(v_Date, -1);
v_lastYearDate := add_months(v_Date, -12);
strDat := to_char(v_Date, 'yyyy-mm');
strLastMonthDate := to_char(v_lastMonthDate, 'yyyy-mm');
strLastYearDate := to_char(v_lastYearDate, 'yyyy-mm');
open bt;
LOOP
fetch bt
into COMPANYCNNAME;
exit when bt%notfound;
dbms_output.PUT_LINE('COMPANYCNNAME=' || COMPANYCNNAME)
while i <= 2 loop
If (i = 0) then
v_CREATETIME := strDat;
dbms_output.PUT_LINE(v_CREATETIME);
else
if (i = 1) then
v_CREATETIME := strLastMonthDate;
dbms_output.PUT_LINE(v_CREATETIME);
else
if (i = 2) then
v_CREATETIME := strLastYearDate;
dbms_output.PUT_LINE(v_CREATETIME);
end if;
end if;
end If;
select COUNT(*)
into ASUM form table1 WHERE to_char(t.CREATETIME, 'yyyy-mm') >= v_CREATETIME
AND T.ENABLE = 'T' AND SUBSTR(T.no, 2, 2) in
(select b.extno
from BASETOTAL b
where b.companycnname = COMPANYCNNAME);
dbms_output.PUT_LINE('ASUM =' || ASUM );
i := i + 1;
END loop;
commit;
end LOOP;
需要处理的逻辑是,循环基础信息表,按照对应的地区名称统计tablea里的这个月,上个月、去年这月的数据。
出现的问题是基础信息表只有一家公司数据正确,多家公司统计出来的ASUM变成了集合。每个地区的数据都一样。
cursor bt is
select distinct (companycnname) from BASETOTAL;
begin
v_Date := to_DATE(strDate, 'yyyy-mm');
v_lastMonthDate := add_months(v_Date, -1);
v_lastYearDate := add_months(v_Date, -12);
strDat := to_char(v_Date, 'yyyy-mm');
strLastMonthDate := to_char(v_lastMonthDate, 'yyyy-mm');
strLastYearDate := to_char(v_lastYearDate, 'yyyy-mm');
open bt;
LOOP
fetch bt
into COMPANYCNNAME;
exit when bt%notfound;
dbms_output.PUT_LINE('COMPANYCNNAME=' || COMPANYCNNAME)
while i <= 2 loop
If (i = 0) then
v_CREATETIME := strDat;
dbms_output.PUT_LINE(v_CREATETIME);
else
if (i = 1) then
v_CREATETIME := strLastMonthDate;
dbms_output.PUT_LINE(v_CREATETIME);
else
if (i = 2) then
v_CREATETIME := strLastYearDate;
dbms_output.PUT_LINE(v_CREATETIME);
end if;
end if;
end If;
select COUNT(*)
into ASUM form table1 WHERE to_char(t.CREATETIME, 'yyyy-mm') >= v_CREATETIME
AND T.ENABLE = 'T' AND SUBSTR(T.no, 2, 2) in
(select b.extno
from BASETOTAL b
where b.companycnname = COMPANYCNNAME);
dbms_output.PUT_LINE('ASUM =' || ASUM );
i := i + 1;
END loop;
commit;
end LOOP;
...全文
相关推荐
ORACLE存储过程最全教程
超实用最全的ORACLE教程
Oracle存储过程及调用
Oracle存储过程语法 Oracle的存储过程语法如下: create procedure 存储过程名称(随便取) is 在这里可以定义常量、变量、游标、复杂数据类型这里可以定义变量、常量 begin 执行部分 end; (2)带参数的存储过程语法: create procedure 存储过程名称(随便取) (变量1 数据类型,变量2 数据类型,...,变量n 数据类型) is 在这里可以定义常量、变量、游标、复杂数据类型这里可以定义变量、常量 begin 执行部分 end; (3)带输入、输出参数的存储过程语法: create procedure
oracle存储过程编写
NULL 博文链接:https://yunhuii.iteye.com/blog/888700
oracle存储过程各种写法
此文档对oracle存储过程做了详细讲解,游标用法 变量定义,触发器,序列,DML DCL DDL
oracle 存储过程
oracle 存储过程,关于存储过程的,函数,包等语法介绍


