1

我是 pl/sql 的菜鸟。我正在尝试使用 pl sql 计算 gpa。我创建了一个表,其中包含带有值的等级。

SSN             CNO           GRADE
--------------- -------- ----------
55555           cs101             1
55555           math101           4
55555           bio101            1
55555           cgdd101           3
55555           swe203            3
55555           eng101            3
11111           bio101            4
11111           cgdd101           4
55555           cs101             1
55555           math101           4
55555           bio101            1

我正在尝试使用以下 pl sql 函数计算 gpa,但出现以下错误。

55555           eng101            3

36 rows selected.

SQL> create or replace function get_count
  2  return is
  3  declare
  4  v_count number;
  5  begin
  6  select count(*) into v_count from grade;
  7  return grade;
  8
  9  end;
 10  /

Warning: Function created with compilation errors.

SQL> show errors
Errors for FUNCTION GET_COUNT:

LINE/COL ERROR
-------- -----------------------------------------------------------------
2/8      PLS-00103: Encountered the symbol "IS" when expecting one of the
         following:
         <an identifier> <a double-quoted delimited-identifier> self
         long double ref char time timestamp interval date binary
         national character nchar
4

2 回答 2

0

您的函数缺少返回数据类型,例如:

create or replace function get_count
return NUMBER is
v_count number;
...

此外,您不需要declare.

于 2012-10-05T03:47:59.237 回答
0

尝试这个

CREATE OR REPLACE FUNCTION GET_COUNT
   RETURN NUMBER
IS
   V_COUNT   NUMBER;
BEGIN
   SELECT COUNT (*)
     INTO V_COUNT
     FROM GRADE;
   RETURN V_COUNT;
END;
于 2012-10-05T08:49:32.137 回答