sql - 如果为空则插入数据
问题描述
任何人请帮助我,当程序运行时,我在oracle中有程序表Rekon它从另一个表中获取数据以创建数据,但问题是当 Table Rekon中另一个表中的数据为空(空)时,它是空的,但我仍然想要在我的Rekon表中有数据,例如模板:
NO_ACC|ttrx|Amount
1111 |USD |2200
|SGD |5410
|total|7610
但是当另一个表中的数据在where 子句 substr(NARATION,1,3)='SGD' 中为空时,该表类似于:
NO_ACC|ttrx|Amount
1111 |USD |2200
|total|2200
这是我的查询:
insert into datamart.rekon_801_ugm_sm
select to_char(no_acc) no_acc, 'USD' ttrx, sum(amount) amount from (select
* from rekon_801_ugm where no_acc = 1111 and substr(narasi,9,4)='1112'
or substr(narasi,37,4)='1112') group by no_acc
union all
select to_char(no_acc) no_acc, 'SGD' as ttrx, sum(amount) amount from (select
* from rekon_801_ugm where no_acc = 8010000487 and substr(narasi,9,2)='88'
or substr(narasi,37,2)='88') group by no_acc
union all
select ' ' as no_acc, 'TOTAL TRANSAKSI H2H' as ttrx, sum(amount) amount from (select
* from rekon_801_ugm where no_acc = 1111 and debet_kredit = 'K') group by no_acc
解决方案
如果您想拥有空值,您必须在所有子查询中使用带有常量条件的 acc_no ,您必须将此条件替换为类似
(acc_no=8010000487 或 acc_no 为空)