Issue when comparing result of to_char(myDate, #39;DAY#39;) to a string(将 to_char(myDate, DAY) 的结果与字符串进行比较时出现问题)
问题描述
我一直试图找出可能是什么问题,但我只是运气不好,根本不了解这个问题.我有以下代码:
I have been trying to find what the issue might be but I am just out of luck and don't understand this problem at all.I have the following code:
CREATE OR REPLACE FUNCTION ckeckDay(dateC in date)
RETURN VARCHAR
IS
day VARCHAR(15);
checkFriday VARCHAR(1);
BEGIN
checkFriday := 'N';
day := to_char(dateC, 'DAY');
IF day = 'FRIDAY' THEN
checkFriday := 'Y';
END IF;
RETURN day;
END;
/
dateC 设置为 Friday(甚至通过返回 day 而不是 day 变量来测试它并返回 Friday.)但是IF 语句永远不会计算为真,即使 day 变量确实是星期五.任何想法如何解决这个问题.谢谢
the dateC is set to Friday (even tested it by returning day instead of the day variable and it returns Friday.) However the IF statement never evaluates to true even though the day variable is indeed Friday.Any ideas how to go around this issue.Thanks
推荐答案
这是因为 day 变量包含一个空白填充值.使用 trim 函数去除前导和尾随空格:
It is because day variable contains a blank padded value. Use trim function to get rid of leading and trailing spaces:
IF trim(day) = 'FRIDAY' THEN
checkFriday := 'Y';
END IF;
并且请使用 VARCHAR2 数据类型作为字符串变量.不要使用VARCHAR.
And please use VARCHAR2 datatype for string variables. Do not use VARCHAR.
这篇关于将 to_char(myDate, 'DAY') 的结果与字符串进行比较时出现问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:将 to_char(myDate, 'DAY') 的结果与字符串进行比较时出现问题
基础教程推荐
- 带更新的 sqlite CTE 2022-01-01
- 使用 VBS 和注册表来确定安装了哪个版本和 32 位 2021-01-01
- while 在触发器内循环以遍历 sql 中表的所有列 2022-01-01
- MySQL 5.7参照时间戳生成日期列 2022-01-01
- MySQL根据从其他列分组的值,对两列之间的值进行求和 2022-01-01
- ORA-01830:日期格式图片在转换整个输入字符串之前结束/选择日期查询的总和 2021-01-01
- CHECKSUM 和 CHECKSUM_AGG:算法是什么? 2021-01-01
- 从字符串 TSQL 中获取数字 2021-01-01
- 如何在 CakePHP 3 中实现 INSERT ON DUPLICATE KEY UPDATE aka upsert? 2021-01-01
- 带有WHERE子句的LAG()函数 2022-01-01
