CREATE OR REPLACE PROCEDURE V8_UPD_Roomtypeavailability is

  CURSOR yrat_cur  IS
     SELECT yrat.* FROM yrat WHERE yrat_date>=(select wgbs_datevalue from wgbs);
   yratr yrat_cur%ROWTYPE;  
  
begin
   FOR yratr IN yrat_cur
   LOOP
            INSERT INTO YRAV
                        (yrav.yrav_id, 
                        yrav.yrav_date, 
                        yrav.yrav_type,
                         yrav.yrav_value, 
                         yrav.yrav_maxvalue, 
                         yrav_yrch_id, 
                         yrav_yrpg_id, 
                         yrav_rateavailcat, 
                         yrav_ycat_id
                        )
                 VALUES (seq_yrav.NEXTVAL, 
                               yratr.yrat_date,  
                               1, 
                               0,
                                0, 
                                yratr.yrat_yrch_id, 
                                yratr.yrat_yrpg_id, 
                                yratr.yrat_rateavailcat, 
                                yratr.yrat_ycat_id
                        );
   END LOOP;

  Delete from yrat;
  
  COMMIT;
end;
/

CREATE OR REPLACE procedure V8_UPD_TableResCCMIntegration is 
  wussid number;
  wussflag number;  
begin   
  wussid := 0;
  begin 
    select wuss_id 
    into wussid 
    from wuss where wuss_name='TableReservationCCMIntegration'; 
  exception 
    when no_data_found then null;   
  end; 
   
  wussflag := 0;
  begin
    select count(1)
    into wussflag
    from rrst
    where nvl(rrst_yfsc_id, 0) > 0;
  exception 
    when no_data_found then null;   
  end;
  
  if wussflag > 0 then
    wussflag := 1;
  end if;
  
  if wussid=0 then 
    insert into wuss (wuss_id, wuss_xcms_id, wuss_name, wuss_value) values (seq_wuss.nextval, to_char(wussflag), 'TableReservationCCMIntegration', 0);
  else
    update wuss set wuss_value = to_char(wussflag) where wuss_id = wussid;  
  end if; 
end;
/
