求教function 问题

WXHDSWH 2012-02-06 08:36:30

Create or replace function Get_specific_student_score(V_Name varchar2(8),V_Course varchar2(50))

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;

begin
exec Get_specific_student_score('张三','语文')
end
这个有问题吗,怎么就是出不来,说function 存在invalid
还有谁能教我把问题的截图传上来啊。。。十分感谢!
...全文
142 10 打赏 收藏 转发到动态 举报
写回复
用AI写文章
10 条回复
切换为时间正序
请发表友善的回复…
发表回复
singzero 2012-02-10
  • 打赏
  • 举报
回复
good
[Quote=引用 5 楼 liyongjie 的回复:]

第一:定义函数名称中的参数不需要带长度
Get_specific_student_score(V_Name varchar2(8),V_Course varchar2(50))
应该为:
Get_specific_student_score(V_Name varchar2,V_Course varchar2)

第二:
return number is V_score student……
[/Quote]
liyongjie 2012-02-10
  • 打赏
  • 举报
回复
第一:定义函数名称中的参数不需要带长度
Get_specific_student_score(V_Name varchar2(8),V_Course varchar2(50))
应该为:
Get_specific_student_score(V_Name varchar2,V_Course varchar2)

第二:
return number is V_score student.Score%type
这一句后面应该有个分号(;)
应该为:
return number is V_score student.Score%type;

基础不牢
merrill 2012-02-10
  • 打赏
  • 举报
回复
你异常捕获的时候 也要给个返回值
oO寒枫Oo 2012-02-10
  • 打赏
  • 举报
回复

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;
geniuswjt 2012-02-10
  • 打赏
  • 举报
回复
mingchaoyan 2012-02-10
  • 打赏
  • 举报
回复
[Quote=引用 5 楼 liyongjie 的回复:]

第一:定义函数名称中的参数不需要带长度
Get_specific_student_score(V_Name varchar2(8),V_Course varchar2(50))
应该为:
Get_specific_student_score(V_Name varchar2,V_Course varchar2)

第二:
return number is V_score student……
[/Quote]
顶,另外推荐dbms_output.put_line()中用单引号
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


我心飞翔 2012-02-07
  • 打赏
  • 举报
回复
上传截图方法:http://topic.csdn.net/u/20090623/15/83fd893b-1ca1-42aa-932f-d7abb284a55e.html


V_Name varchar2(8),V_Course varchar2(50)

修改为:

V_Name varchar2,V_Course varchar2

即去掉类型的精度


kingtiy 2012-02-06
  • 打赏
  • 举报
回复
重新编译下这个函数
WXHDSWH 2012-02-06
  • 打赏
  • 举报
回复
WXHDSWH 2012-02-06
  • 打赏
  • 举报
回复

17,377

社区成员

发帖
与我相关
我的任务
社区描述
Oracle 基础和管理
社区管理员
  • 基础和管理社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧