Oracle中的动态SQL的execute immediate 的各种语法

查询语句:
单条记录:
execute immediate 
'select a.dummy from dual' into v_dummy;

多条记录:
execute immediate 
'select dbms_random.value(0,1) from dual connect by rownum <= 10' 
bulk collect into v_dummy;

使用绑定变量:
execute immediate 
'select dbms_random.value(0,1) from dual connect by rownum <= :1' 
bulk collect into v_dummy
using rowcnt;

更新语句:
更新并获取单个所更新记录:
execute immediate 
'update test t set t.flag = 1 where t.id = 10 returning t.name into :1'
returning into v_name;

更新并获取多个所更新记录:
execute immediate 
'update test t set t.flag = 1 where t.name like ''jack%'' returning t.name into :1'
returning bulk collect into v_names;
delete和insert 语句与update基本类似。

你可能感兴趣的:(总结)