Oracle - 获取游标中的函数参数值



>我有一个包,我在其中创建了一个这样的函数

create or replace package pk_server_control
is
function fn_get_employees_by_consultant(consultant_id number) return number;
end;
-----------------------------------------------------------------
create or replace package body pk_server_control
is
 **function fn_get_employees_by_consultant(consultant_id number)
 return number
 is
  cursor employees is select c.CST_NAME, a.NO_OF_EMPLOYEES from NISHAN_LDS_ACCOUNT a join NISHAN_LDS_CONSULTANT c
                      on c.CONSULTANT_ID = a.FK1_CONSULTANT_ID where c.CONSULTANT_ID =consultant_id ;
 total number := 0; **
 begin
   for data in employees
   loop
    total := total + data.NO_OF_EMPLOYEES;
   end loop;
   return total;
 end;
end;

begin
dbms_output.put_line(pk_server_control.fn_get_employees_by_consultant(1));
end;

我需要从函数"fn_get_employees_by_consultant"的参数"consultant_id数字"中获取值到光标"的"consultant_id"。运行时,它不会给出错误,也不会传递值。请帮助我度过这个:)

试试这个

create or replace package pk_server_control
is
 function fn_get_employees_by_consultant(consultant_id number) return number;
end;
-----------------------------------------------------------------
create or replace package body pk_server_control
is
  function fn_get_employees_by_consultant(consultant_id number)
  return number
  is
   val number := consultant_id;
   cursor employees is select c.CST_NAME, a.NO_OF_EMPLOYEES from NISHAN_LDS_ACCOUNT a join NISHAN_LDS_CONSULTANT c
                       on c.CONSULTANT_ID = a.FK1_CONSULTANT_ID where c.CONSULTANT_ID =val;
  total number := 0;
  begin
    for data in employees 
    loop
     total := total + data.NO_OF_EMPLOYEES;
    end loop;
    return total;
  end;
end;

begin
 dbms_output.put_line(pk_server_control.fn_get_employees_by_consultant(3));
end;

最新更新