SELECT CAST (p.id AS NUMBER (10)) id,
          p.anlaegs_navn,
          p.virksomhedstype_tekst,
          b.borid,
          bb.dgunr dgu_nr,
          p.indtag_nr,
          b.aktiv_indvinding_jn,
          CAST (p.indtag_top_dybde AS NUMBER (7, 2)) indtag_top_dybde,
          al.lang_tekst boringsanvendelse,
          TO_CHAR (p.dato_seneste, 'YYYY-MM-DD') dato_seneste,
          CAST (p.antal_pejlinger AS NUMBER (7)) antal_pejlinger,
          CAST (p.klassifikation AS NUMBER (3)) klassifikation,
          TO_CHAR (p.dato_foerste, 'YYYY-MM-DD') dato_foerste,
          CAST (p.kote_seneste AS NUMBER (7, 2)) kote_seneste,
          CAST (p.median_kote AS NUMBER (7, 2)) median_kote,
          CAST (p.max_kote AS NUMBER (7, 2)) max_kote,
          TO_CHAR (p.dato_max_kote, 'YYYY-MM-DD') dato_max_kote,
          CAST (p.min_kote AS NUMBER (7, 2)) min_kote,
          TO_CHAR (p.dato_min_kote, 'YYYY-MM-DD') dato_min_kote,
          CAST (p.stddev_kote AS NUMBER (7, 2)) stddev_kote,
          CAST (p.diff_max_min AS NUMBER (7, 2)) diff_max_min,
          CAST (p.synkron AS NUMBER (7)) synkron,
          CAST (p.vsp_mtu_seneste AS NUMBER (7, 2)) vsp_mtu_seneste,
          p.overanlaegs_navn,
          CAST (p.anlaeg_id AS NUMBER (10)) anlaeg_id,
          p.virksomhedstype_kode,
          CAST (p.kommune_nr AS NUMBER (5)) kommune_nr,
          p.kommune_navn,
          ml.kode mc_kode,
          ml.lang_tekst mc_navn,
          rl.kode region_kode,
          rl.lang_tekst region_navn,
          fl.lang_tekst boringsformaal,
          p.indtag_anvendelse_tekst,
          bb.zdvr90 terraen_kote,
          bb.boringsdybde,
          bb.xutm32euref89,
          bb.yutm32euref89,
          p.indtag_top_dybde_forklaret,
          CAST (p.indtag_bund_dybde AS NUMBER (7, 2)) indtag_bund_dybde,
          p.indtag_bund_dybde_forklaret,
          p.indtags_bjergart,
          p.akvitard_over_indtag_m,
          p.magasin_over_indtag_m,
          p.ukendt_over_indtag_m,
          p.boringskvalitet,
          b.hoved_vandopland,
          b.sloejfet_jn,
          TO_CHAR (b.udtraeksdato, 'YYYY-MM-DD') udtraeksdato,
          bs.punkt_utm32 geom,
          NVL (mpf.farve_rgb, '255 255 255') rgb,
          CASE
             WHEN LENGTH (REPLACE (NVL (mpf.farve_rgb, '255 255 255'), ' ')) <
                     7
             THEN
                '255 255 255'
             ELSE
                '0 0 0'
          END
             symbol_rgb,                     -- White label if dark background
          p.symbol,
          p.symbol_size,
          p.symbol_txt_size,
          p.cache_date
     FROM mcportal.mc_boring b
          INNER JOIN bor$boring$v bb
             ON bb.borid = b.borid                          -- fortrolig='nej'
          INNER JOIN bor$boring_spatial bs
             ON bs.borid = b.borid
          LEFT OUTER JOIN gen$miljoecenter_liste ml
             ON ml.kode = bb.miljoecenter
          LEFT OUTER JOIN gen$region_liste rl
             ON rl.kode = bb.region
          LEFT OUTER JOIN bor$formaal_liste fl
             ON fl.kode = bb.formaal
          LEFT OUTER JOIN bor$anvend_liste al
             ON al.kode = bb.anvendelse
          INNER JOIN mcportal.mc_pejling p
             ON b.borid = p.borid
          LEFT OUTER JOIN mc_pejlefarver mpf
             ON mpf.indtags_bjergart = p.indtags_bjergart;