Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/sql/79.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Oracle SQL-使用合并函数_Sql_Oracle_Coalesce - Fatal编程技术网

Oracle SQL-使用合并函数

Oracle SQL-使用合并函数,sql,oracle,coalesce,Sql,Oracle,Coalesce,我真的无法理解凝聚函数。。。或者这是我想要达到的结果的最好方式 在下面的脚本中,我有三个日期:iv.dated,iv1.dated,dh.actshpdate。当我运行以下脚本时,日期如预期的那样在单独的列中 select unique li.catnr, li.av_part_no, li.artist||' / '||li.title description, li.cust_catnr pallet_ref, trunc(iv.dated), trunc(iv1.dated), trunc

我真的无法理解凝聚函数。。。或者这是我想要达到的结果的最好方式

在下面的脚本中,我有三个日期:iv.dated,iv1.dated,dh.actshpdate。当我运行以下脚本时,日期如预期的那样在单独的列中

select unique li.catnr, li.av_part_no, li.artist||' / '||li.title description, li.cust_catnr pallet_ref,
trunc(iv.dated), trunc(iv1.dated), trunc(dh.actshpdate)
from leos_item li
left join invtran_view_oes iv
    on li.av_part_no = iv.part_no 
    and (iv.transaction = 'NREC' and iv.location_no = '        RETURNS    W')
left join invtran_view_oes iv1
    on li.av_part_no = iv1.part_no
    and (iv1.transaction = 'CORR+' and iv1.remark like 'STOCK FROM SP PALLET%')
left join oes_delsegview od
    on od.catnr = li.catnr
    and od.prodtyp = li.prodtyp
    and od.packtyp = li.packtyp
left join oes_dpos dp
    on od.ordnr = dp.ordnr
    and od.posnr = dp.posnr
    and od.segnr = dp.segnr
left join oes_dhead dh
    on dp.dheadnr = dh.dheadnr
where li.cunr = '816900'
and substr(li.catnr,1,5) in ('RGMCD','RGJCD')
and li.item_type = 'FP'
and li.catnr = 'RGJCD221'
我想实现的是一个列,所有日期按日期顺序排列。 我试着用

trunc(coalesce(iv.dated, iv1.dated, dh.actshpdate)) transaction_date
。。。但是,我丢失了一些日期

如何才能达到以下效果

您可以通过以下方式使用UNION-

WITH DATA AS(
<your query goes here>
)
SELECT A, b, c, d, e FROM DATA
UNION
SELECT A,b,c,d,f FROM DATA
UNION
SELECT A,b,c,d,g FROM DATA

其中a、b、c、d、e、f、g是原始查询中选择列表的列别名。您可以在UNION查询中提供自己的列别名。

coalesce将从传递给它的参数中返回第一个非空值,因此它无法执行您想要执行的操作。是否有方法将日期整理到一列中?使用UNION,请参阅我的答案。如[Oracle文档][1]中所述,COALESCE返回表达式列表中的第一个非空表达式。因此,如果iv.dated、iv1.dated、dh.actshpdate中有超过1个非空日期,则只会使用第一个日期,而其他日期值将丢失。[1]: