Advertisement
psi_mmobile

Untitled

Feb 27th, 2025
67
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.46 KB | None | 0 0
  1. function getLastScLoadIdByCreationNumber(p_person_id in number, p_sc_creation_number in number) return number is
  2. v_poi_tin varchar2(50);
  3. v_real_employer_tin varchar2(50);
  4. v_vehicle_owner_id number(10);
  5. v_last_sc_load_id number(10);
  6. begin
  7. -- Get last so transaction : TIN + real_employer_tin + vehicle_owner
  8. begin
  9. select sot.poi_tin, p.real_employer_tin, vpc.vehicle_owner_id
  10. into v_poi_tin,v_real_employer_tin,v_vehicle_owner_id
  11. from social_office_transaction sot, person p, vo_person_category vpc
  12. where sot.person_id = p.person_id
  13. and p.person_id = p_person_id
  14. and sot.so_creation_number = p_sc_creation_number
  15. and vpc.vo_person_category_id = p.vo_person_category_id;
  16. exception when no_data_found then
  17. return null;
  18. end;
  19. if v_poi_tin is not null and v_real_employer_tin is not null and v_vehicle_owner_id is not null then
  20.  
  21. -- Get last load with vo_id, and TIN
  22. begin
  23. select max(sc_load_id)
  24. into v_last_sc_load_id
  25. from sc_load
  26. where vehicle_owner_id = v_vehicle_owner_id
  27. and status = 'L'
  28. and poi_tin = v_poi_tin;
  29. exception when no_data_found then
  30. return null;
  31.  
  32. end;
  33. if v_last_sc_load_id is not null then
  34.  
  35. -- Within last load
  36. return v_last_sc_load_id;
  37.  
  38. end if;
  39. end if;
  40. return null;
  41. end;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement