簡體   English   中英

為什么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,則無論我插入在工作日還是在周末發生的Performance PerformanceID,它都會應用折扣!

v_performanceday DATE;

誰能幫我弄清楚為什么它不能正確地應用to_char函數,而在圍繞此的其他case語句按預期運行時卻完全忽略了它嗎?

v_performancedate應該是一個日期-這是正確的類型。

您的邏輯不正確。 or應當為and 或更好,但not in

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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM