【问题标题】:Displaying two records from two different functions in oracle instead of in a single row在 oracle 中显示来自两个不同函数的两条记录,而不是在一行中
【发布时间】:2020-05-19 18:47:58
【问题描述】:

我在下面写了一个运行良好的函数。并显示记录

select emp_name,
       get_emp_status(emp_id) status_1,
       get_emp_name_dept(emp_id) status_2
from employee;

当前输出为

emp_name -------- status_1 ------ status_2

克莱尔 ---------------- 是 ------------ 否

泰勒 --------------- 没有 ---------------
米奇 --------------- 没有--------------- 是的

但是,我需要显示以下结果。请让我知道如何进行。

需要的预期输出:

emp_name ----- 状态

克莱尔 --------------是的

克莱尔---------------没有

泰勒 --------------没有

米奇---------------没有

米奇 -------------- 是的

【问题讨论】:

  • 泰勒的status_2是什么?它是空白(或 null)吗?
  • 是的。 Taylor 的 status_2 为 NULL。

标签: sql oracle function output record


【解决方案1】:

简单的选择是UNION那些结果:

select emp_name,
       get_emp_status(emp_id) status
from employee
union all
select emp_name,
       get_emp_name_dept(emp_id) status
from employee
order by emp_name, status

【讨论】:

  • 实际上,我的查询已经有几个联合......然后这个作为增强。联合可能需要更长的时间来执行我的大查询。除了Union还有别的选择吗?
  • UNION 可能会减慢速度,因为它返回不同的行。 UNION ALL(我建议)不这样做,它只是返回它获取的内容
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2020-08-20
  • 2014-06-09
  • 2015-07-12
  • 2019-10-26
  • 2017-05-23
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多