我有这个查询从多个表中提取数据。
SELECT ph.list_header_id
,phtl.name
,mtl.segment1
,mtl.description
,pl.list_price_uom_code
,pl.price_break_type_code
,pl.list_price
,ph.currency_code
,pl.start_date_active
,pl.end_date_active
FROM qp_list_headers_b ph
LEFT OUTER JOIN qp_list_headers_tl phtl ON phtl.list_header_id = ph.list_header_id
AND phtl.language = userenv('LANG')
LEFT OUTER JOIN qp_list_lines pl ON pl.list_header_id = ph.list_header_id
LEFT OUTER JOIN mtl_parameters mp ON mp.master_organization_id = mp.organization_id
LEFT OUTER JOIN mtl_system_items_b mtl ON mtl.inventory_item_id = pl.inventory_item_id
AND mtl.organization_id = mp.organization_id
WHERE ph.list_header_id BETWEEN :p_header_id_start AND :p_header_id_end
AND pl.start_date_active BETWEEN :p_start_date AND :p_end_date
问题在于,如果日期中有空值,则不会拉出该行(当它们为空时也适用于其他列)
如何解决此问题?非常感谢
答案 0 :(得分:3)
您可以从
更改最后一个条件AND pl.start_date_active BETWEEN :p_start_date AND :p_end_date
到
AND (
pl.start_date_active IS NULL
OR pl.start_date_active BETWEEN :p_start_date AND :p_end_date
)