Трябваше да е външно присъединяване; нещо подобно:
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 /
което води до
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>
От Oracle Reports проблем:пропуснете изцяло PL/SQL и използвайте леко модифицирана заявка на курсора като заявка на отчета. В ред #8 все още бихте използвали параметри, най-вероятно създадени под Потребителски параметри на отчета в навигатора на обекти. Предполагам, че отчетът ще получи стойностите си от другаде (като Oracle Forms или Apex или ...). Същото важи и за ID
, вярвам - всъщност не искате да кодирате твърдо 111
, а вие?
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>
[Външно присъединяване в отчети]
А, да ... в отчетите ще трябва да използвате външното съединение на "стария" Oracle (+)
оператор. Същото важи и за case
- използвайте decode
вместо това:
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;