欢迎各位兄弟 发布技术文章
这里的技术是共享的
6 Replies
Last updated on October 08, 2013
This question is 
declare
   v_sql varchar2(2000);
   v_type varchar2(8);
 begin
   v_type := '100';
   v_sql := 'insert into t_emp(id, name)'
     || 'select id, name from tmp_tab where calc_type = ''' || v_type || '''';
   ---(1)
   execute immediate v_sql;
   ---(2)
   execute immediate '
     insert into t_emp(id, name)
     select id, name from tmp_tab where calc_type = :calc_type
     '
     using v_type;
 end;
 
上面两部分execute immediate,一个对应sql未使用变量绑定,一个使用变量绑定,两者性能上是否有明显区别,使用绑定变量的是否对应再次执行就不用硬解析了呢?
直接使用程序调用SQL执行(使用变量绑定),与execute immediate使用变量绑定(上面(2)部分的execute immediate 用法)性能有明显差别吗?主要差别在哪里?
insert into t_emp(id, name)
     select id, name from tmp_tab where calc_type = ?
有一个功能,会频繁调用SQL,想判断或分析一下execute immediate 对性能是否有影响,影响多大,然后决定是否使用此方案。
谢谢!
来自 https://www.oracle.com/webfolder/community/%E4%B8%AD%E6%96%87%E7%A4%BE%E5%8C%BA/3386316.html