Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on Jan 19th, 2012  |  syntax: PL/SQL  |  size: 1.32 KB  |  hits: 102  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. SET echo off;
  2. SET termout off;
  3. SET head off;
  4. SET feedback off;
  5. SET trimspool ON;
  6. SET linesize 800;
  7. SET pagesize 0;
  8.  
  9.  
  10. DECLARE
  11.  
  12. CURSOR c1 IS
  13. SELECT pupil_number,school,absent_date FROM (
  14. SELECT DISTINCT
  15. sa.pupil_number,
  16. sa.school,
  17. sa.absent_date
  18. FROM sec_attendances sa inner join students s ON s.pupil_number = sa.pupil_number
  19. inner join schools sc ON sc.school = sa.school
  20. WHERE (sa.reason_code IN ('02','26'))
  21. AND TO_DATE(sa.absent_date) = TRUNC(SYSDATE)
  22. AND sa.pupil_number NOT IN (SELECT SUBSTR(pupil_number,2) FROM swcs_global_conn_temp)
  23. AND sa.period = sc.period
  24. AND sa.absent_code <> 'L'
  25. UNION
  26. SELECT DISTINCT
  27. ea.pupil_number,
  28. ea.school,
  29. ea.absent_date
  30. FROM elem_attendances ea inner join students s ON s.pupil_number = ea.pupil_number
  31. WHERE  ea.reason_code_am IN ('02','26')
  32. AND TO_DATE(ea.absent_date) = TRUNC(SYSDATE)
  33. AND s.grade IN ('KA','KP','KG','01','02','03','04','05','06','07','08','09','10','11','12')
  34. AND ea.pupil_number NOT IN (SELECT SUBSTR(pupil_number,2) FROM swcs_global_conn_temp))
  35. ORDER BY school;
  36.  
  37. spool "someDir\test1.csv";
  38.  
  39. SELECT 'Pupil_Number, School, Absence_Code, Absence_Date' FROM dual;
  40. BEGIN
  41.  
  42. FOR rec IN c1
  43. LOOP
  44. DBMS_OUTPUT.put_line('S' || rec.pupil_number || ' ' || rec.school || ' ' || 'U ' || rec.absent_date);
  45. --add insert into temp table
  46. END LOOP;
  47.  
  48. spool off;