query="SELECT a.id, b.id
FROM tab_a a, tab_b b
WHERE a.ref = b.ref
AND a.amount = -b.amount
AND NOT a.tot AND NOT b.tot
AND a.a_id = %(a_id)s AND b.a_id = %(a_id)s
{p_id_condition}
ORDER BY a.date desc"
我正在尝试
首先尝试匹配ref,但如果找不到对,请尝试匹配金额
答案 0 :(得分:1)
这样的事情会起作用吗?
SQL> with tbl(str) as (
select 'value1~|~value2~|~~|~value4' from dual
)
select regexp_substr(str, '(.*?)(~\|~|$)', 1, level, NULL, 1) parsed
from tbl
connect by level <= regexp_count(str, '~\|~')+1;
PARSED
--------------------------------
value1
value2
value4
SQL>
我使用显式连接语法重写了您的查询,该语法隔离并显示您在问题中提到的两个连接条件。然后我把它改成了一个或者,这似乎是你想要的。