Este tipo de SQL dinámico en SQL se puede crear con DBMS_XMLGEN.getXML
. Aunque la consulta parece un poco extraña, es posible que desee considerar un diseño diferente.
Primero, creé una tabla de muestra y una fila usando su DDL. No estoy seguro exactamente de lo que está tratando de hacer con las condiciones, así que las simplifiqué en dos filas con condiciones más simples. La primera fila coincide con la primera condición y ninguna fila coincide con la segunda condición.
--Create sample table and row that matches the condition.
CREATE TABLE test_tab(
date_column DATE,
frequency NUMBER,
test_statement VARCHAR2(255)
)
/
insert into test_tab values(sysdate, 1, 'frequency = 1');
insert into test_tab values(sysdate, 2, '1=2');
commit;
Aquí está la consulta grande, y solo devuelve la primera fila, que solo coincide con la primera condición.
--Find rows where ROWID is in a list of ROWIDs that match the condition.
select *
from test_tab
where rowid in
(
--Convert XMLType to relational data.
select the_rowid
from
(
--Convert CLOB to XMLType.
select xmltype(xml_results) xml_results
from
(
--Create a single XML file with the ROWIDs that match the condition.
select dbms_xmlgen.getxml('
select rowid
from test_tab where '||test_statement) xml_results
from test_tab
)
where xml_results is not null
)
cross join
xmltable
(
'/ROWSET/ROW'
passing xml_results
columns
the_rowid varchar2(128) path 'ROWID'
)
);