Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function getLastScLoadIdByCreationNumber(p_person_id in number, p_sc_creation_number in number) return number is
- v_poi_tin varchar2(50);
- v_real_employer_tin varchar2(50);
- v_vehicle_owner_id number(10);
- v_last_sc_load_id number(10);
- begin
- -- Get last so transaction : TIN + real_employer_tin + vehicle_owner
- begin
- select sot.poi_tin, p.real_employer_tin, vpc.vehicle_owner_id
- into v_poi_tin,v_real_employer_tin,v_vehicle_owner_id
- from social_office_transaction sot, person p, vo_person_category vpc
- where sot.person_id = p.person_id
- and p.person_id = p_person_id
- and sot.so_creation_number = p_sc_creation_number
- and vpc.vo_person_category_id = p.vo_person_category_id;
- exception when no_data_found then
- return null;
- end;
- if v_poi_tin is not null and v_real_employer_tin is not null and v_vehicle_owner_id is not null then
- -- Get last load with vo_id, and TIN
- begin
- select max(sc_load_id)
- into v_last_sc_load_id
- from sc_load
- where vehicle_owner_id = v_vehicle_owner_id
- and status = 'L'
- and poi_tin = v_poi_tin;
- exception when no_data_found then
- return null;
- end;
- if v_last_sc_load_id is not null then
- -- Within last load
- return v_last_sc_load_id;
- end if;
- end if;
- return null;
- end;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement