计算gpa oracle pl sql

时间:2012-10-05 02:43:02

标签: sql oracle plsql

我是pl / sql中的noobie。我正在尝试使用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

2 个答案:

答案 0 :(得分:0)

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

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

此外,您不需要declare

答案 1 :(得分: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;
相关问题