如何创建一个可以按所有者显示我的对象总数的选择?

时间:2019-02-22 22:31:33

标签: sql oracle select oracle11g oracle-sqldeveloper

我正在学习sql,我有这句话:

select owner, object_name, object_id, object_type, status, last_ddl_time 
from dba_objects;

向我展示所有对象,但是我想要类似的东西:

  • 用户安全
  • 表格:#
  • 观看次数:#
  • 触发器:#
  • 无效的触发器:#

谢谢。

1 个答案:

答案 0 :(得分:0)

使用条件聚合:

SELECT
    owner,
    SUM(DECODE(object_type, 'TABLE', 1, 0)) "Tables #",
    SUM(DECODE(object_type, 'VIEW', 1, 0)) "View #",
    SUM(DECODE(object_type, 'TRIGGER', 1, 0)) "Triggers #",
    SUM(CASE WHEN object_type = 'TRIGGER' AND status = 'INVALID' THEN 1 ELSE 0 END) "Invalid Triggers #"
FROM dba_objects
GROUP BY owner