我是一个刚开始学习PL/SQL的菜鸟,写了一段代码
set serveroutput on format wrapped
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 count_num;编译没有错误,但是执行时总报如下错误:
ERROR at line 1:
ORA-06550: line 1, column 7:
PLS-00306: wrong number or types of arguments in call to 'COUNT_NUM'
ORA-06550: line 1, column 7:
PL/SQL: Statement ignored请高手指点

解决方案 »

  1.   


    SQL> drop table teachers;Table droppedSQL> 
    SQL> create table teachers(sex varchar2(100));Table createdSQL> 
    SQL> create or replace procedure count_num(in_sex in teachers.sex%type) as
      2    out_num number;
      3  begin
      4    if in_sex = 'm' then
      5      select count(sex) into out_num from teachers where sex = 'm';
      6      dbms_output.put_line('number of male teachers:' || out_num);
      7    else
      8      select count(sex) into out_num from teachers where sex = 'f';
      9      dbms_output.put_line('number of female teachers:' || out_num);
     10    end if;
     11  end count_num;
     12  /Procedure createdSQL> insert into teachers values('m');1 row insertedSQL> commit;Commit completeSQL> set serveroutput on;
    SQL> select count_num('m') from dual;select count_num('m') from dualORA-00904: "COUNT_NUM": 标识符无效SQL> begin
      2  count_num('m');
      3  end;
      4  /number of male teachers:1PL/SQL procedure successfully completedSQL> 
      

  2.   

    我是用execute count_num('m');执行过程的,就是报错!还有teachers表中可以有其他字段吧,除了sex字段
      

  3.   

    你把前面加上你的用户名看看[username.]count_num('m')
      

  4.   

    入参类型teachers.sex%type改为varchar2就可以了,因为存储过程的入参不用指定长度,你的teachers.sex%type相当于指定长度了
      

  5.   

    execute count_num('m');    --plsql命令窗口begin
    count_num('m');
    end;    
    --sql窗口