sql 占位符行
sql placeholder rows
我有一个顶点项 P_USERS
,它的值可以高于从下面的查询返回的行数。
我有一份经典报告,其中包含以下查询:
select
first_name,
last_name
from accounts
where account_role = 'Author'
order by account_nr;
如果查询中的总行数小于 apex_item
中的值,我希望将占位符行添加到查询中(first_name = null
、last_name = null
等) P_USERS
.
关于如何实现这一目标的任何提示?也许用 LEFT join
?
您可以尝试使用 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
如果您的结果多于您定义的最小值,则必须将其余部分与并集相加。
以下是您可以根据自己的情况尝试调整的内容:
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
我有一个顶点项 P_USERS
,它的值可以高于从下面的查询返回的行数。
我有一份经典报告,其中包含以下查询:
select
first_name,
last_name
from accounts
where account_role = 'Author'
order by account_nr;
如果查询中的总行数小于 apex_item
中的值,我希望将占位符行添加到查询中(first_name = null
、last_name = null
等) P_USERS
.
关于如何实现这一目标的任何提示?也许用 LEFT join
?
您可以尝试使用 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
如果您的结果多于您定义的最小值,则必须将其余部分与并集相加。
以下是您可以根据自己的情况尝试调整的内容:
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