If Sunday then show Week rest else present in oracle 报告
If Sunday then show Week rest else present in oracle reports
嗨,亲爱的,我在 oracle 报告中工作,我有一个列 ATT_DATE
,其中有下一个月的日期我有:我创建这样的函数的日期
begin
RETURN TO_CHAR(:ATT_DATE, 'DAY');
end;
它给了我出现在 :ATT_DATE 中的日期
现在我想再做一个函数来检查 SUNDAY 然后给我两个这样的东西 if Sunday than Weekly Rest else Present 在 :Status 列我写了这段代码
function M_DAY2Formula return CHAR is
begin
IF TO_CHAR(:ATT_DATE, 'DAY') = 'SUNDAY' THEN
RETURN 'WEEK REST';
ELSE
RETURN 'PRESENT';
END IF;
end;
但它从不占用星期日它在所有的日子里都给现在
我认为大约是 TRIM
。请参阅以下示例:
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>
换句话说:
- 如果您的日期语言不是英语,则无法将其与“SUNDAY”(在我的示例中是
dan
)进行比较
- 如果语言没有问题,为什么第一个
case
(status
列)不能正常工作?因为 length - 看到了吗?无论是哪一天,在所有情况下长度都是 9
。
- 因此,
trim
DAY
值然后按预期工作
或者,在 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;
什么代码适合我
function M_DAY3Formula return Char is
a varchar2(40);
B varchar2(40);
begin
select RTRIM(to_char(:ATT_DATE,'DAY')) into a from dual;
IF A = 'SUNDAY'
THEN B := 'WEEK REST';
ELSE B := 'PRESENT';
END IF;
return B;
end;
嗨,亲爱的,我在 oracle 报告中工作,我有一个列 ATT_DATE
,其中有下一个月的日期我有:我创建这样的函数的日期
begin
RETURN TO_CHAR(:ATT_DATE, 'DAY');
end;
它给了我出现在 :ATT_DATE 中的日期 现在我想再做一个函数来检查 SUNDAY 然后给我两个这样的东西 if Sunday than Weekly Rest else Present 在 :Status 列我写了这段代码
function M_DAY2Formula return CHAR is
begin
IF TO_CHAR(:ATT_DATE, 'DAY') = 'SUNDAY' THEN
RETURN 'WEEK REST';
ELSE
RETURN 'PRESENT';
END IF;
end;
但它从不占用星期日它在所有的日子里都给现在
我认为大约是 TRIM
。请参阅以下示例:
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>
换句话说:
- 如果您的日期语言不是英语,则无法将其与“SUNDAY”(在我的示例中是
dan
)进行比较 - 如果语言没有问题,为什么第一个
case
(status
列)不能正常工作?因为 length - 看到了吗?无论是哪一天,在所有情况下长度都是9
。 - 因此,
trim
DAY
值然后按预期工作
或者,在 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;
什么代码适合我
function M_DAY3Formula return Char is
a varchar2(40);
B varchar2(40);
begin
select RTRIM(to_char(:ATT_DATE,'DAY')) into a from dual;
IF A = 'SUNDAY'
THEN B := 'WEEK REST';
ELSE B := 'PRESENT';
END IF;
return B;
end;