Oracle 函式中 遊標報表或檢視不存在
阿新 • • 發佈:2018-11-20
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