2014-11-10 1 views
0

가능한지 확신 할 수 없지만이 프로 시저를 뷰로 변환 할 수 있는지 확인하려고합니다. 절차가 실행됩니다.프로 시저를 Oracle에서 뷰로 변경

다른 사람의 코드를 이해하려고하고 커서 때문에이 절차를보기로 변경할 수 있는지 확신 할 수 없습니다.

---------------------------------------------------------------------- 
--This Procedure will interface drive information on a nightly basis-- 
---------------------------------------------------------------------- 
Procedure HEMA_DRIVE_AUTO IS 

v_start_date    DATE  := trunc(sysdate) -30;  
v_end_date     DATE  := trunc(sysdate);   
v_delete_stats_dt   DATE  := trunc(sysdate)-120; 

v_total_registration_count NUMBER; 
v_total_performed_count NUMBER; 
v_total_collected_count NUMBER; 
v_total_deferred_count  NUMBER; 
v_total_qns_count   NUMBER; 
v_existing_drive   NUMBER; 
v_existing_performed  NUMBER; 
v_maph_drive    NUMBER; 

--This Cursor will collect the initial data 
cursor c_drive_info is 
    select dr.drive_id, dr.Start_time, dr.vehicle_id 
    from drives dr 
    --where dr.drive_id in(1605606); 
    where trunc(dr.start_time) between v_start_date and v_end_date; 

--This Cursor will be used to decode the Donation Types 
cursor c_procedure_codes is 
    select * from hema_donation_type_map hdt 
    where hdt.mobiles = 1 order by procedure_code_id; 

--This Cursor will define the intentions but exclude theraputics inthe mapping 
cursor c_intention is 
    select rsa_motivation_id,hema_intent_id from hema_intent_map 
    where rsa_motivation_id <> 4 order by rsa_motivation_id; 

    BEGIN 
-- delete records older then 4 months 
delete from hema_nightly h where trunc(h.drive_date) < v_delete_stats_dt; 
commit; 

FOR cur_drive IN c_drive_info LOOP 

delete from hema_nightly where drive_id = cur_drive.drive_id; 
commit; 

-- Loop by motivation/intention 
FOR cur_intent in c_intention LOOP 

    -- Loop to get the procedure code data 
    FOR cur_proc_code IN c_procedure_codes LOOP 

    v_total_registration_count := 0; 
    v_total_performed_count := 0; 
    v_total_collected_count := 0; 
    v_total_deferred_count  := 0; 
    v_total_qns_count   := 0; 
    v_maph_drive    := 0; 


     -- get the count for all other procedures 
     select count(1) 
     into v_total_registration_count 
     from registration r 
     where r.drive_id = cur_drive.drive_id 
     and r.donation_type_id = cur_proc_code.donation_type_id 
     and r.motivation_id = cur_intent.rsa_motivation_id; 

     --get the deferral count 
     select count(unique(r.registration_id)) 
     into v_total_deferred_count 
     from registration r 
     where r.drive_id = cur_drive.drive_id 
     and r.donation_type_id = cur_proc_code.donation_type_id 
     and r.motivation_id = cur_intent.rsa_motivation_id 
     and r.step_completed < 12 
     and exists (select rsc.registration_id 
       from reg_steps_completed rsc 
       where rsc.registration_id = r.registration_id 
       and rsc.collection_step_id = 99); 

     -- QNS count 
     select count(unique(r.registration_id)) 
     into v_total_qns_count 
     from registration r 
     where r.drive_id = cur_drive.drive_id 
     and r.step_completed < 12 
     and not exists (select rsc.registration_id 
       from reg_steps_completed rsc 
       where rsc.registration_id = r.registration_id 
       and rsc.collection_step_id = 99) 
     and r.donation_type_id = cur_proc_code.donation_type_id 
     and r.motivation_id = cur_intent.rsa_motivation_id; 

    -- performed count is the difference between total registrations and total deferrals. 
    v_total_performed_count := v_total_registration_count - 
           (v_total_deferred_count + 
           v_total_qns_count); 

    -- not calulatind yield so keep count the same 
    v_total_collected_count := v_total_performed_count; 

    -- does this drive exist 
    select count(drive_id) 
     into v_existing_drive 
     from hema_nightly 
    where drive_id = cur_drive.drive_id 
     and procedure_id = cur_proc_code.procedure_code_id 
     and intent = cur_intent.hema_intent_id; 

    -- Is this an aph vehicle? 
    select count(vehicle_id) 
     into v_maph_drive 
     from vehicles 
     where veh_drive_type_uid = 2 
     and vehicle_id = cur_drive.vehicle_id; 

    if v_existing_drive > 0 then 

     update hema_nightly 
      set performed = performed + v_total_performed_count, 
       collected = collected + v_total_collected_count, 
       registered = registered + v_total_registration_count, 
       deferrals = deferrals + v_total_deferred_count, 
       qns  = qns  + v_total_qns_count, 
       drive_date = cur_drive.start_time, 
       mod_date = sysdate, 
       intent  = cur_intent.hema_intent_id, 
       aph  = v_maph_drive 
     where drive_id = cur_drive.drive_id 
      and procedure_id = cur_proc_code.procedure_code_id 
      and intent = cur_intent.hema_intent_id; 
     commit; 

    elsif v_existing_drive = 0 and v_total_registration_count > 0 then 
     insert into hema_nightly 
     (drive_id, 
     procedure_id, 
     performed, 
     collected, 
     registered, 
     deferrals, 
     qns, 
     drive_date, 
     mod_date, 
     intent, 
     aph) 
     values 
     (cur_drive.drive_id, 
     cur_proc_code.procedure_code_id, 
     v_total_performed_count, 
     v_total_collected_count, 
     v_total_registration_count, 
     v_total_deferred_count, 
     v_total_qns_count, 
     trunc(cur_drive.start_time), 
     sysdate, 
     cur_intent.hema_intent_id, 
     v_maph_drive); 
     commit; 
    end if; 

    v_existing_drive := 0; 

    end loop; 
end loop; 
end loop; 

end hema_drive_auto; 
+0

짧은 대답, 아니요. – OldProgrammer

답변

0

조회수가 DML을 수행하지 않는 (삽입, 업데이트, 삭제) 그들이 COMMIT 및 ROLLBACK와의 거래를 관리하지 않는; 그들은 단지 데이터를 선택하고 검색합니다.

관련 문제