新手上路343 2017-04-13 10:06
浏览 399

求大神指点,oracle函数转化为sql

函数如下:
CREATE OR REPLACE FUNCTION FUN_GET_ROLESOFUSER(v_emp_id in number , in_type in number) -- 获取当前用户所有角色
RETURN VARCHAR2 is
return_roles VARCHAR2(10240);
v_code varchar2(128);
v_name varchar2(128);
v_name_split varchar2(128);
v_code_split varchar2(128);
cursor role_cur is
select distinct r.ROLE_ID, r.ROLE_NAME from tbl_user_role ur join tbl_role r on ur.ROLE_ID = r.ROLE_ID
where ur.emp_id = v_emp_id;
BEGIN
-- in_type = 1 , 返回 角色name列表(逗号隔离)
-- in_type = 2 , 返回 角色id列表(逗号隔离)
return_roles:='';
v_name_split:='
';
v_code_split:=',';
open role_cur;
loop
fetch role_cur
into v_code, v_name;
exit when role_cur%notfound;
if in_type = 1 then
return_roles := return_roles || v_name ||v_name_split;
elsif in_type = 2 then
return_roles := return_roles || v_code ||v_code_split;
else
return_roles := return_roles || v_code ||v_code_split;
end if;
end loop;
close role_cur;
-- 去尾逗号
if in_type = 1 and length(v_name_split)>0 and length(return_roles)-length(v_name_split)>0 then
return_roles := substr(return_roles,0,length(return_roles)-length(v_name_split));
elsif in_type = 2 and length(v_code_split)>0 and length(return_roles)-length(v_code_split)>0 then
return_roles := substr(return_roles,0,length(return_roles)-length(v_code_split));
end if;
return(return_roles);
exception
when others then
return null;
END FUN_GET_ROLESOFUSER;

  • 写回答

0条回答 默认 最新

      报告相同问题?

      悬赏问题

      • ¥80 关于海信电视聚好看安装应用的问题
      • ¥15 vue引入sdk后的回调问题
      • ¥15 求一个智能家居控制的代码
      • ¥15 ad软件 pcb布线pcb规则约束编辑器where the object matpcb布线pcb规则约束编辑器where the object matchs怎么没有+15v只有no net
      • ¥15 虚拟机vmnet8 nat模式可以ping通主机,主机也能ping通虚拟机,但是vmnet8一直未识别怎么解决,其次诊断结果就是默认网关不可用
      • ¥20 求各位能用我能理解的话回答超级简单的一些问题
      • ¥15 yolov5双目识别输出坐标代码报错
      • ¥15 这个代码有什么语法错误
      • ¥15 给予STM32按键中断与串口通信
      • ¥15 使用QT实现can通信