ORACLE 存储过程 在此 SELECT 语句中缺少 INTO 子句,怎么办?

create or replace procedure cp_DialSrvlevelStat(
userid in int,
bgdate in date,
enddate in date,
month_ in int,
year_ in int,
isvalid in int )
is
begin
select userid,sum(to_number(servicelevel)) from trunklog where

(userid is null or userid = userid) and
(bgdate is null or dialtime >= bgdate) and
(enddate is null or dialtime >= enddate) and
(month_ is null or to_char(dialtime, 'mm ') = month_) and
(year_ is null or to_char(dialtime, 'yyyy ') = year_) and
(isvalid is null or servicetime > 0) group by userid;

end cp_DialSrvlevelStat;

执行提示错误:PLS-00428:在此 SELECT 语句中缺少 INTO 子句

请问应该怎么修改?
最新回答
我是太阳啊

2024-04-20 02:14:31

select出来的结果要放到变量中去,select ... into .... from ... where ....
追问
谢谢,这个变量是自己声明,还是使用参数中的变量呢?
追答
理论上是都可以的,但是如果应用过程中,参数中的变量一般都是传进来的,所以已经有值,既然作为参数,肯定是利用传进来的值再到SELECT的WHERE条件中作为利用,您觉得呢?
SELECT出来的结果放到变量中,这个变量肯定是后声明的比较多,当然了,你也可以把SELECT出来的结果放到参数变量中替代传递进来的参数值。
西雅图很忙°

2024-04-20 00:13:02

create or replace procedure cp_DialSrvlevelStat(
userid in int,
bgdate in date,
enddate in date,
month_ in int,
year_ in int,
isvalid in int )
is
--自己声明一个变量TEMP
TEMP VARCHAR2(128);
begin
--使用into 子句
select sum(to_number(servicelevel)) into TEMP from trunklog where
end cp_DialSrvlevelStat;