比较字符总是返回false

时间:2017-12-10 15:21:10

标签: sql oracle plsql

我是PL / SQL的新手,我的存储过程已经存在问题。它编译,但一个IF语句永远不会按需运行。

IF SUBSTR(p_phone_number, 5, 1) <> '2' OR SUBSTR(p_phone_number, 5, 1) <> '6' THEN
    RAISE ex_phone_number_non_lv_custom2;
END IF;

调用程序时,p_phone_number'+37122222222',类型为VARCHAR2(12)。我使用了SUBSTR(p_phone_number, 5, 1)的服务器输出,它是预期的2,但是这个IF语句仍然引发了我的异常。为什么会这样?

2 个答案:

答案 0 :(得分:5)

你想要not in。 。 。但更好的是,使用IF SUBSTR(p_phone_number, 5, 1) NOT IN ('2', '6') THEN RAISE ex_phone_number_non_lv_custom2; END IF;

{{1}}

答案 1 :(得分:3)

您正在使用OR,您应该使用AND。

IF SUBSTR(p_phone_number, 5, 1) <> '2' AND SUBSTR(p_phone_number, 5, 1) <> '6' THEN
    RAISE ex_phone_number_non_lv_custom2;

使用OR时,它将始终抛出异常,因为其中一个条件始终为真。

相关问题