我有一个包含这样的列的表:
ID number
Adress varchar2
Message varchar2
地址可以有电子邮件或电话
我有一个这样的存储过程:
PROCEDURE get_messages (
i_email IN varchar2,
i_phone IN varchar2
o_messages OUT messages)
BEGIN
哪个会收到电子邮件,电话或两者。
在这个过程中,我想选择这样的消息:
nulls
,我想选择所有消息null
且i_phone是null
,我想全选
发送到该电子邮件的邮件null
且i_email是null
我想要全选
发送到该手机的消息
nulls
我想选择发送到i_email和i_phone的所有邮件我很难写出像这样的选择。
SELECT * FROM MESSAGES
WHERE (Address = i_email OR i_email IS NULL)
OR
(Address = i_phone OR i_phone IS NULL)
但只有当两个值都不是nulls
答案 0 :(得分:1)
试试这个。
SELECT *
FROM MESSAGES
WHERE ( i_email IS NULL
AND i_phone IS NULL )
OR ( i_email IS NOT NULL
AND i_phone IS NULL
AND Address = i_email )
OR ( i_phone IS NOT NULL
AND i_email IS NULL
AND Address = i_phone )
OR ( Address = i_email
OR i_phone = Address )