微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

Oracle存储过程中EXECUTE IMMEDIATE用法

  • execute immediate:动态解析sql语句
    CREATE OR REPLACE PROCEDURE PRO_test() IS
      V_sql VARCHAR2(2000) := '';
      V_NUM NUMBER;
    BEGIN
      --EXECUTE IMMEDIATE用法1:立刻执行
      V_sql := 'create or replace view mytest as select employee_id, first_name from employees';
      EXECUTE IMMEDIATE V_sql;
      --EXECUTE IMMEDIATE用法2:立刻执行,并赋值给某变量
      V_sql := 'select count(1) from employees';
      EXECUTE IMMEDIATE V_sql;
      INTO V_NUM;
      --EXECUTE IMMEDIATE用法3:带参数的sql
      V_sql := 'select * from employees e where e.employee_id = :1 and first_name = :2';
      EXECUTE IMMEDIATE V_sql;
      USING 200, 'Jennifer';
    END PRO_TEST;

     

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐