为什么 to_Char(date, 'd') 函数只是忽略了 Oracle 过程中的条件逻辑?
Why does the to_Char(date, 'd') function simply ignoring the conditional logic in Oracle procedure?
我正在尝试查看 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 函数,而当其他 case 语句按预期完美运行时却简单地忽略它?
v_performancedate
应该是日期 -- 这是正确的类型。
你的逻辑不正确。 or
应该是 and
。 . .或者更好,not in
:
CASE WHEN to_char(v_performanceday, 'd') not in ('6', '7')
我正在尝试查看 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 函数,而当其他 case 语句按预期完美运行时却简单地忽略它?
v_performancedate
应该是日期 -- 这是正确的类型。
你的逻辑不正确。 or
应该是 and
。 . .或者更好,not in
:
CASE WHEN to_char(v_performanceday, 'd') not in ('6', '7')