在旧式连接中使用REGEXP_LIKE

时间:2014-03-13 09:51:31

标签: sql oracle

我有旧样式连接的PL / SQL查询(使用(+))。现在我需要添加带有REGEXP_LIKE子句的左连接表。我该怎么做?

在ANSI样式中,查询如下所示:

select
    *
from
    deals d
    left join
        auctions a on a.session_code = d.session_code
    left join
        auction_history ah on ah.auction_code = a.auction_code and
                                REGEXP_LIKE(ah.auction_code, '^[A-Z]+')
where
    trunc(d.operday) = trunc(sysdate)

旧式我希望得到这样的东西:

select
    *
from
    deals d,
    auctions a,
    auction_history ah,
where
    trunc(d.operday) = trunc(sysdate) and
    d.session_code = a.session_code (+) and 
    (a.auction_code = ah.auction_code (+) and 
        REGEXP_LIKE(ah.auction_code, '^[A-Z]+'))

但它不会返回session_code为null的交易。

提前致谢!

1 个答案:

答案 0 :(得分:3)

REGEXP_LIKE被视为有关旧版连接的常规函数​​。这是一个例子:

SQL> WITH main_table AS
  2  (SELECT 1 ID FROM dual UNION ALL
  3   SELECT 2 FROM dual),
  4  lookup_table AS
  5  (SELECT 1 ID, 'txt' txt FROM dual UNION ALL
  6   SELECT 2 ID, '999' txt FROM dual)
  7  SELECT m.id, l.txt
  8    FROM main_table m, lookup_table l
  9   WHERE m.id = l.id(+)
 10     AND REGEXP_LIKE(l.txt(+), '^[A-Z]+');

        ID TXT
---------- ---
         1 txt
         2 

不过,我建议不要在最近的版本中使用旧式连接。