halona 0 Newbie Poster

hi,

I have objects called Customer_obj , phonecall_obj ,
then I have tables of these objects where there is a reference to the customer table inside the phonecall_obj table.

I try to pass the customer object in a stored function to search in the phonecall tables about that specific customer then to get the cost of his calls.

I couldn't know how to implement this, where every time it's give me an error that I entered a customer object where it is expected to get a reference to customer object..

any one can help !! I will appreciate it.

thank u

this is my code:

CREATE OR REPLACE TYPE Customer_obj AS OBJECT 
(
  id            NUMBER,
  fname         VARCHAR2(30),
  lname         varchar2(30),
  DOB           date,
  careacode     number,
  ctelenum      number,
  map MEMBER FUNCTION get_age  RETURN number
) ;


/
CREATE OR REPLACE TYPE phonecall_obj AS OBJECT
 (
  callnum            NUMBER,
  customer_ref       REF Customer_obj,
  areacode           number,
  telephonenum       NUMBER,
  startt             date,
  etime              date,
  ccost              number,
  
  map MEMBER FUNCTION get_duration  RETURN number 
  
  );
  


/ 



CREATE TABLE Customer_obj_table OF Customer_obj (id PRIMARY KEY) 
   OBJECT IDENTIFIER IS PRIMARY KEY ;   



CREATE TABLE phonecall_obj_table OF phonecall_obj 
   (PRIMARY KEY (callnum),
   FOREIGN KEY (customer_ref) REFERENCES Customer_obj_table,
   CONSTRAINT check_area_code 
   CHECK (areacode in (01,02,075,077,078,079,0800,0845,0870,08442,08449,08712,08719,090,091,098)))
   OBJECT IDENTIFIER IS PRIMARY KEY 
  
  ;

and this is my function code

create or replace
function calls_cost_in_range_of_dates2 (customer Customer_obj , sd date , ed date) return number is
  
  call_cost number;
  
begin

 SELECT SUM(p.ccost) INTO call_cost
  FROM phonecall_obj_table p where p.customer_ref = customer  and p.startt >= sd and p.etime <=ed;
return call_cost;
end;