【问题标题】:If any column has NULL value in oracle forms then how the next row to be inserted如果任何列在 oracle 表单中具有 NULL 值,那么如何插入下一行
【发布时间】:2017-06-30 18:11:03
【问题描述】:
如果任何列在 oracle 表单中具有 NULL 值,那么如何插入下一行。
empID city
1001 NYC
1002 DC
1003 CA
1004 NULL
1005 LA
1006 PL
这里在第 4 列 NULL 值存在于 Oracle 表单中。如果我们插入下一个值然后它恢复到第 4 行意味着 LA 转移到第 4 行 & PL转移到第 5 行。我们怎样才能使插入的行在 Oracle 表单中向上移动?
【问题讨论】:
标签:
sql
oracleforms
oraclereports
【解决方案1】:
您可以使用lag( . . . ignore nulls):
select empID,
coalesce(city, lag(city ignore nulls) over (order by empID)) as city
from t;
如果您确实想要更新,可以使用相关子查询:
update t
set city = (select max(t2.city) keep (dense_rank first order by t2.empID desc)
from t t2
where t2.empID < t.empId
)
where city is null;