为什么 to_Char(date, 'd') 函数只是忽略 Oracle 过程中的条件逻辑?



我正在尝试检查performanceDate的日期,只有在工作日时才应用折扣。

//14/04/2018周六

v_performanceday VARCHAR(5);
SELECT PERFORMANCEDATE INTO v_performanceday FROM PERFORMANCE WHERE PERFORMANCEID = p_PerformanceID;
CASE
WHEN (to_char(v_performanceday, 'd') != '6' OR to_char(v_performanceday, 'd') != '7')
THEN
INSERT INTO DISCOUNT  (Reason, MembershipID, PerformanceID) 
VALUES (p_Reason, p_MembershipID, p_PerformanceID)
returning DiscountID into v_discountid;
v_discountprice := 2.0;
ELSE
RAISE_APPLICATION_ERROR(-20101, '***********Members only get discount on weekday performances!***************'); 
END CASE;

现在,我收到了这个错误。

Error report -
ORA-06502: PL/SQL: numeric or value error: character string buffer too small
ORA-06512: at "USER2.CREATE_NEW_BOOKING", line 56
ORA-06512: at line 1
06502. 00000 -  "PL/SQL: numeric or value error%s"
*Cause:    An arithmetic, numeric, string, conversion, or constraint error
occurred. For example, this error occurs if an attempt is made to
assign the value NULL to a variable declared NOT NULL, or if an
attempt is made to assign an integer larger than 99 to a variable
declared NUMBER(2).
*Action:   Change the data, how it is manipulated, or how it is declared so
that values do not violate constraints.

但是,如果我将第一行数据类型替换为DATE,则无论我是否插入工作日或周末发生的性能的PerformanceID,它都会应用折扣!

v_performanceday DATE;

有人能帮我弄清楚为什么它没有正确地应用to_char函数,而在其他围绕它的案例语句如预期完美工作时却忽略了它吗?

v_performancedate应该是日期——这是正确的类型。

你的逻辑不正确。or应该是and。或者更好的是not in:

CASE WHEN to_char(v_performanceday, 'd') not in ('6', '7')

最新更新