create or replace procedure count_num
(
in_sex in teachers.sex%type
)
as
out_num number;
begin
if in_sex='M' then
select count(sex) into out_num
from teachers
where sex='M';
dbms_output.put_line('NUMBER OF MALE TEACHERS:'||out_num);
else
select count(sex) into out_num
from teachers
where sex='F';
dbms_output.put_line('NUMBER OF FEMALE TEACHERS:'||out_num);
end if;
end ;
execute count_num('M');
执行该语句报错。
SQL>
begin count_num('M'); end;
ORA-06550: line 2, column 7:
PLS-00905: object SMP.COUNT_NUM is invalid
ORA-06550: line 2, column 7:
PL/SQL: Statement ignored
------解决方案--------------------
看一下你的存储过程是否在当前用户下。以及编译是否通过。。
------解决方案--------------------
找不到SMP.COUNT_NUM这个对象。COUNT_NUM是在这个schema下吗
------解决方案--------------------
-- create a test table first
create table teachers (name varchar2(255), sex char(1) );
create or replace procedure count_num
(
in_sex in teachers.sex%type
)
as
out_num number;
begin
if in_sex='M' then
select count(sex) into out_num
from teachers
where sex='M';
dbms_output.put_line('NUMBER OF MALE TEACHERS:'
------解决方案--------------------
out_num);
else
select count(sex) into out_num
from teachers
where sex='F';
dbms_output.put_line('NUMBER OF FEMALE TEACHERS:'
------解决方案--------------------
out_num);
end if;
end ;
-- execute procedure
execute count_num('M');
Toad执行结果:NUMBER OF MALE TEACHERS:0
------解决方案--------------------
是不是你执行方法有问题。
例如:
如果用类似于plsql这样的工具的话,在执行窗口就不能直接写execute count_num('M'); 来 这样子执行。