Advertisement
psi_mmobile

Untitled

Mar 28th, 2023
1,509
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PL/SQL 1.85 KB | None | 0 0
  1. DECLARE
  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. SELECT sot.poi_tin, p.real_employer_tin, vpc.vehicle_owner_id
  9. INTO v_poi_tin,v_real_employer_tin,v_vehicle_owner_id
  10. FROM social_office_transaction sot, person p, vo_person_category vpc
  11. WHERE p.person_id = :person_id
  12. AND vpc.vo_person_category_id = p.vo_person_category_id
  13. AND sot.social_office_transaction_id = p.last_so_transaction_id;
  14.  
  15. IF v_poi_tin != NULL AND v_real_employer_tin != NULL AND v_vehicle_owner_id != NULL THEN
  16.  
  17.     -- Get last load with vo_id, and TIN
  18.     SELECT MAX(sc_load_id)
  19.     INTO v_last_sc_load_id
  20.     FROM sc_load
  21.     WHERE vehicle_owner_id = v_vehicle_owner_id
  22.     AND status = 'L'
  23.     AND poi_tin = v_poi_tin;
  24.     IF v_last_sc_load_id != NULL THEN
  25.    
  26.     -- Within last load, get sc chain
  27.         SELECT t1.sc_load_data_id,      
  28.                t1.company_name,
  29.                t1.company_tin,
  30.                t1.parent_sc_load_data_id,
  31.                DECODE (t2.children_count, NULL, 0, t2.children_count) AS children_count
  32.                FROM
  33.         (SELECT sld.sc_load_data_id,      
  34.                sld.company_name,
  35.                sld.company_tin,
  36.                sld.parent_sc_load_data_id
  37.           FROM sc_load_data sld
  38.          START WITH sld.parent_sc_load_data_id IS NULL
  39.         CONNECT BY sld.parent_sc_load_data_id = PRIOR sld.sc_load_data_id
  40.          ORDER SIBLINGS BY sld.company_name) t1,
  41.          (SELECT parent_sc_load_data_id, COUNT (parent_sc_load_data_id) AS children_count FROM sc_load_data
  42.          GROUP BY parent_sc_load_data_id) t2
  43.          WHERE t1.sc_load_data_id = t2.parent_sc_load_data_id (+)
  44.          AND t1.sc_load_id = v_last_sc_load_id;
  45.     endif;
  46. endif;
  47.  
  48. END;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement