Question : error in code

Can please anyone tell me what's wrong with this code?

Basically this piece of code is trying to insert a new row in a table but before it can insert it  should perform a check on primary keys(& raise the appropriate exception)in order to prevent user from entering duplicate key.  

It also has to call another method from another table to check if the expenditure attribute which should nothave exceeded 300000.

create or replace type body Wet_Ride_objtyp
as
MEMBER PROCEDURE Insert_Wet_Ride(
    p_attraction_id NUMBER,
    p_Attraction_Name VARCHAR2,
    p_cost NUMBER,
    p_year_open number,
    p_height VARCHAR2,
    p_capacity NUMBER,
    p_Category varchar2 ,
    p_name varchar2,
    p_year number,
    p_wetfactor number,
    p_durations varchar2)
is
v_expenditure number;
Too_expensive exception;
budget_limit_reached exception;
e_invalid_year exception;

begin

   updateExpenditure() -- method from another table See code for this methods below

   if p_current_expenditure >= 300000
   then raise budget_limit_reached; -- after executing the methods above if expenditure exceeds 300000 then raise error

   else
   select current_expenditure
   into v_expenditure
   from Budget_objtab
   where year = p_year;
   end if;

  IF SQL%NOTFOUND THEN
  Raise e_invalid_year;
else

  SELECT COUNT(*)
  INTO v_count
  FROM Attraction_objtab;
 
  FOR i IN 1..v_count
   LOOP
  if attraction_id = p_attraction_id
  then raise Dup_on_val_index; -----------retrieve all existing record and check for duplicate key
  else if p_cost >=100000 then
  raise Too_expensive;
else
insert into Attraction_objtab values
    (p_attraction_id,
    p_Attraction_Name,
    p_cost,
    p_dateopen,
    p_height,
    p_capacity,
    p_Category,
    p_name,
    p_year,
    p_wetfactor,
    p_durations);
    end if;
   
  If v_expenditure + p_cost >=300000 then
  raise budget_limit_reached;
  end if;
end if;
end loop;
  rollback;

  Exception
 when e_invalid_year then
 DBMS_output.Put_line('please enter a valid year');
 When
 Too_expensive then
 DBMS_output.put_line('');
 
 When
 budget_limit_reached then
 DBMS_output.Put_line('Cannot afford Attraction, budget limit reached');
 
 When
 Dup_val_on_index then
 DBMS_output.Put_line('Cannot afford Attraction, budget limit');
 When others then
DBMS_output.Put_line('Cannot afford Attraction, budget limit ');
end Insert_Wet_Ride;
end;
/
show errors

LINE/COL  ERROR  
24/12  PLS-00103: Encountered the symbol "NUMBER" when expecting one of the following: . ( ) , * @ % & | = - + < / > at in is mod not range rem => .. <> or != or ~= >= <= <> an d or like as between from using ||  
25/1  PLS-00103: Encountered the symbol ")" when expecting one of the following: , from into bulk  


The method called above belongs to this object

create or replace type body Budget_objtyp
as
member function UpdateExpenditure(
      p_Year number,
      p_value number,
      p_current_expenditure number
)return number ---------------------------------------method used above
is
v_value number;
v_current_expenditure number;
begin
SELECT  Value, current_expenditure
   INTO v_value, v_current_expenditure
   FROM budget_objtab
   WHERE  year = p_year;
    v_value:=p_value;
    v_current_expenditure:=p_current_expenditure;
 return (p_value - p_current_expenditure);
end UpdateExpenditure;

member function CalcRemaining(
      p_Year number,
      p_value number,
      p_current_expenditure number)
return number  
is
v_value number;
v_current_expenditure number;
begin
SELECT  Value, current_expenditure
   INTO v_value, v_current_expenditure
   FROM budget_objtab
   WHERE  year = p_year;
    v_value:=p_value;
    v_current_expenditure:=p_current_expenditure;
 return (p_value - p_current_expenditure);
end CalcRemaining;
end;
/
show errors

can anyone please tell me what's wrong with the code.
Thanks

cassiusduke



Answer : error in code

..."before it can insert it  should perform a check on primary keys(& raise the appropriate exception)in order to prevent user from entering duplicate key.  "
Do you have a Primary Key in place? If you don't, do it and you don't need to check it yourself. The database will handle this for you.

create or replace type wetride_ot
as object
(name varchar2(25)
,cost number
)
/
create table t of wetride_ot
/
alter table t add constraint wrpk primary key (name)
/
insert into t
values (wetride_ot ('Scary',10) )
/
/
insert into t
*
ERROR at line 1:
ORA-00001: unique constraint (SA.WRPK) violated

Alex
Random Solutions  
 
programming4us programming4us