Объединить две таблицы с разными столбцами без нулевых значений - PullRequest
0 голосов
/ 01 апреля 2020

снова здесь, чтобы попросить помощи - я работаю с двумя Oracle таблицами

У меня есть эта проблема (изображение-1)

enter image description here

имея две таблицы с разными столбцами, я сделал объединение всех и получил результат, который вы видите на изображении-1. Это мой запрос:

(select td.DETALLE col1, 
           tg.FININ col2, 
           tg.ffinn col3,
           null as col4
    from table_1 tg
    inner join other_table td on (tg.cod_f = td.fol and tg.prod_c = td.prod)
    where UPPER(tg.sys_user) = UPPER(:APP_USER)
      and td.fol = :P10_FOLLETO
      and td.prod = :P10_PRODUCTO
      and tg.fin = :P10_FECHA_INICIO)
    union all 
    (select null as col1
          ,null as col2
          ,null as col3
          ,camp.camp_util.get_data(:P10_FOLLETO, :P10_PRODUCTO, :P10_FECHA_INICIO) as col4 -- This is a FUNCTION from another schema that will return in this case just MAD
    from dual);

, но мой результат mut быть:

enter image description here

Примечание: каждый запрос будет возвращать одну строку, по этой причине я хочу сгруппировать все в одну строку.

Может кто-нибудь мне помочь?

С уважением

1 Ответ

2 голосов
/ 01 апреля 2020

Я думаю, что вы не хотите union, а один выбор с вызовом функции:

select td.DETALLE col1, 
       tg.FININ col2, 
       tg.ffinn col3,
       camp.camp_util.get_data(:P10_FOLLETO, :P10_PRODUCTO, :P10_FECHA_INICIO) as col4
from table_1 tg
inner join other_table td on (tg.cod_f = td.fol and tg.prod_c = td.prod)
where UPPER(tg.sys_user) = UPPER(:APP_USER)
  and td.fol = :P10_FOLLETO
  and td.prod = :P10_PRODUCTO
  and tg.fin = :P10_FECHA_INICIO
...