Imagine table t1 have 2 cols:
col1 col2
--------------
test 900 1
test 901 2
test 902 3
user 901 4
test 909 5
I want to find just one row by 2 params (name, code) where name its (test, user ..etc) and code - (901, 902, null, .. etc). There could not be more than one row of the same (Code,name) - I Mean there Are no 2 rows that have "test 901" in Col1.
Code:
declare
name varchar2(30);
code varchar(10);
col_val varchar2(30);
col2_val numeric;
begin
name:= 'test';
code := '900';
select col1, col2 into col_val, col2_val
from t1
where
( REGEXP_LIKE(col1, name||'\s+'||code) -- (3)
or (
not REGEXP_LIKE(col1, name||'\s+'||code) -- (1)
and REGEXP_LIKE(col1, name) -- (2)
)
)
order by col1;
DBMS_OUTPUT.PUT_LINE('val:'||col_val||' id:'||col2_val);
end;
1) for test values name:= 'test' code := '900' the result should be "val:test 900 id:1" - It's OK.
2) BUT for name:= 'test' code := '909' the result should be "val:test 909 id:5", but I got "val:test 900 id:1" ( the first row with Name='Test' ) - It's NOT want I want.
3) and in case name:= 'test' code := '999' the result should be "val:test 900 id:1" (there are NO 999 code, so I need just any row that have Name='test' inside).
The main question is WHY oracle Ignores (1) clause for 2) example? Perhaps I'm doing something wrong - so it would be great if You could show my mistake!