oracle 11g中存储过程的编译错误和执行错误

时间:2014-04-25 15:18:31

标签: oracle11g plsqldeveloper

这是我的存储过程

create or replace procedure EMP_DB.std_stdsp
( stid  in out varchar(10),
 name   in out varchar(100)
)
is 
begin
select *from students s
where S.STDID in(stid)
and S.STDNME in (name);
end EMP_DB.std_stdsp;
/

编译错误

警告:编译但编译错误

当我执行存储过程时,我收到错误

EXEC EMP_DB.std_stdsp('1','Farhat');

错误

BEGIN EMP_DB.std_stdsp('1','Farhat'); END;
Error at line 1
ORA-06550: line 1, column 14:
PLS-00905: object EMP_DB.STD_STDSP is invalid
ORA-06550: line 1, column 7:
PL/SQL: Statement ignored

任何人都帮帮我。谢谢你提前

1 个答案:

答案 0 :(得分:1)

看起来您打算从select中获取多条记录。要处理多个记录,您需要一个循环。以下应该编译(抱歉,没有测试)

create or replace procedure EMP_DB.std_stdsp ( 
     stid  in out varchar(10),
     name   in out varchar(100)) is 
begin
  for rec in (select *
                from students s
                where S.STDID in(stid)
                  and S.STDNME in (name)) loop
    dbms_output.put_line ('student record');
    -- replace the dbms_output and this comment with some meaningful code
    -- any code inside the loop will execute once for each student record 
    -- returned from the select statement
  end loop;
end EMP_DB.std_stdsp;
/

第二个错误只是因为你的程序没有编译。

您打算将'1,3,5'之类的内容传递给stid参数以获取记录1,3和5.如果是这种情况,则无法按预期工作。 in将整个'1,3,5'作为单个值。要匹配表格中的记录,stdid列必须完全为'1,2,3'。如果要获取多条记录,可以将其切换为使用like而不是in。你必须添加一些通配符。