Det skulle have været ydre sammenføjning; noget som dette:
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 /
hvilket resulterer i
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>
Fra og med Oracle Reports problem:spring PL/SQL helt over og brug en let ændret markørforespørgsel som rapportens forespørgsel. I linje #8 ville du stadig bruge parametre, sandsynligvis oprettet under rapportens Brugerparametre i objektnavigatoren. Rapport ville, formoder jeg, få deres værdier fra andre steder (såsom Oracle Forms eller Apex eller ...). Det samme gælder for ID
, tror jeg - du ønsker ikke rigtig at hardkode 111
, gør du?
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>
[Ydre deltagelse i rapporter]
Ah, ja ... i rapporter skal du bruge den "gamle" Oracles ydre joinforbindelse (+)
operatør. Det samme gælder for case
- brug decode
i stedet:
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;