计算oracle pl sql的gpa
我是pl/sql的高手。我正在尝试使用pl sql计算gpa。我已经创建了一个表,其中包含带有值的分数计算oracle pl sql的gpa,sql,oracle,plsql,Sql,Oracle,Plsql,我是pl/sql的高手。我正在尝试使用pl sql计算gpa。我已经创建了一个表,其中包含带有值的分数 SSN CNO GRADE --------------- -------- ---------- 55555 cs101 1 55555 math101 4 55555 bio101 1 55555 cg
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
您的函数缺少返回数据类型,例如:
create or replace function get_count
return NUMBER is
v_count number;
...
另外,您不需要声明。试试这个
CREATE OR REPLACE FUNCTION GET_COUNT
RETURN NUMBER
IS
V_COUNT NUMBER;
BEGIN
SELECT COUNT (*)
INTO V_COUNT
FROM GRADE;
RETURN V_COUNT;
END;
它应该是返回v_计数;而不是返回等级;快速提问。我何时知道何时使用declare?是否在过程中?如果块需要任何局部声明(例如变量),则DECLARE用于在PL/SQL中启动匿名块。过程、函数或包不需要它,因为声明部分是在开始之前隐含的。