首页 > 数据库技术 > 详细

oracle 函数

时间:2015-10-19 11:03:14      阅读:287      评论:0      收藏:0      [点我收藏+]

create or replace function getUserByUnit(ccmsOriginId in number,

                                         indexId      in varchar2)

  return varchar2 is

  str varchar2(4000) default ‘‘;

  i   number default 0;

begin

  for x in (select s.user_id

              from t_sys_unit u, t_sys_staff s

             where u.ccms_origin_id = ccmsOriginId

               and u.node_id = s.org_node_id

               and not exists (select c.alert_config_id

                      from T_YJ_ALERT_CONFIG c

                     where c.unit_id = ccmsOriginId

                       and c.staff_id = s.user_id

                       and c.index_id = indexId)) Loop

    if i <> 0 then

      str := str || ‘,‘;

    end if;

    str := str || x.user_id;

    i   := i + 1;

  end Loop;

  return(str);

end getUserByUnit;



使用:

select t.unit_id,

       t.staff_id,

       t.index_id,

       t.alert_value1,

       t.alert_value2,

       ‘1‘ message_type

  from T_YJ_ALERT_CONFIG t

 where t.staff_id is not null

union all

select t.unit_id,

       getuserbyunit(t.unit_id, t.index_id) staff_id,

       t.index_id,

       t.alert_value1,

       t.alert_value2,

       ‘2‘ message_type

  from T_YJ_ALERT_CONFIG t

 where t.staff_id is null


oracle 函数

原文:http://my.oschina.net/u/2285090/blog/518764

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!