将to_char(myDate,'DAY')的结果与字符串进行比较时出现的问题 [英] Issue when comparing result of to_char(myDate, 'DAY') to a string

查看:90
本文介绍了将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设置为星期五(甚至通过返回day而不是day变量对其进行了测试,然后返回星期五.)但是,即使day变量,IF语句也永远不会求值为true确实是星期五.任何想法都可以解决这个问题.谢谢

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')的结果与字符串进行比较时出现的问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆