oracle 自定义类型

本文介绍了一个用于生成用户权限列表的PL/SQL过程。该过程通过创建两种类型RIGHTOBJECT和RIGHTOBJECTCOLLECTION来组织权限数据,并定义了getuserrightlist函数来收集用户的个人权限和用户组权限。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

ex1:

RIGHTOBJECT是UserID,RightTypeId,UserDutyId,RightId,RightFlag集合类型

CREATE OR REPLACE TYPE "RIGHTOBJECT"                                                                                                                                                                                                                            as object
(
UserID number,
RightTypeID number,
UserDutyID number,
RightID number,
RightFlag number
)

RIGHTOBJECTCOLLECTION 是RIGHTOBJECT的集合类型

CREATE OR REPLACE TYPE "RIGHTOBJECTCOLLECTION"  as table of rightobject

 

用法:

function getuserrightlist(userid      sys_userinfo.userid%type,
                            righttypeid rgt_righttype.righttypeid%type)
    return rightobjectcollection as
    result rightobjectcollection;
  begin
    result := rightobjectcollection();
 
    for mycs in (
                 --个人自定义权限
                 select *
                   from rgt_userright
                  where userid = getuserrightlist.userid
                    and righttypeid = getuserrightlist.righttypeid) loop
      result.extend;
      result(result.count) := rightobject(0, 0, 0, 0, 0);
      result(result.count).userid := mycs.userid;
      result(result.count).righttypeid := mycs.righttypeid;
      result(result.count).rightid := mycs.rightid;
      result(result.count).userdutyid := mycs.userdutyid;
      result(result.count).rightflag := mycs.rightflag;
   
    end loop;
  
 
    --插入个人用户组的权限  
    for mycs in (select rightid,
                        righttypeid,
                        max(rightflag) rightflag,
                        getuserrightlist.userid
                   from rgt_rightgroupcontent
                  where rightgroupid in
                        (select rightgroupid
                           from rgt_usergroupright
                          where usergroupid in
                                (select distinct usergroupid
                                   from sys_groupuser
                                  where userid = getuserrightlist.userid))
                    and righttypeid = getuserrightlist.righttypeid
                    and rightid not in (select rightid from table(result))
                  group by rightid, righttypeid /*,rightgroupid*/) loop
      result.extend;
      result(result.count) := rightobject(0, 0, 0, 0, 0);
      result(result.count).userid := mycs.userid;
      result(result.count).righttypeid := mycs.righttypeid;
      result(result.count).rightid := mycs.rightid;
      result(result.count).rightflag := mycs.rightflag;
    end loop;
   return result;
  end;

转载于:https://www.cnblogs.com/kelly/archive/2008/08/30/1280189.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值