本帖最后由 WXHDSWH 于 2012-02-06 20:49:58 编辑

解决方案 »

  1.   

    上传截图方法: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即去掉类型的精度
      

  2.   

    第一:定义函数名称中的参数不需要带长度
    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;基础不牢
      

  3.   

    顶,另外推荐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
    张三     数学                                                       95SQL> 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
      

  4.   


    create or replace function Get_specific_student_score
    (V_Name varchar2,
    V_Course varchar2)return number 
    is 
    V_score student.Score%type;
    beginselect score into V_score from studentwhere StudentName=V_name and Course=V_course;return V_score;exceptionwhen no_data_found thendbms_output.put_line('Please input the correct StudentName and Course');end;