次のスクリプトを使用して基本情報を返します。このスクリプトは、私は私の選択にしてLISTAGGを追加するときに、報告書はわずか55行を返し、65行(予想通り)...Oracle SQL:listaggの結果がないときにnull値を返します。
select unique
trunc(li.cre_dat) cre_date,
li.cre_usr,
li.catnr,
li.av_part_no,
li.artist,
li.title,
li.prodtyp,
li.packtyp,
nvl(sp.name_for_customer,sp.name) pack_type
from leos_item li,
scm_packtyp sp
where li.cunr in ('816900','816901','816902')
and li.item_type = 'FP'
and li.av_part_no is null
and trunc(li.cre_dat) >= '01-JAN-2016'
and li.model_force_creation_idc != 'Y'
and li.i_status != 'I'
and li.packtyp = sp.packtyp
を返す...しかし。 10行にはlistaggの結果がないため、結果から省略されます。
select unique
trunc(li.cre_dat) cre_date,
li.cre_usr,
li.catnr,
li.av_part_no,
li.artist,
li.title,
li.prodtyp,
li.packtyp,
nvl(sp.name_for_customer,sp.name) pack_type,
regexp_replace(listagg(nvl(bom.av_part_no,'No'), ', ')
within group (order by bom.item_id),'([^,]+)(,\1)+', '\1') masters
from leos_item li,
scm_packtyp sp,
TABLE(leos_flatbom_pkg.GetFlatBOM(li.item_id)) bom,
leos_item li1
where li.cunr in ('816900','816901','816902')
and li.item_type = 'FP'
and li.av_part_no is null
and trunc(li.cre_dat) >= '01-JAN-2016'
and li.model_force_creation_idc != 'Y'
and li.i_status != 'I'
and li.packtyp = sp.packtyp
and bom.item_id = li1.item_id
and li1.item_type = 'MT'
group by li.cre_dat,
li.cre_usr,
li.catnr,
li.av_part_no,
li.artist,
li.title,
li.prodtyp,
li.packtyp,
nvl(sp.name_for_customer,sp.name)
しかし、これらの行も参照する必要があります。 listaggの結果が見つからない場合に10行を返す方法があります。私は、ヌルとnvlの以下の組み合わせを試しましたが、運がありません。
nullif(regexp_replace(listagg(nvl(bom.av_part_no,'No'), ', ') within group (order by bom.item_id),'([^,]+)(,\1)+', '\1'),'No Master')
nvl(regexp_replace(listagg(nvl(bom.av_part_no,'No'), ', ') within group (order by bom.item_id),'([^,]+)(,\1)+', '\1'),'No Master')
あなたがトンで、おそらくいくつかのサンプルデータをポスト構築または小さなテーブル定義することができますあなたの問題を示す文を挿入するものはほとんどありません。私はhr employeesテーブルで小さなlistaggを試して、nullが返されました。部門番号を にして を にグループ (注文番号hire_date、last_name)を入力してください。 –