我想执行查询A,但我想使用查询B执行查询A.实现此目的的一种方法是将查询B的结果假脱机到sql文件并运行。我更愿意使用PL / SQL来完成这项任务。
- 查询A
delete from
tableA
where
id=4;
- 查询B
select 'delete from' as test from dual
union all
select 'tableA' as test from dual
union all
select 'where' as test from dual
union all
select 'id=4'||';' as test from dual
答案 0 :(得分:1)
您可以尝试loop
查询B的陈述,并在最后应用execute immediate
:
SQL> set serveroutput on;
SQL> declare
v_sql varchar2(4000);
begin
for c in ( select 'delete from ' as test from dual
union all
select 'tableA ' as test from dual
union all
select 'where ' as test from dual
union all
select 'id=4' as test from dual )
loop
v_sql := v_sql || c.test;
end loop;
dbms_output.put_line(v_sql);
execute immediate v_sql;
end;
/
答案 1 :(得分:0)
像...一样的东西。
begin
execute immediate 'delete from ta where id = ' || 4 ;
end;
/
或者,如果您想使用某个程序:
create or replace procedure delete_row ( row_ number )
as
begin
execute immediate 'delete from ta where id = ' || row_ ;
end;
/
begin
delete_row( 4 );
end;
/
Dbfiddle here。