I have a table with columns like this:
ID number
Adress varchar2
Message varchar2
Address can have email or phone
And I have a stored procedure like this:
PROCEDURE get_messages (
i_email IN varchar2,
i_phone IN varchar2
o_messages OUT messages)
BEGIN
Which gets email, phone or both.
And in this procedure I want to select messages like this:
- If i_email and i_phone both are
nullsI want to select all messages - If i_email is not
nulland i_phone isnullI want to select all messages sent to that email - If i_phone is not
nulland i_email isnullI want to select all messages sent to that phone- If i_email and i_phone both are not
nullsI want to select all messages sent to i_email and i_phone
- If i_email and i_phone both are not
I have a difficult time to write select like like this.
SELECT * FROM MESSAGES
WHERE (Address = i_email OR i_email IS NULL)
OR
(Address = i_phone OR i_phone IS NULL)
But it works only if both values are not nulls