sql - Oracle: Mixing NVL with Outer Join -


i've got following query.

the "left" table 1 alias "o".

i want specify following. how can do? should use temp construct?

and (   nvl (domb.domb_conto_corrente, ' ') != o.campo43 or nvl (abi.abi_descrizione, ' ') != o.campo41 or nvl (cab.cab_descrizione, ' ') != o.campo42) 

here's complete statement:

  select /*+ parallel(o 64) */         o.stato, count (1)     conf_raggruppamenti_forn rgf,          crd_rid_rel_domiciliazione crrd,          crd_domiciliazioni domb,          uff_abi abi,          uff_abi_cab cab,          conto_cliente_t809 o,          eni_flussi_hub c,          eni_monitor mon        1 = 1          --rgf - out          , rgf.rgf_codice_raggruppamento(+) = o.campo1          --join tra out e la eni_flussi_hub          , o.id_messaggio = c.flh_id_messaggio(+)          , o.d_pubblicazione = c.flh_data_elaborazione(+)          --join tra eni_flussi_hub e eni_monitor          , c.flh_id_messaggio = mon.mon_id_messaggio(+)          , c.flh_tipo_processo_cod = mon.mon_cod_tp_processo(+)          , c.flh_flag_ann(+) = 'n'          , mon_flag_ann(+) = 'n'          --join da rgf domb          , rgf.uitr_ident_tipi_raggr_id(+) = 'mp'          , rgf.rgf_raggruppamento_forn_id = crrd.rgf_raggruppamento_forn_id(+)          , crrd.domb_domiciliazione_id = domb.domb_domiciliazione_id(+)          , crrd.crrd_rid_rel_dom_id = crrd.crrd_storico_id          , crrd.crrd_flag_ann (+) = 'n'          , domb.domb_flag_ann (+) = 'n'          , rgf.rgf_flag_ann(+) = 'n'          --join tra domb e abi e cab          , domb.abi_id = abi.abi_id(+)          , domb.cab_id = cab.cab_id(+)          --filtro sulle date          , o.d_pubblicazione between to_date ('06-apr-2013')                                    , to_date ('14-apr-2013')          --solo flussi che producono variazioni          , (   nvl (domb.domb_conto_corrente, ' ') != o.campo43               or nvl (abi.abi_descrizione, ' ') != o.campo41               or nvl (cab.cab_descrizione, ' ') != o.campo42) group o.stato 

if can, recommend rewriting query in modern ansi syntax. makes query not more readable, it's easier apply predicates on optional table in clear manner. i've rewritten 'old' oracle queries , it's quick cut , paste job move join conditions where clause from ... join ... on ... clause.

then, predicates apply optional table listed under outer join condition, not under where. example (in very rough example):

select    mt.col1,    mt.col2,    ot.col3   -- other columns ... main_table mt left outer join optional_table ot on mt.col1 = ot.col1    , ot.col2 = 'n'    , nvl (ot.some_column, 'x') != mt.col5 -- result set , main table  , mt.col4 between to_date ('06-apr-2013') , to_date ('14-apr-2013') -- other conditions on total result set. 

i've found easiest way apply conditions optional table without excluding rows final set.


Comments

Popular posts from this blog

linux - Does gcc have any options to add version info in ELF binary file? -

android - send complex objects as post php java -

charts - What graph/dashboard product is facebook using in Dashboard: PUE & WUE -