一个简单的存储过程,帮忙看一下
传入年月yearmonth,型号actypeChar,和数字num
得到rpt_bjch_midvalue 这张表的对应型号和传入年月的前num个月的UNPLANED_CH_NUM 的总和
自己写了个,完全错的,大家帮帮忙啊
rpt_bjch_midvalue CREATE OR REPLACE procedure GET_UNPLANED_CH_NUM(
@yearmonth varchar2,
@actypeChar varchar2,
@num int)
as
begin
declare @s int
set @s = 'select a.UNPLANED_CH_NUM from rpt_bjch_midvalue a where
(a.YEARMONTH between to_char(add_months(to_date(''+@yearmonth+'','yyyy-mm'),'+@num+'),'yyyy-mm') and ''+@yearmonth+'') and a.ACTYPE = ''+@actypeChar+''
return sum(@s)
commit;
end;
/
------解决方案--------------------CREATE OR REPLACE procedure GET_UNPLANED_CH_NUM(
@yearmonth in varchar2,
@actypeChar in varchar2,
@num in int,
@s out int)
as
begin
select sum(a.UNPLANED_CH_NUM) into @s from rpt_bjch_midvalue a
where a.YEARMONTH-to_date(a.YEARMONTH,'yyyymm')<=@num and
a.ACTYPE=@actypeChar;
end;
/
兄弟啊,实在看不清你写的存储过程,隐隐约约不确定的写了下.
期待楼下的高见!
------解决方案--------------------
--try
SQL code
CREATE or replace procedure GET_UNPLANED_CH_NUM
(v_yearmonth in varchar2, v_actypeChar in varchar2,
v_num in number, v_CH_NUM out number)
as
begin
Select sum(UNPLANED_CH_NUM) into v_CH_NUM from rpt_bjch_midvalue
Where to_char(YEARMONTH,'yyyy-mm') between v_yearmonth and
to_char(add_months(to_date(v_yearmonth,'yyyy-mm'),v_num),'yyyy-mm')
and ACTYPE=v_actypeChar ;
end GET_UNPLANED_CH_NUM;