【问题标题】:SQL and OIM - querying against roles on a userSQL 和 OIM - 查询用户的角色
【发布时间】:2020-02-19 22:17:55
【问题描述】:

我正在尝试构建查询,但在一件事上迷路了。我需要根据另一个查询的输出来构建一个输出 true 或 false 的列。我遇到的问题是另一个查询有一个表的输出数据。我从该查询中需要的是,如果它返回某些内容,则为真,否则为假。

如果对我使用 Oracle 的 OIM 数据库有帮助 以下是我需要进行任何更改之前的查询。这将输出过去 7 天内被称为用户的列表。

select usr_login as "User Login", usr_emp_no as "Employee Number", usr_first_name as "First Name", usr_last_name as "Last Name", usr_status as "User Status", 
  to_char(USR_AUTOMATICALLY_DELETE_ON, 'MM/DD/YYYY') USR_AUTOMATICALLY_DELETE_ON, 
  to_char(usr_end_date, 'MM/DD/YYYY') usr_end_date,
  USR_DISPLAY_NAME,
  act.act_name as "Organization Name",
  USR_UDF_PS_EMPL_STATUS as "Employee Status"
from usr, act
where usr_end_date >= to_date(to_char(sysdate - interval '8' day, 'MM/DD/YYYY'), 'MM/DD/YYYY')
  and usr_end_date <= to_date(to_char(sysdate - interval '1' day, 'MM/DD/YYYY'), 'MM/DD/YYYY')
  and usr.act_key = act.act_key
order by usr_end_date, usr_login;

对于每个用户,我需要根据该用户返回它所在的列。因此,如果一个用户有角色,则返回 true,而下一个没有角色的用户返回 false。

除非有更好的方法,否则我正在尝试使用此查询来返回真假:

define usr_login = '&usr_login'
select ugp.ugp_name, ugp.ugp_key, usr.usr_key, usr.usr_login, usr.usr_status
from usg, ugp, usr
where usr.usr_key = usg.usr_key and ugp.ugp_key = usg.ugp_key and
    upper(usr.usr_login) = upper('&usr_login')
    and ugp.ugp_name != 'ALL_USERS' -- I need to exclude the role "All Users"
order by usr.usr_status, ugp.ugp_name, usr.usr_login, usr.usr_status;

我的思路是这样的:

(NVL((select usr_login from usr where usr_login=UPPER('non-existantValue')),'False')) as "dumb", --Working if null(expression,ifnull, do this)This outputs as false

但我非常愿意接受建议。

为了使这更复杂,我真的需要使用上面的第二个查询来工作。如果用户有角色,则返回 true。如果用户没有,则返回 false。

注意:我在 Oracle SQL Developer 中工作

有什么帮助或建议吗? 谢谢!

【问题讨论】:

    标签: sql oracle oracle-sqldeveloper user-management oim


    【解决方案1】:

    您可以包含 CASE 语句

    select usr_login as "User Login", usr_emp_no as "Employee Number", usr_first_name as "First Name", usr_last_name as "Last Name", usr_status as "User Status", 
      to_char(USR_AUTOMATICALLY_DELETE_ON, 'MM/DD/YYYY') USR_AUTOMATICALLY_DELETE_ON, 
      to_char(usr_end_date, 'MM/DD/YYYY') usr_end_date,
      USR_DISPLAY_NAME,
      act.act_name as "Organization Name",
      USR_UDF_PS_EMPL_STATUS as "Employee Status",
      CASE WHEN (SELECT unique USR_KEY FROM USG WHERE UGP_KEY > 3 and USG.USR_KEY = USR.USR_KEY) is null THEN 'FALSE' ELSE 'TRUE' END AS "HAS ROLE"
    from usr, act
    where usr_end_date >= to_date(to_char(sysdate - interval '8' day, 'MM/DD/YYYY'), 'MM/DD/YYYY')
      and usr_end_date <= to_date(to_char(sysdate - interval '1' day, 'MM/DD/YYYY'), 'MM/DD/YYYY')
      and usr.act_key = act.act_key
    order by usr_end_date, usr_login;
    

    【讨论】:

    • 我应该注意具有键 1、2、3 的 3 个系统角色是系统管理员、操作员和所有用户
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-06-17
    • 2011-02-17
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多