在过程PL / SQL中调用内部函数

时间:2015-09-24 16:00:07

标签: oracle plsql

有点PL / SQL函数,但试图添加一个函数,如果当前的人没有alt_id来通过应用程序获取相对alt_id。非常感谢提前。

CREATE OR REPLACE PROCEDURE CLIENT.p_Verification(pin_Member_ID   IN dbo.member.member_id%Type,
                                                                 pin_Person_ID   IN dbo.person.person_id%type,
                                                                 pin_user_id     IN NUMBER default null,
                                                                 pioc_ref_cursor IN OUT dbo.pkg_benefit_q.ref_cursor) IS

lv_member_id         dbo.person.alt_identifier%Type;
-- other variables
...
Procedure p_get_other_deductions(...
Begin
...
end;

这里的新功能

    FUNCTION f_get_alt_id 
         RETURN Varchar2 
         IS-- dbo.person.alt_identifier%Type IS
        alt_id Varchar2(10); --dbo.person.alt_identifier%Type;
    BEGIN        

      SELECT p.ALT_IDENTIFIER
        into alt_id
        FROM DBO.PERSON p , DBO.MEMBER m, DBO.APPLICATION a
      where p.PERSON_ID = m.PERSON_ID
        AND m.MEMBER_ID = a.MEMBER_ID
        AND a.APPLICATION_ID= cn_EntAppId
        ;

      RETURN alt_id;

    END;

在这里打电话......

  Select dbo.pkg_benefit_s.f_get_value_description('PREFIX',
                                                   p.prefix,
                                                   'Y',
                                                   'N') || case
           when p.prefix is not null then
            ' '
           else
            Null
         end || nvl2(p.first_name, initcap(p.first_name) || ' ', '') ||
         nvl2(p.middle_name, initcap(p.middle_name) || ' ', '') ||
         nvl2(p.last_name, initcap(p.last_name), '') || ' ' ||
         dbo.pkg_benefit_s.f_get_value_description('SUFFIX',
                                                   p.suffix,
                                                   'Y',
                                                   'N'),
         nvl2(p.alt_identifier, 
         f_get_alt_id, -- errors here
         ''), 
         nvl2(p.first_name, initcap(p.first_name), ''),
         nvl2(p.last_name, initcap(p.last_name), '')

    into lv_member_name,
         lv_member_id,
         lv_member_first_name,
         lv_member_last_name
    From dbo.person p
   where p.person_id = ln_person_id;
... more code 
END p_Verification;
/

2 个答案:

答案 0 :(得分:1)

最好通过多种方式练习创建一个程序包,使程序和函数列在标题和正文中。

CREATE OR REPLACE PACKAGE CLIENT IS
PROCEDURE p_Verification(pin_Member_ID   IN dbo.member.member_id%Type,
                         pin_Person_ID   IN dbo.person.person_id%type,
                         pin_user_id     IN NUMBER default null,
                         pioc_ref_cursor IN OUT dbo.pkg_benefit_q.ref_cursor);
Procedure p_get_other_deductions(...
FUNCTION f_get_alt_id(alt_id_in IN NUMBER:= NULL)  RETURN Varchar2;
END CLIENT;
CREATE OR REPLACE PACKAGE BODY CLIENT IS

END CLIENT;

注意我是如何添加一个null参数的,所以如果你需要重新设计这个函数,你可以这样做而不会使任何依赖对象失效。

答案 1 :(得分:0)

我加了 声明部分中的alt_id varchar(10)

恢复上面的选择查询,只需返回

     dbo.pkg_benefit_s.f_get_value_description('SUFFIX',
                                               p.suffix,
                                               'Y',
                                               'N'),
     p.alt_identifier,         
     nvl2(p.first_name, initcap(p.first_name), ''),
     nvl2(p.last_name, initcap(p.last_name), '')

into lv_member_name,
     lv_member_id,
     lv_member_first_name,
     lv_member_last_name

......其他一切都是一样的......直到

我添加了另一部分来设置lv_member_id

BEGIN

   Select p.alt_identifier
   into alt_id
   from dbo.person p
   where P.PERSON_ID = pin_Person_id;
   if alt_id is not null
   then
   lv_member_id := alt_id;
   else
   lv_member_id := f_get_alt_id;
   end if;   

   END;

...程序的其余部分结束; - 它现在编译