Het had outer join moeten zijn; zoiets als dit:
SQL> declare
2 descr varchar2(90);
3 gz_dt date;
4 date1 date :=to_date('2021-01-01','YYYY-MM-DD');
5 date2 date :=to_date('2021-01-31','YYYY-MM-DD');
6 vatt_date date;
7 vempcode number;
8 cursor c_gzdt is
9 select g.gazzeted_date, g.description, p.att_date, p.emp_code
10 from pay_in_out p left join gazzeted_days g
11 on p.att_date = g.gazzeted_date
12 and gazzeted_date between date1 and date2
13 and p.emp_code=111
14 order by p.att_date;
15 begin
16 open c_gzdt;
17 loop
18 fetch c_gzdt into gz_dt, descr, vatt_date, vempcode ;
19 exit when c_gzdt%notfound;
20
21 if vatt_date = gz_dt then
22 dbms_output.put_line(vatt_date||' THE DAY OF : '||descr);
23 else
24 dbms_output.put_line(vatt_date||' THE DAY OF : '||'PRESENT');
25 end if;
26
27 end loop;
28 close c_gzdt;
29 end;
30 /
wat resulteert in
01.01.21 THE DAY OF : PRESENT
02.01.21 THE DAY OF : PRESENT
03.01.21 THE DAY OF : PRESENT
04.01.21 THE DAY OF : PRESENT
05.01.21 THE DAY OF : PRESENT
06.01.21 THE DAY OF : PRESENT
07.01.21 THE DAY OF : PRESENT
08.01.21 THE DAY OF : PRESENT
09.01.21 THE DAY OF : Its Holyday two
10.01.21 THE DAY OF : PRESENT
11.01.21 THE DAY OF : PRESENT
12.01.21 THE DAY OF : PRESENT
13.01.21 THE DAY OF : Its Holyday three
14.01.21 THE DAY OF : PRESENT
15.01.21 THE DAY OF : PRESENT
16.01.21 THE DAY OF : Its Holyday four
17.01.21 THE DAY OF : PRESENT
18.01.21 THE DAY OF : PRESENT
19.01.21 THE DAY OF : PRESENT
20.01.21 THE DAY OF : PRESENT
21.01.21 THE DAY OF : Its Holyday five
22.01.21 THE DAY OF : PRESENT
23.01.21 THE DAY OF : PRESENT
24.01.21 THE DAY OF : PRESENT
25.01.21 THE DAY OF : PRESENT
26.01.21 THE DAY OF : Its Holyday six
27.01.21 THE DAY OF : PRESENT
28.01.21 THE DAY OF : PRESENT
29.01.21 THE DAY OF : PRESENT
30.01.21 THE DAY OF : PRESENT
31.01.21 THE DAY OF : PRESENT
PL/SQL procedure successfully completed.
SQL>
Vanaf Oracle Reports probleem:sla PL/SQL volledig over en gebruik een licht gewijzigde cursorquery als rapportquery. In regel #8 zou je nog steeds parameters gebruiken, hoogstwaarschijnlijk gemaakt onder de Gebruikersparameters van het rapport binnen de Object Navigator. Rapport zou, neem ik aan, hun waarden ergens anders vandaan halen (zoals Oracle Forms of Apex of ...). Hetzelfde geldt voor de ID
, geloof ik - je wilt 111
niet echt hardcoderen , jij ook?
SQL> select p.att_date ||
2 ' THE DAY OF : ' ||
3 case when p.att_date = g.gazzeted_date then g.description
4 else 'PRESENT'
5 end result
6 from pay_in_out p left join gazzeted_days g
7 on p.att_date = g.gazzeted_date
8 and gazzeted_date between date '2021-01-01' and date '2021-01-31'
9 and p.emp_code = 111
10 order by p.att_date;
RESULT
--------------------------------------------------------------
01.01.21 THE DAY OF : PRESENT
02.01.21 THE DAY OF : PRESENT
03.01.21 THE DAY OF : PRESENT
04.01.21 THE DAY OF : PRESENT
05.01.21 THE DAY OF : PRESENT
06.01.21 THE DAY OF : PRESENT
07.01.21 THE DAY OF : PRESENT
08.01.21 THE DAY OF : PRESENT
09.01.21 THE DAY OF : Its Holyday two
10.01.21 THE DAY OF : PRESENT
<snip>
[Buitenste deelname in rapporten]
Ah, ja ... in rapporten moet je de "oude" outer join van Oracle gebruiken (+)
exploitant. Hetzelfde geldt voor case
- gebruik decode
in plaats daarvan:
select p.att_date ||
' THE DAY OF : ' ||
decode(p.att_date, g.gazzeted_date, g.description, 'PRESENT') result
from pay_in_out p, gazzeted_days g
where p.att_date = g.gazzeted_date (+)
and g.gazzeted_date (+) between date '2021-01-01' and date '2021-01-31'
and p.emp_code = 111
order by p.att_date;