当前位置: 代码迷 >> Oracle开发 >> oracle中的select into语句的动态查询解决方案
  详细解决方案

oracle中的select into语句的动态查询解决方案

热度:41   发布时间:2016-04-24 07:55:42.0
oracle中的select into语句的动态查询
具体的意思是这样的:
CREATE   OR   REPLACE   FUNCTION   testExecute   RETURN   NUMBER   IS
tmpVar   NUMBER;
sqltemp   varchar2(200);
 
BEGIN
      tmpVar   :=   0;
     
      sqltemp   :=   'select   count(*)   into   tmpVar   from   gg_book   ';
     
      --execute   immediate   sqltemp;
     
      select   count(*)   into   tmpVar   from   gg_book;
     
     
      RETURN   tmpVar;
     
END   testExecute;

我使用--execute   immediate   sqltemp;就提示错误,请那位大哥给点提示,谢谢了!

------解决方案--------------------
execute immediate 主要用来执行DDL,函数中不能使用DDL。
查询时直接执行select into即可,不要用execute immediate。
------解决方案--------------------
execute immediate
用来执行单行操作。select into属于当行操作时可行的!
------解决方案--------------------
sqltemp := 'select count(*) from gg_book ';

execute immediate sqltemp into tmpVar; --应该这样使用
  相关解决方案