Oracle存储过程中EXECUTE IMMEDIATE用法

2021/11/11 2:13:40

本文主要是介绍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;

     



这篇关于Oracle存储过程中EXECUTE IMMEDIATE用法的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!


扫一扫关注最新编程教程