GeekInterview.com
  I am new, Sign me up!
 
GeekInterview.com  >  Interview Questions  >  Oracle  >  PL/SQL
Go To First  |  Previous Question  |  Next Question 
 PL/SQL  |  Question 239 of 241    Print  
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?



  
Total Answers and Comments: 4 Last Update: April 17, 2009     Asked by: harit79 
  
 Sponsored Links

 
 Best Rated Answer
Submitted by: ananth.oracle
 
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



Above answer was rated as good by the following members:
orasuman9, samareshp
March 09, 2009 15:33:08   #1  
ananth.oracle Member Since: March 2009   Contribution: 3    

RE: Package Function
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


 
Is this answer useful? Yes | NoAnswer is useful 2   Answer is not useful 0Overall Rating: +2    
March 18, 2009 05:17:17   #2  
msenthil19 Member Since: March 2009   Contribution: 3    

RE: Package Function

Yes You can call the function from another package as below:

Pakagename.funciton name


 
Is this answer useful? Yes | NoAnswer is useful 1   Answer is not useful 0Overall Rating: +1    
March 19, 2009 00:36:43   #3  
Mohamed Harish Member Since: September 2008   Contribution: 2    

RE: Package Function
You can call the function in another package like:

Package_name.function_name();

In your case:

variable1 : A.XYZ();

 
Is this answer useful? Yes | No
April 17, 2009 15:29:16   #4  
OraclePassport Member Since: April 2009   Contribution: 2    

RE: Package Function
Call the package.procedure (A.XYZ) in the other procedure. This is not possible if XYZ is a private procedure.
 
Is this answer useful? Yes | No


 
Go To Top


 Sponsored Links

 
About Us -  Privacy Policy -  Terms and Conditions -  Contact -  Ask Question -  Propose Category -  Site Updates 

Copyright © 2005 - 2009 GeekInterview.com. All Rights Reserved

Page copy protected against web site content infringement by Copyscape