日期:2014-05-17  浏览次数:21076 次

创建的函数带有编译错误,急~~~
CREATE OR REPLACE FUNCTION numpass
  (level char)
  return number
  as
num_pass number
begin
  if level="优" then
  select count(*) into num_pass from grade where grade>='90';
  elseif level="良" then
  select count(*) into num_pass from grade where grade>='75";
  elseif level="及格" then
  select count(*) into num_pass from grade where grade>='60";
  elseif level="不及格" then
  select count(*) into num_pass from grade where grade<'60';
  end if;
  return num_pass;
  end;

警告: 创建的函数带有编译错误。


用show error后提示

SQL> show error
FUNCTION NUMPASS 出现错误:

LINE/COL ERROR
-------- -----------------------------
6/1 PLS-00103: 出现符号 "BEGIN"在需要下列之一时:
  := . ( @ % ; not null
  range default character

有谁能帮忙下嘛谢谢

------解决方案--------------------
有很多的基本语法错误,如elseif就为ELSEIF,再有数字不用加单引号。
具体代码请参考:
SQL code

CREATE OR REPLACE FUNCTION numpass(level CHAR)
RETURN NUMBER
AS
    num_pass NUMBER;
BEGIN
    IF level="优" THEN
        SELECT COUNT(*) INTO num_pass FROM grade WHERE grade>= 90;
    ELSIF level="良" THEN
        SELECT COUNT(*) INTO num_pass FROM grade WHERE grade>= 75;
    ELSIF level="及格" THEN
        SELECT COUNT(*) INTO num_pass FROM grade WHERE grade>= 60;
    ELSIF level="不及格" THEN
        SELECT COUNT(*) INTO num_pass FROM grade WHERE grade < 60;
    END IF;
    RETURN num_pass;
END;