Como puedo usar el resultado de un query dentro del operador in, lo he intentado y no me retorna resultados de manera dinamica, pero si lo hago manual y me retorna datos.
CREATE TABLE table_name (isn) AS
SELECT 'A8176,A8605,A4460' FROM DUAL;
WITH
DATA_COD AS (
SELECT 'A8176' COD, '1' IND FROM DUAL
UNION
SELECT 'A8605' COD, '2' IND FROM DUAL
UNION
SELECT 'A4460' COD, '3' IND FROM DUAL
UNION
SELECT 'A8178' COD, '4' IND FROM DUAL
)
SELECT *
FROM DATA_COD
WHERE DATA_COD.COD IN (
SELECT REGEXP_REPLACE(isn,
'([A-Za-z0-9]+)',
'''\1''',
1,
0,
'c'
) OBD
FROM table_name
);
Resultado: No rows returned dbfiddle
Manual:
WITH
DATA_COD AS (
SELECT 'A8176' COD, '1' IND FROM DUAL
UNION
SELECT 'A8605' COD, '2' IND FROM DUAL
UNION
SELECT 'A4460' COD, '3' IND FROM DUAL
UNION
SELECT 'A8178' COD, '4' IND FROM DUAL
)
SELECT *
FROM DATA_COD
WHERE DATA_COD.COD IN ('A8176','A8605','A4460')
;
Resultado: dbfiddle
WHERE DATA_COD.COD IN (select regexp_substr(isn,'[^,]+', 1, level) as C from table_name connect by regexp_substr(isn, '[^,]+', 1, level) is not null)