组合三个选择语句以提供单个输出

时间:2019-01-21 12:57:08

标签: sql oracle

我正在尝试为Oracle数据库中的数据库角色创建一份报告,该报告需要 $old_article = trim(strip_tags($request->article)); $old_article_word_count = count($old_article ); $words_from_database_array= Words::all(); $article_will_replace = trim(strip_tags($request->article)); $count_the_replaced_words = 0; foreach($words_from_database_array as $word){ $article_will_replace = preg_replace('/[^a-zA- ZğüşıöçĞÜŞİÖÇ]\b'.$word['word'].'\b\s/u', " <b>".$word['spin']."</b> ", $article_will_replace ); $count_the_replaced_words = preg_match_all('/[^a-zA- ZğüşıöçĞÜŞİÖÇ]\b'.strip_tags($word['spin']).'\b\s/u',$article_will_replace ); if($count_the_replaced_words ){ $count_the_replaced_words ++; } } 。为此,准备了三个选择:

select "DB Name", "Hostname", Grantee, Granted_role

问题是否可以将它们组合并生成单个报告表:

select name from v$database;

select host_name from v$instance;

select distinct(grantee), granted_role from dba_role_privs order by 1;

有人可以提供任何提示吗? 谢谢!

1 个答案:

答案 0 :(得分:0)

您可以使用联接来执行此操作,但是标量子查询缓存意味着在选择列表中使用标量子查询可能会更快,因为它们会被查询一次,然后对所有行重复使用值,例如:

SELECT DISTINCT (SELECT NAME
             FROM   v$database) db_name,
            (SELECT host_name
             FROM   v$instance) host_name,
            grantee,
            granted_role
FROM   dba_role_privs
ORDER  BY 1;