Package Function

You have a package called A and one function in that packgae called XYZ.
If you need to call that function in second packaged B, How will you call?

Questions by harit79   answers by harit79

Showing Answers 1 - 8 of 8 Answers

Yes, we can call a packaged function in another package.

Example
CREATE OR REPLACE package VISION_SURGERY.test_a isfunction call_func(enter_date date) return varchar2;

end;
/


CREATE OR REPLACE package body VISION_SURGERY.test_a is
function call_func(enter_date in date) return varchar2 is
v_date
varchar2(100);


begin
v_date:=to_char(enter_date,'Ddspth-Month-Year');
return
v_date;
end;
end;
/
Package A is created

create or replace package test_b isprocedure
call_func_a;
end;
/

create or replace package body test_b is
procedure call_func_a is

v_date date;
v_date_mod varchar2(100);

begin

v_date := to_date('10/03/2009','dd/mm/yyyy');
v_date_mod:=test_a.call_func(v_date);

dbms_output.put_line('Date before modificaion is : '|| v_date);
dbms_output.put_line
('Date after modificaion is : '|| v_date_mod);

end;
end;
/

Now execute the packaged procedure by
exec test_b.CALL_FUNC_A

abey238

  • Jan 19th, 2010
 

To access a function or a procedure that is defined in package 1 from a procedure defined in package 2, just ensure that the package 1's specification has those functions/procedure definitions defined.

Function/Procedures that are defined in a packages's specification have a public access.

To access a procedure 
Package.Procedure_name(a,b,c);

To access a function
a := Package.function_name(a,b,c);

shekhar2010

  • Aug 30th, 2010
 

Yes we can call a function which is there in a Package 'A' from Package 'B'. And it is very simple as stated below

Package_Name.Function_Name(Parameter_List);

  Was this answer useful?  Yes

1) VarName := PackageName.FunctionName(<Parameter List>).
2) Select PackageName.FunctionName(<Parameter List>) From <TableName?
     You cannot run this statement if your function is performing DML or DDL operation.

Note: The function defined in a packaged must have public access. I mean that must be declared in a package specification and must be defined in a package body.




  Was this answer useful?  Yes

Give your answer:

If you think the above answer is not correct, Please select a reason and add your answer below.

 

Related Answered Questions

 

Related Open Questions