oracleoracle11goraclereports

If Sunday then show Week rest else present in oracle reports


Hi dear I am working in oracle reports I have a column ATT_DATE which have dates for the month next column I have :Day which I create function like this which gives me day

begin
  RETURN TO_CHAR(:ATT_DATE, 'DAY');
end;

It gives me Day of the Date which present in :ATT_DATE Now I wants to make one more function which checks SUNDAY then gives me two these things like if Sunday than Weekly Rest else Present in :Status column I write this code

function M_DAY2Formula return CHAR is
begin
  IF TO_CHAR(:ATT_DATE, 'DAY') = 'SUNDAY' THEN
     RETURN 'WEEK REST';
  ELSE
     RETURN 'PRESENT';
  END IF;
end;

but it neve Takes Sunday it gives in all days Present


Solution

  • I believe it is about TRIM. See the following example:

    SQL> with dates as
      2    (select trunc(sysdate, 'iw') + level - 1 datum
      3     from dual
      4     connect by level <= 10
      5    )
      6  select datum,
      7         to_char(datum, 'DAY') dan,
      8         to_char(datum, 'DAY', 'nls_date_language = english') dan2,
      9         --
     10         length(to_char(datum, 'DAY', 'nls_date_language = english')) len_dan2,
     11         --
     12         case when to_char(datum, 'DAY', 'nls_date_language = english') = 'SUNDAY' then 'Week rest'
     13              else 'Present'
     14         end status,
     15         --
     16         case when trim(to_char(datum, 'DAY', 'nls_date_language = english')) = 'SUNDAY' then 'Week rest'
     17              else 'Present'
     18         end status2
     19  from dates
     20  order by datum;
    
    DATUM      DAN         DAN2        LEN_DAN2 STATUS    STATUS2
    ---------- ----------- --------- ---------- --------- ---------
    15.02.2021 PONEDJELJAK MONDAY             9 Present   Present
    16.02.2021 UTORAK      TUESDAY            9 Present   Present
    17.02.2021 SRIJEDA     WEDNESDAY          9 Present   Present
    18.02.2021 ČETVRTAK    THURSDAY           9 Present   Present
    19.02.2021 PETAK       FRIDAY             9 Present   Present
    20.02.2021 SUBOTA      SATURDAY           9 Present   Present
    21.02.2021 NEDJELJA    SUNDAY             9 Present   Week rest
    22.02.2021 PONEDJELJAK MONDAY             9 Present   Present
    23.02.2021 UTORAK      TUESDAY            9 Present   Present
    24.02.2021 SRIJEDA     WEDNESDAY          9 Present   Present
    
    10 rows selected.
    
    SQL>
    

    In other words:


    Or, in Reports Builder:

    function M_DAY2Formula return CHAR is
    begin
      IF trim(TO_CHAR(:ATT_DATE, 'DAY')) = 'SUNDAY' THEN     --> TRIM, here
         RETURN 'WEEK REST';
      ELSE
         RETURN 'PRESENT';
      END IF;
    end;