我有一张这样的表:
table_name SQL_statement id_value result
employee select ... where ..= :1 101
customer select ....where ..= :1 903
我知道我可以使用EXECUTE IMMEDIATE,但这会在SGA中创建硬分析。
这里可以使用哪种BULK技术?
答案 0 :(得分:0)
如果您可以假设语句始终使用固定别名提取单个值,则可以尝试以下操作。
<强>设置:强>
create table yourTable(table_name varchar2(30), SQL_statement varchar2(100), id_value number, result number);
insert into yourTable
(
select 'employee', 'select :1 *2 as result from dual', 1, null from dual union all
select 'customer', 'select :1 as result from dual', 10, null from dual
);
给定别名result
,您可以使用单个更新语句。
<强>更新强>
update yourTable
set result = extractvalue(xmltype(dbms_xmlgen.getxml(replace (SQL_statement, ':1', id_value))),'/ROWSET/ROW/RESULT')
<强>结果:强>
SQL> select *
2 from yourTable;
TABLE_NAME SQL_STATEMENT ID_VALUE RESULT
---------- ---------------------------------------- ---------- ----------
employee select :1 *2 as result from dual 1 2
customer select :1 as result from dual 10 10