Advertisement
Guest User

transform

a guest
Dec 6th, 2019
140
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 23.76 KB | None | 0 0
  1. //Acho que aqui não alterá-mos nada
  2.  
  3.  
  4.  
  5. create or replace PACKAGE BODY pck_transform IS
  6.  
  7. e_transformation EXCEPTION;
  8.  
  9. -- *********************************************
  10. -- * PUTS AN ERROR IN THE FACT TABLE OF ERRORS *
  11. -- *********************************************
  12. PROCEDURE error_log(p_screen_name t_tel_screen.screen_name%TYPE,
  13. p_hora_deteccao DATE,
  14. p_source_key t_tel_source.source_key%TYPE,
  15. p_iteration_key t_tel_iteration.iteration_key%TYPE,
  16. p_record_id t_tel_error.record_id%TYPE) IS
  17. v_date_key t_tel_date.date_key%TYPE;
  18. v_screen_key t_tel_screen.screen_key%TYPE;
  19. BEGIN
  20. -- obtém o id da dimensão «date» referente ao dia em que o erro foi detectado
  21. BEGIN
  22. SELECT date_key
  23. INTO v_date_key
  24. FROM t_tel_date
  25. WHERE date_full=TO_CHAR(p_hora_deteccao,'DD-MM-YYYY');
  26. EXCEPTION
  27. WHEN NO_DATA_FOUND THEN
  28. pck_log.write_log(' -- ERROR -- could not find date key from "t_tel_date" ['||sqlerrm||']');
  29. RAISE e_transformation;
  30. END;
  31.  
  32. BEGIN
  33. SELECT screen_key
  34. INTO v_screen_key
  35. FROM t_tel_screen
  36. WHERE UPPER(screen_name)=UPPER(p_screen_name);
  37. EXCEPTION
  38. WHEN NO_DATA_FOUND THEN
  39. pck_log.write_log(' -- ERROR -- could not find screen key from "t_tel_screen" ['||sqlerrm||']');
  40. RAISE e_transformation;
  41. END;
  42.  
  43. INSERT INTO t_tel_error (date_key,screen_key,source_key,iteration_key, record_id) VALUES (v_date_key,v_screen_key,p_source_key,p_iteration_key, p_record_id);
  44. EXCEPTION
  45. WHEN OTHERS THEN
  46. pck_log.write_log(' -- ERROR -- could not write quality problem to "t_tel_error" fact table ['||sqlerrm||']');
  47. RAISE e_transformation;
  48. END;
  49.  
  50.  
  51.  
  52. -- *******************************************
  53. -- * DUPLICATES THE LAST SCHEDULED ITERATION *
  54. -- *******************************************
  55. PROCEDURE duplicate_last_iteration(p_start_date t_tel_iteration.iteration_start_date%TYPE) IS
  56. v_last_iteration_key t_tel_iteration.iteration_key%TYPE;
  57. v_new_iteration_key t_tel_iteration.iteration_key%TYPE;
  58.  
  59. CURSOR c_scheduled_screens(p_iteration_key t_tel_iteration.iteration_key%TYPE) IS
  60. SELECT s.screen_key as screen_key,screen_name,screen_order, s.source_key
  61. FROM t_tel_schedule s, t_tel_screen
  62. WHERE iteration_key=p_iteration_key AND
  63. s.screen_key = t_tel_screen.screen_key;
  64. BEGIN
  65. pck_log.write_log(' Creating new iteration by duplicating the previous one');
  66.  
  67. -- FIND THE LAST ITERATIONS'S KEY
  68. BEGIN
  69. SELECT MAX(iteration_key)
  70. INTO v_last_iteration_key
  71. FROM t_tel_iteration;
  72. EXCEPTION
  73. WHEN NO_DATA_FOUND THEN
  74. pck_log.write_log(' -- ERROR -- could not find iteration key ['||sqlerrm||']');
  75. RAISE e_transformation;
  76. END;
  77.  
  78. INSERT INTO t_tel_iteration(iteration_start_date) VALUES (p_start_date) RETURNING iteration_key INTO v_new_iteration_key;
  79. FOR rec IN c_scheduled_screens(v_last_iteration_key) LOOP
  80. -- schedule screen
  81. INSERT INTO t_tel_schedule(screen_key,iteration_key,source_key,screen_order)
  82. VALUES (rec.screen_key,v_new_iteration_key,rec.source_key,rec.screen_order);
  83. END LOOP;
  84. pck_log.write_log(' Done!');
  85. EXCEPTION
  86. WHEN NO_DATA_FOUND THEN
  87. pck_log.write_log(' -- ERROR -- previous iteration has no screens to reschedule');
  88. RAISE e_transformation;
  89. WHEN OTHERS THEN
  90. pck_log.write_uncomplete_task_msg;
  91. RAISE e_transformation;
  92. END;
  93.  
  94.  
  95. -- *************************************************************************************
  96. -- * GOAL: Detect incorrect data in the size of products *
  97. -- * QUALITY CRITERIUM: "Correção" *
  98. -- * PARAMETERS: *
  99. -- * p_iteration_key: key of the iteration in which the screen will be run *
  100. -- * p_source_key: key of the source system related to the screen's execution *
  101. -- * p_screen_order: order number in which the screen is to be executed *
  102. -- *************************************************************************************
  103. PROCEDURE screen_product_dimensions (p_iteration_key t_tel_iteration.iteration_key%TYPE,
  104. p_source_key t_tel_source.source_key%TYPE,
  105. p_screen_order t_tel_schedule.screen_order%TYPE) IS
  106. -- SEARCH FOR EXTRACTED PRODUCTS CONTAINING PROBLEMS
  107. CURSOR products_with_problems IS
  108. SELECT rowid
  109. FROM t_data_products
  110. WHERE rejected_by_screen='0'
  111. AND (((width IS NULL OR height IS NULL OR depth IS NULL) AND UPPER(pack_type) IN (SELECT pack_type
  112. FROM t_lookup_pack_dimensions
  113. WHERE has_dimensions='1'))
  114. OR ((width>=0 OR height>=0 OR depth>=0 AND UPPER(pack_type) IN (SELECT pack_type
  115. FROM t_lookup_pack_dimensions
  116. WHERE has_dimensions='0'))));
  117. i PLS_INTEGER:=0;
  118. v_screen_name VARCHAR2(30):='screen_product_dimensions';
  119. BEGIN
  120. pck_log.write_log(' Starting SCREEN ["'||UPPER(v_screen_name)||'"] with order #'||p_screen_order||'');
  121. FOR rec IN products_with_problems LOOP
  122. -- RECORDS THE ERROR IN THE TRANSFORMATION ERROR LOGGER BUT DOES * NOT REJECT THE LINE *
  123. error_log(v_screen_name,SYSDATE,p_source_key,p_iteration_key,rec.rowid);
  124. i:=i+1;
  125. END LOOP;
  126. pck_log.write_log(' Data quality problems in '|| i || ' row(s).',' Done!');
  127. EXCEPTION
  128. WHEN NO_DATA_FOUND THEN
  129. pck_log.write_log(' No data quality problems found.',' Done!');
  130. WHEN OTHERS THEN
  131. pck_log.write_uncomplete_task_msg;
  132. RAISE e_transformation;
  133. END;
  134.  
  135.  
  136.  
  137. -- *************************************************************************************
  138. -- * GOAL: detect and reject packed products with an empty liquid weight *
  139. -- * QUALITY CRITERIUM: "Completude" *
  140. -- * PARAMETERS: *
  141. -- * p_iteration_key: key of the iteration in which the screen will be run *
  142. -- * p_source_key: key of the source system related to the screen's execution *
  143. -- * p_screen_order: order number in which the screen is to be executed *
  144. -- *************************************************************************************
  145. PROCEDURE screen_null_liq_weight (p_iteration_key t_tel_iteration.iteration_key%TYPE,
  146. p_source_key t_tel_source.source_key%TYPE,
  147. p_screen_order t_tel_schedule.screen_order%TYPE) IS
  148. -- SOMETHING IS MISSING
  149. CURSOR PRODUTOS_COM_PROBLEMAS IS
  150. SELECT rowid
  151. FROM t_data_products
  152. WHERE LIQ_WEIGHT IS NULL;
  153.  
  154. i PLS_INTEGER:=0;
  155. v_screen_name VARCHAR2(30):='screen_null_liq_weight';
  156. BEGIN
  157. pck_log.write_log(' Starting SCREEN ["'||UPPER(v_screen_name)||'"] with order #'||p_screen_order||'');
  158.  
  159. FOR j IN PRODUTOS_COM_PROBLEMAS LOOP
  160. --REGISTAR OS PROBLEMAS DE QUALIDADE ENCONTRADOS
  161. error_log(v_screen_name,SYSDATE,p_source_key,p_iteration_key,j.rowid);
  162.  
  163. --REJEICAO DAS LINHAS COM PROBLEMAS
  164. UPDATE t_data_products SET rejected_by_screen = i WHERE rowid = j.rowid;
  165.  
  166. i:=i+1;
  167.  
  168. END LOOP;
  169. -- SOMETHING IS MISSING
  170.  
  171.  
  172. pck_log.write_log(' Data quality problems in '|| i || ' row(s).',' Done!');
  173. EXCEPTION
  174. WHEN NO_DATA_FOUND THEN
  175. pck_log.write_log(' No data quality problems found.',' Done!');
  176. WHEN OTHERS THEN
  177. pck_log.write_uncomplete_task_msg;
  178. RAISE e_transformation;
  179. END;
  180.  
  181.  
  182. -- *************************************************************************************
  183. -- * GOAL: detect incorrect data in products *
  184. -- * QUALITY CRITERIUM: "Correção" *
  185. -- * PARAMETERS: *
  186. -- * p_iteration_key: key of the iteration in which the screen will be run *
  187. -- * p_source_key: key of the source system related to the screen's execution *
  188. -- * p_screen_order: order number in which the screen is to be executed *
  189. -- *************************************************************************************
  190. PROCEDURE screen_incorrect_products ( p_iteration_key t_tel_iteration.iteration_key%TYPE,
  191. p_source_key t_tel_source.source_key%TYPE,
  192. p_screen_order t_tel_schedule.screen_order%TYPE) IS
  193. cursor products_with_problems is
  194. SELECT p.rowid FROM t_data_products p join t_lookup_brands b on p.brand=b.brand_wrong
  195. WHERE REJECTED_BY_SCREEN='0';
  196.  
  197. i PLS_INTEGER:=0;
  198. v_screen_name VARCHAR2(30):='screen_incorrect_products';
  199. BEGIN
  200. pck_log.write_log(' Starting SCREEN ["'||UPPER(v_screen_name)||'"] with order #'||p_screen_order||'');
  201.  
  202. FOR rec IN products_with_problems LOOP
  203. error_log(v_screen_name,SYSDATE,p_source_key,p_iteration_key,rec.rowid);
  204. i:=i+1;
  205. END LOOP;
  206.  
  207. pck_log.write_log(' Data quality problems in '|| i || ' row(s).',' Done!');
  208. EXCEPTION
  209. WHEN NO_DATA_FOUND THEN
  210. pck_log.write_log(' No data quality problems found.',' Done!');
  211. WHEN OTHERS THEN
  212. pck_log.write_uncomplete_task_msg;
  213. RAISE e_transformation;
  214. END;
  215.  
  216. ----
  217. PROCEDURE screen_promocoes_problemas ( p_iteration_key t_tel_iteration.iteration_key%TYPE,
  218. p_source_key t_tel_source.source_key%TYPE,
  219. p_screen_order t_tel_schedule.screen_order%TYPE) IS
  220.  
  221. CURSOR promocoes_com_problemas_red IS
  222. SELECT rowid rRed
  223. FROM t_data_promotions
  224. WHERE reduction=0 AND (on_outdoor=1 OR on_tv=1) ;
  225.  
  226. CURSOR promocoes_com_problemas_null IS
  227. SELECT rowid rNull
  228. FROM t_data_promotions
  229. WHERE on_tv is null ;
  230.  
  231. i PLS_INTEGER:=0;
  232. v_screen_name VARCHAR2(30):='screen_promocoes_problemas';
  233. BEGIN
  234. pck_log.write_log(' Starting SCREEN ["'||UPPER(v_screen_name)||'"] with order #'||p_screen_order||'');
  235.  
  236. FOR j IN promocoes_com_problemas_red LOOP
  237. --REGISTAR OS PROBLEMAS DE QUALIDADE ENCONTRADOS
  238. error_log(v_screen_name,SYSDATE,p_source_key,p_iteration_key,j.rRed);
  239.  
  240.  
  241. i:=i+1;
  242.  
  243. END LOOP;
  244.  
  245. FOR j IN promocoes_com_problemas_null LOOP
  246. --REGISTAR OS PROBLEMAS DE QUALIDADE ENCONTRADOS
  247. error_log(v_screen_name,SYSDATE,p_source_key,p_iteration_key,j.rNull);
  248.  
  249. --REJEICAO DAS LINHAS COM PROBLEMAS
  250. UPDATE t_data_promotions SET rejected_by_screen = i WHERE rowid = j.rNull;
  251.  
  252. i:=i+1;
  253.  
  254. END LOOP;
  255.  
  256.  
  257.  
  258. pck_log.write_log(' Data quality problems in '|| i || ' row(s).',' Done!');
  259. EXCEPTION
  260. WHEN NO_DATA_FOUND THEN
  261. pck_log.write_log(' No data quality problems found.',' Done!');
  262. WHEN OTHERS THEN
  263. pck_log.write_uncomplete_task_msg;
  264. RAISE e_transformation;
  265. END;
  266.  
  267.  
  268.  
  269.  
  270. -- ####################### TRANSFORMATION ROUTINES #######################
  271.  
  272. -- ****************************************************************
  273. -- * TRANSFORMATION OF PRODUCTS ACCORDING TO THE LOGICAL DATA MAP *
  274. -- ****************************************************************
  275.  
  276. PROCEDURE transform_products IS
  277. BEGIN
  278. pck_log.write_log(' Transforming data ["TRANSFORM_PRODUCTS"]');
  279.  
  280. INSERT INTO t_clean_products(id,name,brand,pack_size,pack_type,diet_type,liq_weight,category_name)
  281. SELECT prod.id,prod.name,brand,height||'x'||width||'x'||depth,pack_type,cal.type,liq_weight,categ.name
  282. FROM t_data_products prod, t_lookup_calories cal, t_data_categories categ
  283. WHERE categ.rejected_by_screen='0'
  284. AND prod.rejected_by_screen='0'
  285. AND calories_100g>=cal.min_calories_100g
  286. AND calories_100g<=cal.max_calories_100g
  287. AND categ.id=prod.category_id;
  288.  
  289. -- SOMETHING IS MISSING --> ATUALIZAR AS LINHAS DA T_CLEAN_PRODUCTS PARA CORRIGIR AS MARCAS INVALIDAS
  290.  
  291. UPDATE t_clean_products c
  292. SET c.brand = (SELECT brand_transformed
  293. FROM t_lookup_brands l
  294. WHERE l.brand_wrong = c.brand )
  295. WHERE c.brand IN (SELECT brand_wrong
  296. FROM t_lookup_brands);
  297.  
  298.  
  299. pck_log.write_log(' Done!');
  300. EXCEPTION
  301. WHEN NO_DATA_FOUND THEN
  302. pck_log.write_log(' Found no lines to transform',' Done!');
  303. WHEN OTHERS THEN
  304. pck_log.write_uncomplete_task_msg;
  305. RAISE e_transformation;
  306. END;
  307.  
  308.  
  309.  
  310. -- **************************************************************
  311. -- * TRANSFORMATION OF STORES ACCORDING TO THE LOGICAL DATA MAP *
  312. -- **************************************************************
  313. PROCEDURE transform_stores IS
  314. BEGIN
  315. pck_log.write_log(' Transforming data ["TRANSFORM_STORES"]');
  316.  
  317. INSERT INTO t_clean_stores(name,reference,address,zip_code,location,district,telephones,fax,status,manager_name,manager_since)
  318. SELECT name,s.reference,CASE building WHEN '-' THEN NULL ELSE building||' - ' END || address||' / '||zip_code||', '||location,zip_code,location,district,SUBSTR(REPLACE(REPLACE(telephones,'.',''),' ',''),1,9),fax,CASE WHEN closure_date IS NULL THEN 'ACTIVE' ELSE 'INACTIVE' END, manager_name,manager_since
  319. FROM (SELECT name,reference,building,address,zip_code,location,district,telephones,fax,closure_date
  320. FROM t_data_stores_new
  321. WHERE rejected_by_screen='0'
  322. MINUS
  323. SELECT name,reference,building,address,zip_code,location,district,telephones,fax,closure_date
  324. FROM t_data_stores_old) s, t_data_managers_new d
  325. WHERE s.reference=d.reference AND
  326. d.rejected_by_screen='0';
  327.  
  328. pck_log.write_log(' Done!');
  329. EXCEPTION
  330. WHEN NO_DATA_FOUND THEN
  331. pck_log.write_log(' Found no lines to transform',' Done!');
  332. WHEN OTHERS THEN
  333. pck_log.write_uncomplete_task_msg;
  334. RAISE e_transformation;
  335. END;
  336.  
  337.  
  338. -- *********************************************************
  339. -- * TRANSFORMATION OF CELSIUS ACCORDING TO LOGICAL DATA MAP *
  340. -- *********************************************************
  341. PROCEDURE transform_celsius IS
  342. BEGIN
  343. pck_log.write_log(' Transforming data ["TRANSFORM_CELSIUS"]');
  344.  
  345.  
  346.  
  347. INSERT INTO t_clean_celsius(forecast_date,temperature_status)
  348. SELECT TO_CHAR(SYSDATE, 'MM-DD-YYYY'),
  349. CASE WHEN AVG((t_min+t_max)/2) < 4 THEN 'COLD'
  350. WHEN AVG((t_min+t_max)/2) < 10 THEN 'FRESH'
  351. WHEN AVG((t_min+t_max)/2) < 25 THEN 'NICE'
  352. ELSE 'HOT'
  353. END
  354. FROM t_data_celsius;
  355.  
  356. pck_log.write_log(' Done!');
  357. EXCEPTION
  358. WHEN NO_DATA_FOUND THEN
  359. pck_log.write_log(' Found no lines to transform',' Done!');
  360. WHEN OTHERS THEN
  361. pck_log.write_uncomplete_task_msg;
  362. RAISE e_transformation;
  363. END;
  364.  
  365.  
  366.  
  367.  
  368.  
  369. -- *********************************************************
  370. -- * TRANSFORMATION OF SALES ACCORDING TO LOGICAL DATA MAP *
  371. -- *********************************************************
  372. PROCEDURE transform_sales IS
  373. BEGIN
  374. pck_log.write_log(' Transforming data ["TRANSFORM_SALES"]');
  375.  
  376. INSERT INTO t_clean_sales(id,sale_date,store_id, customer_id)
  377. SELECT id,sale_date,store_id, customer_id
  378. FROM t_data_sales
  379. WHERE rejected_by_screen='0';
  380.  
  381. pck_log.write_log(' Done!');
  382. EXCEPTION
  383. WHEN NO_DATA_FOUND THEN
  384. pck_log.write_log(' Found no lines to transform',' Done!');
  385. WHEN OTHERS THEN
  386. pck_log.write_uncomplete_task_msg;
  387. RAISE e_transformation;
  388. END;
  389.  
  390.  
  391. -- *************************************************************
  392. -- * TRANSFORMATION OF CUSTOMERS ACCORDING TO LOGICAL DATA MAP *
  393. -- *************************************************************
  394. PROCEDURE transform_customers IS
  395. BEGIN
  396. pck_log.write_log(' Transforming data ["TRANSFORM_CUSTOMERS"]');
  397.  
  398. INSERT INTO t_clean_customers(id,card_number,name,address,location,district,zip_code,phone_nr,gender,age,marital_status)
  399. SELECT id,card_number,name,address,UPPER(location),UPPER(district),zip_code,phone_nr,
  400. CASE UPPER(gender) WHEN 'M' THEN 'MALE' WHEN 'F' THEN 'FEMALE' ELSE 'OTHER' END,
  401. age,
  402. CASE UPPER(marital_status) WHEN 'C' THEN 'MARRIED' WHEN 'S' THEN 'SINGLE' WHEN 'V' THEN 'WIDOW' WHEN 'D' THEN 'DIVORCED' ELSE 'OTHER' END
  403. FROM t_data_customers
  404. WHERE rejected_by_screen='0';
  405.  
  406. UPDATE t_clean_customers c
  407. SET c.district =(SELECT district_transformed
  408. FROM t_lookup_districts l
  409. WHERE l.district_wrong = c.district )
  410. WHERE c.district IN (SELECT district_wrong
  411. FROM t_lookup_districts);
  412.  
  413. pck_log.write_log(' Done!');
  414. EXCEPTION
  415. WHEN NO_DATA_FOUND THEN
  416. pck_log.write_log(' Found no lines to transform',' Done!');
  417. WHEN OTHERS THEN
  418. pck_log.write_uncomplete_task_msg;
  419. RAISE e_transformation;
  420. END;
  421.  
  422. PROCEDURE transform_promotions IS
  423. BEGIN
  424. pck_log.write_log(' Transforming data ["TRANSFORM_PROMOTIONS"]');
  425.  
  426. INSERT INTO t_clean_promotions (id,name,start_date,end_date,reduction,on_street,on_tv)
  427. SELECT id,name,start_date,end_date,reduction,
  428. CASE WHEN on_outdoor=0 THEN 'NO'
  429. ELSE 'YES' END,
  430. CASE WHEN on_tv=0 THEN 'NO'
  431. ELSE 'YES' END
  432. FROM t_data_promotions
  433. WHERE rejected_by_screen='0';
  434.  
  435. pck_log.write_log(' Done!');
  436. EXCEPTION
  437. WHEN NO_DATA_FOUND THEN
  438. pck_log.write_log(' Found no lines to transform',' Done!');
  439. WHEN OTHERS THEN
  440. pck_log.write_uncomplete_task_msg;
  441. RAISE e_transformation;
  442. END;
  443.  
  444.  
  445. -- *********************************************************
  446. -- * TRANSFORMATION OF FACTS ACCORDING TO LOGICAL DATA MAP *
  447. -- *********************************************************
  448. PROCEDURE transform_linesofsale IS
  449. BEGIN
  450. pck_log.write_log(' Transforming data ["TRANSFORM_LINESOFSALE"]');
  451.  
  452. INSERT INTO t_clean_linesofsale(id,sale_id,product_id,promo_id,line_date,quantity,ammount_paid)
  453. SELECT los.id,los.sale_id,los.product_id,losp.promo_id,los.line_date,quantity,ammount_paid
  454. FROM t_data_linesofsale los LEFT JOIN (SELECT line_id,promo_id
  455. FROM t_data_linesofsalepromotions
  456. WHERE rejected_by_screen='0') losp ON los.id=losp.line_id, t_data_sales
  457. WHERE los.rejected_by_screen='0' AND
  458. t_data_sales.id=los.sale_id;
  459.  
  460. pck_log.write_log(' Done!');
  461. EXCEPTION
  462. WHEN NO_DATA_FOUND THEN
  463. pck_log.write_log(' Found no lines to transform',' Done!');
  464. WHEN OTHERS THEN
  465. pck_log.write_uncomplete_task_msg;
  466. RAISE e_transformation;
  467. END;
  468.  
  469.  
  470. -- *****************************************************************************************************
  471. -- * MAIN *
  472. -- * *
  473. -- * EXECUTES THE TRANSFORMATION PROCESS *
  474. -- * IN *
  475. -- * p_duplicate_last_iteration: TRUE=duplicates last iteration and its schedule (FOR TESTS ONLY!) *
  476. -- *****************************************************************************************************
  477. PROCEDURE main (p_duplicate_last_iteration BOOLEAN) IS
  478. -- checks all scheduled screens
  479. cursor scheduled_screens_cursor(p_iteration_key t_tel_iteration.iteration_key%TYPE) IS
  480. SELECT UPPER(screen_name) screen_name,source_key,screen_order
  481. FROM t_tel_schedule, t_tel_screen
  482. WHERE iteration_key=p_iteration_key AND
  483. t_tel_schedule.screen_key=t_tel_screen.screen_key;
  484.  
  485. v_iteration_key t_tel_iteration.iteration_key%TYPE;
  486. v_sql VARCHAR2(200);
  487. BEGIN
  488. pck_log.write_log(' ','***** TRANSFORM TRANSFORM TRANSFORM TRANSFORM TRANSFORM TRANSFORM *****'); -- DUPLICATES THE LAST ITERATION AND THE CORRESPONDING SCREEN SCHEDULE
  489. IF p_duplicate_last_iteration THEN
  490. duplicate_last_iteration(SYSDATE);
  491. END IF;
  492.  
  493. -- CLEANS ALL _clean TABLES
  494. pck_log.write_log(' Deleting old _clean tables');
  495. DELETE FROM t_clean_products;
  496. DELETE FROM t_clean_linesofsale;
  497. DELETE FROM t_clean_stores;
  498. DELETE FROM t_clean_promotions;
  499. DELETE FROM t_clean_sales;
  500. DELETE FROM t_clean_celsius;
  501. DELETE FROM t_clean_customers;
  502.  
  503. pck_log.write_log(' Done!');
  504.  
  505. -- FINDS THE MOST RECENTLY SCHEDULED ITERATION
  506. BEGIN
  507. SELECT MAX(iteration_key)
  508. INTO v_iteration_key
  509. FROM t_tel_iteration;
  510. EXCEPTION
  511. WHEN OTHERS THEN
  512. RAISE e_transformation;
  513. END;
  514.  
  515. -- RUNS ALL THE SCHEDULED SCREENS
  516. -- versão estática
  517. /* FOR rec IN scheduled_screens_cursor(v_iteration_key) LOOP
  518. IF UPPER(rec.screen_name)='SCREEN_PRODUCT_DIMENSIONS' THEN
  519. screen_dimensions(v_iteration_key, rec.source_key, rec.screen_order);
  520. ELSIF UPPER(rec.screen_name)='SCREEN_NULL_LIQ_WEIGHT' THEN
  521. screen_null_liq_weight(v_iteration_key, rec.source_key, rec.screen_order);
  522. END IF;*/
  523. -- EXECUÇÃO DINÂMICA DE SCREENS
  524. FOR rec IN scheduled_screens_cursor(v_iteration_key) LOOP
  525. v_sql:='BEGIN pck_transform.'||rec.screen_name||'('||v_iteration_key||','||rec.source_key||','||rec.screen_order||'); END;';
  526. -- pck_log.write_log(v_sql);
  527. EXECUTE IMMEDIATE v_sql;
  528. END LOOP;
  529.  
  530. -- UPDATES TABLE "T_TEL_ITERATION"
  531. UPDATE t_tel_iteration
  532. SET iteration_end_date = SYSDATE,
  533. iteration_duration_real=(SYSDATE-iteration_start_date)/86400
  534. WHERE iteration_key = v_iteration_key;
  535.  
  536. pck_log.write_log(' All screens have been run.');
  537.  
  538. -- EXECUTES THE TRANSFORMATION ROUTINES
  539. transform_customers;
  540. transform_products;
  541. transform_promotions;
  542. transform_stores;
  543. transform_celsius;
  544. transform_sales;
  545. transform_linesofsale;
  546.  
  547. COMMIT;
  548. pck_log.write_log(' All transformed data commited to database.');
  549. EXCEPTION
  550. WHEN e_transformation THEN
  551. pck_log.write_halt_msg;
  552. ROLLBACK;
  553. WHEN OTHERS THEN
  554. ROLLBACK;
  555. pck_log.write_uncomplete_task_msg;
  556. pck_log.write_halt_msg;
  557. END;
  558.  
  559. end pck_transform;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement