oracle plsql,在另一个选择中选择

qaxu7uf2  于 2023-04-20  发布在  Oracle
关注(0)|答案(1)|浏览(170)

i有2个选择;我需要在另一个中使用select。
1.主要选择:

SELECT home_id, home_type, bathrooms, comment, regexp_substr(comment, '[0-9]{20}', 1, 1) acc,
FROM homes
WHERE home_id < 500
AND home_type = 'two-storey'
SELECT distinct l.acc_n,l.gl_id,l.ct FROM sdogl l WHERE l.acc_n='12345678901111472601'

最后,我需要像这样做:

SELECT h.home_id, h.home_type, h.bathrooms, h.comment, regexp_substr(h.comment, '[0-9]{20}', 1, 1) acc, l.acc_n,l.gl_id,l.ct
FROM homes h, sdogl l
WHERE home_id < 500
**AND 'result regexp'=l.acc_n**
AND home_type = 'two-storey'

感谢您的关注!
我试图把l.acc_n放在(SELECT distinct l.acc_n FROM sdogl l)它没有帮助

14ifxucb

14ifxucb1#

可以在连接条件中使用正则表达式:

SELECT h.home_id,
       h.home_type,
       h.bathrooms,
       h.comment,
       regexp_substr(h.comment, '[0-9]{20}', 1, 1) acc,
       l.acc_n,
       l.gl_id,
       l.ct
FROM   homes h
       INNER JOIN (
         SELECT distinct
                acc_n,
                gl_id,
                ct
         FROM   sdogl
         WHERE  acc_n='12345678901111472601'
       ) l
       ON regexp_substr(h.comment, '[0-9]{20}', 1, 1) = l.acc_n
WHERE  home_id < 500
AND    home_type = 'two-storey'

相关问题