Oracle 函数中 游标报表或视图不存在

create or replace function get_inner_name(codes varchar2,regex varchar2,tableName varchar2,tempName varchar2,codeName varchar2,temp_type varchar2)
return VARCHAR2 AUTHID CURRENT_USER is names varchar2(4000);
v_temp_name varchar2(300);
v_codes varchar2(4000);
type refcursor is ref cursor;
     result_cursor refcursor;
qry_sql varchar2(4000);

begin
        if (codes is null) then
           return '';
        end if;
        if(codes='') then
           return '';
        end if;
        v_codes := ''''||to_char(replace(codes,regex,''','''))||'''';

         qry_sql := 'select distinct t.'||tempName||' from '||tableName||' t where t.'||codeName||' in('||v_codes||') and '||temp_type;

        open result_cursor for qry_sql;
            loop
                fetch result_cursor  into v_temp_name;
                exit when result_cursor %notfound;
                names := names||','||v_temp_name;
            end loop;
        close result_cursor;
        return substr(names,2);
end get_inner_name;

但是sql单独拿出来是可以查询的,也不报错。

之前没有遇到过,在网上找了找,说是权限有问题,

需要加个AUTHID CURRENT_USER

--AUTHID DEFINER (定义者权限):指编译存储对象的所有者。也是默认权限模式。

--AUTHID CURRENT_USER(调用者权限):指拥有当前会话权限的模式,这可能和当前登录用户相同或不同(alter session set current_schema 可以改变调用者Schema)


更详细的请看:http://blog.csdn.net/indexman/article/details/17067531



猜你喜欢

转载自blog.csdn.net/sinat_23502039/article/details/77557773