oracle 绑定变量

不太喜欢看到在procedure用||拼接sql的语句

所以贴了个绑定变量的例子,仅供参考

create or replace procedure using_test(t_name nvarchar2) as
  v_id char;
  v_sex  char;
begin
  execute immediate '
        select id,sex  from test_zyy
        where name=:1'
        into v_id, v_sex

    using t_name;
  dbms_output.put_line('ID:' || v_id || '性别:' || v_sex);
exception
  when others then
    dbms_output.put_line('找不到相应信息!');
end using_test;

 有人说过程会自定优化代码,呵呵,不知道这是道听途说,还是真nb看过代码

 反正我是不知道,但是有个Alter system set cursor_sharing=similar 的语句可以强制使用共享区,

让硬解析的写法转化为软解析-绑定变量。但是这种方法不推荐用,因为在一些条件下,会更加降低执行速度,

最明显的例子就是分页 rownum这样的东东。

猜你喜欢

转载自blackproof.iteye.com/blog/1685674