本人初学。所以还请大家帮忙解答下,谢谢了
自定义一个函数实现以下功能。对于一个输入的学号(XH)值,查询该值在XS表中是否存在,若存在返回0,否则返回-1。写出程序段调用上面的函数。当向xs_kc表录入成绩时,首先调用该函数检查欲录入的同学是否存在。若存在,则录入成绩,否则不能录入。

解决方案 »

  1.   

    create or replace function checkStudentNumber
    (
      v_studenNUM    in  number
    ) return number
    is  i_count   number;
      i_stNum   number;
     
    begin  i_stNum := v_studenNUM;  if i_stNum  is null   then
        return -1;
      end if;
     
      select t.XH into i_stNum  from XS t where t.XH =  i_stNum ;  if (i_stNum = 1) then
        return 0;
      else
        return -1;
      end if;   end;
      

  2.   


    create or replace function isexists
    (
        istuid        varchar2
    )
    return number
    as
        i_count       number;
        i_return      number;
    begin
        i_return := -1;
        select count(*) into i_count from tabname where stuid = istuid;
        if (i_count > 0) then
            i_return := 0;
        end if;    return i_return;exception
        when others then
            return i_return;
    end isexists;
      

  3.   


    那这个呢?求解答.....(下面的)写出程序段调用上面的函数。当向xs_kc表录入成绩时,首先调用该函数检查欲录入的同学是否存在。若存在,则录入成绩,否则不能录入。
      

  4.   


    declare
        student_id   varchar2(10);
    begin
        student_id := '001';
        if (isexists(student_id ) = 0) then
            insert into table(stuid) values(student_id);
        end if;
        commit;
    end;
    /
      

  5.   

    insert into T1(student_id, score) select v_stuid, v_score from dual where not exists (select 1 from T1 where student_id=v_stuid)