17,377
社区成员
发帖
与我相关
我的任务
分享
create or replace function Get_specific_student_score
(V_Name varchar2,
V_Course varchar2)
return number
is
V_score student.Score%type;
begin
select score into V_score from student
where StudentName=V_name and Course=V_course;
return V_score;
exception
when no_data_found then
dbms_output.put_line('Please input the correct StudentName and Course');
end;
SQL> ed
已写入 file afiedt.buf
1 CREATE TABLE student(
2 studentname varchar2(8),
3 course VARCHAR2(50),
4 score NUMBER
5* )
SQL> /
表已创建。
SQL> ed
已写入 file afiedt.buf
1 INSERT INTO student VALUES
2* ('张三','语文',59)
SQL> /
已创建 1 行。
SQL> ed
已写入 file afiedt.buf
1 INSERT INTO student VALUES
2* ('张三','数学',95)
SQL> /
已创建 1 行。
SQL> select * from student;
STUDENTN COURSE SCORE
-------- -------------------------------------------------- ----------
张三 语文 59
张三 数学 95
SQL> ed
已写入 file afiedt.buf
1 Create or replace function Get_specific_student_score(V_Name varchar2,V_Co
rse varchar2)
2 return number
3 is
4 V_score student.Score%type;
5 begin
6 select score into V_score from student
7 where StudentName=V_name and Course=V_course;
8 return V_score;
9 exception
10 when no_data_found then
11 dbms_output.put_line('Please input the correct StudentName and
ourse!');
12* end;
SQL> /
函数已创建。
SQL> var s number;
SQL> exec :s:= Get_specific_student_score('张三','语文');
PL/SQL 过程已成功完成。
SQL> print s
S
----------
59
V_Name varchar2(8),V_Course varchar2(50)
修改为:
V_Name varchar2,V_Course varchar2
即去掉类型的精度