调用程序包时如何通过内部三个函数使程序包成功显示两个错误

时间:2019-05-01 14:07:16

标签: sql oracle

这是完整的代码。请帮助我解决错误并成功编译

CREATE OR REPLACE PACKAGE UPDATE_PASS AS
    FUNCTION updatePasswordStudent(
    CurrentP VARCHAR2,
    NewPwd VARCHAR2,
    StudentId NUMBER
    )

  RETURN number
is
    getCount number :=0;  //this line have error


        BEGIN
            Select count(*) into GetCount from users where student_id=StudentId and Password=md5(CurrentP);
            if GetCount = 1
            then 
            update users set Password=md5(NewPwd) where student_id=StudentId and Password=md5(CurrentP);
          insert into users_log(Passwords,student_id,updated_by,action) values(md5(CurrentP),StudentId,StudentId,'Change');
            else
            GetCount := 0;
            end if;
        RETURN GetCount;
        END updatePasswordStudent;

//this line causes an error
    FUNCTION updatePasswordNazim(
    CurrentP VARCHAR2,
    NewPwd VARCHAR2,
    NazimId number)
    RETURN number
        IS
            GetCount number :=0;

          BEGIN
            Select count(*) into GetCount from nazim_login where nazim_id=NazimId and Password=md5(CurrentP);
            if GetCount = 1
            then 
            update nazim_login set Password=md5(NewPwd) where nazim_id=NazimId and Password=md5(CurrentP);
          insert into nazim_password_log(Passwords,nazim_id,updated_by,action) values(md5(CurrentP),NazimId,NazimId,'Change');
            else
            GetCount := 0;
            end if;
        RETURN GetCount;
        END updatePasswordNazim;

    FUNCTION updatePasswordTeacher(
    CurrentP VARCHAR2,
    NewPwd VARCHAR2,
    TeacherId number)
    RETURN number
        IS
            GetCount number :=0;

          BEGIN
            Select count(*) into GetCount from teacher_login where teacher_id=TeacherId and Password=md5(CurrentP);
            if GetCount = 1
            then 
            update teacher_login set Password=md5(NewPwd) where teacher_id=TeacherId and Password=md5(CurrentP);
          insert into teacher_password_log(Passwords,teacher_id,updated_by,action) values(md5(CurrentP),TeacherId,TeacherId,'Change');
            else
            GetCount := 0;
            end if;
        RETURN GetCount;
        END updatePasswordTeacher;
    END UPDATE_PASS;

我尝试了多个过程,但错误仍然相同

CREATE OR REPLACE PACKAGE UPDATE_PASS AS
    FUNCTION updatePasswordStudent(
    CurrentP VARCHAR2,
    NewPwd VARCHAR2,
    StudentId NUMBER
    )

  RETURN number
is
    getCount number :=0;  //this line have error


        BEGIN
            Select count(*) into GetCount from users where student_id=StudentId and Password=md5(CurrentP);
            if GetCount = 1
            then 
            update users set Password=md5(NewPwd) where student_id=StudentId and Password=md5(CurrentP);
          insert into users_log(Passwords,student_id,updated_by,action) values(md5(CurrentP),StudentId,StudentId,'Change');
            else
            GetCount := 0;
            end if;
        RETURN GetCount;
        END updatePasswordStudent;

//this line causes an error
    FUNCTION updatePasswordNazim(
    CurrentP VARCHAR2,
    NewPwd VARCHAR2,
    NazimId number)
    RETURN number
        IS
            GetCount number :=0;

          BEGIN
            Select count(*) into GetCount from nazim_login where nazim_id=NazimId and Password=md5(CurrentP);
            if GetCount = 1
            then 
            update nazim_login set Password=md5(NewPwd) where nazim_id=NazimId and Password=md5(CurrentP);
          insert into nazim_password_log(Passwords,nazim_id,updated_by,action) values(md5(CurrentP),NazimId,NazimId,'Change');
            else
            GetCount := 0;
            end if;
        RETURN GetCount;
        END updatePasswordNazim;

我希望程序包成功编译

Error Image

1 个答案:

答案 0 :(得分:1)

包装包括两部分:包装规格和包装主体。 您正在尝试将两者结合起来。

尝试这样的事情:

create or replace package update_pass
is
  function updatepasswordstudent
       ( currentp  varchar2
       , newpwd    varchar2
       , studentid number
       )
  return number;
end update_pass;
/

create or replace package body update_pass
as
  function updatepasswordstudent
       ( currentp  varchar2
       , newpwd    varchar2
       , studentid number
       )
  return number
  is
    getcount number := 0;
  begin
    -- logic goes here
    return getcount;
  end updatepasswordstudent;
end update_pass;
/