sql占位符行

时间:2018-08-29 08:42:18

标签: oracle join oracle-apex placeholder

我有一个顶点项目P_USERS,其值可以比下面的查询返回的行数高。

我有一个经典报告,其中包含以下查询:

  select 
       first_name,
       last_name
  from  accounts
  where account_role = 'Author'
  order by account_nr;

如果查询的总行数小于first_name = null {{的值,我希望将占位符行添加到查询(last_name = nullapex_item等)中1}}。

有关如何实现此目标的任何提示?也许使用P_USERS

2 个答案:

答案 0 :(得分:1)

您可以尝试使用LEFT JOIN

首先,创建一个数字列表,直到达到所需的限制,例如suggested here

-- let's say you want 300 records
Select Rownum r From dual Connect By Rownum <= 300

然后,您可以使用它退出联接并保留空白记录:

SELECT C, R FROM  
  ( select rownum i, c from (select  'a' c from dual union all select 'b' from dual) )
, ( Select Rownum r From dual Connect By Rownum <= 300)
where i(+)= r order by r

上面的代码为您提供了一个以'a','b'开头,然后为null直到结尾的有序列表。

因此您可以根据自己的情况进行调整,以便:

SELECT F,L FROM  
  ( select rownum i, f, l from (
             select first_name f, last_name l 
               from  accounts where account_role = 'Author'
            order by account_nr) )
, ( Select Rownum r From dual Connect By Rownum <= 300)
where i(+)= r

答案 1 :(得分:1)

如果结果超出定义的最小值,则必须将其余部分与并加。

以下是您可以尝试适应情况的方法:

  SELECT i,c FROM  (
select rownum i, c from (
select  'a' c from dual union all select 'b' from dual union all select 'd' from dual union all select 'be' from dual
)), (Select Rownum r From dual Connect By Rownum <= 3)
where (i(+)= r)
union select i,c from (select rownum i, c from (
select  'a' c from dual union all select 'b' from dual union all select 'd' from dual union all select 'be' from dual
)) where i>3