日期:2014-05-17  浏览次数:20738 次

Mybatis 调用oracle 效率问题
写了一个function qx(uid,pid)
在某个查询语句中这样写select * from customer where delflag=1 and 1=qx(#{id});
这样会查询很慢。

create or replace function qx(uId varchar2){
   return varchar2 is
 hasXq varchar2(20) :='0';
 adminCount number:=0;
begin
--是否是管理员
  select count(*) into adminCount from user_role where user_id=uId and role_id=1;
 if adminCount>0 then
     hasXq:='1';
  else
     hasXq:='0';
  end if;
  return hasXq;
end;
}

若果不用函数直接这样写select * from customer where delflag=1 and 1=( select count(*)from user_role where user_id=uId and role_id=1)就很快


若果还是想用function该怎么改,才能优化查询效率

------解决方案--------------------
能不用function 还是别用function 吧,,,非要用function 就在业务代码里做处理吧。。。
------解决方案--------------------
你以后要换其他数据库就哭吧
------解决方案--------------------
为什么不用存储过程呢?为什么不建索引呢
------解决方案--------------------
这个是SQL语句的问题了,不是MyBatis的问题。
所以需要你去优化SQL