Facebook
From Innocent Giraffe, 3 Years ago, written in Plain Text.
Embed
Download Paste or View Raw
Hits: 135
  1. create or replace procedure sys_cron.JOB_SAU_REDE_CREDENCIADA is
  2.  
  3.   CURSOR CurPrinc IS
  4.   /*************************************************************************************************************************/
  5.   /* Criado em 06/07/2016 por iDA                                                                      */
  6.   /* A finalidade deste processo e enviar arquivo CVS da REDE CREDENCIADA  */
  7.   /*                                                                                              */
  8.   /* Este processo devera ser executado  todo dia                                                                       */
  9.   /*************************************************************************************************************************/
  10.   --Corrigido 01/07/2019 - SEN47400PFC
  11.   --Corrigido 30/04/2020 - E40106
  12. select
  13.           '"' || trim(cesp.cod_especialid) || '"' codigo_cbo,
  14.           '"' || trim(pl.cod_plano) || '"' codigo_plano,
  15.           CASE
  16.               WHEN ccl.COD_CLASSE in (20) THEN '"'||'4'||'"'
  17.               WHEN ccl.COD_CLASSE in (31) THEN '"'||'15'||'"'
  18.               WHEN ccl.COD_CLASSE in (25) THEN '"'||'26'||'"'
  19.               WHEN ccl.COD_CLASSE in (25) THEN '"'||'26'||'"'
  20.               WHEN ccl.COD_CLASSE in (27) THEN '"'||'28'||'"'
  21.               WHEN ccl.COD_CLASSE in (24) THEN '"'||'13'||'"'
  22.               WHEN ccl.COD_CLASSE in (23) THEN '"'||'12'||'"'
  23.               WHEN ccl.COD_CLASSE in (41) THEN '"'||'40'||'"'
  24.               ELSE '"'||trim(ccl.cod_classe)      ||'"'
  25.           END AS   classe_prestador,
  26.           '"' || trim(cv.cod_convenente) || '"' codigo_legado,
  27.           '"' || trim(cv.nom_convenente) || '"' nome_prestador,
  28.           '"' || trim(cv.cod_sexo) || '"' sexo,
  29.           '"' || trim(cend.nom_logradouro) || '"' endereco,
  30.           '"' || trim(cend.num_logradouro) || '"' numero,
  31.           '"' || trim(REPLACE(cend.des_complemento,'"','')) || '"' complemento,
  32.           '"' || trim(cend.nom_bairro) || '"' bairro,
  33.           '"' || trim(cend.cod_munici) || '"' codigo_municipio,
  34.           '"' || trim(cend.cod_estado) || '"' codigo_UF,
  35.           '"' || trim(cend.num_cep) || '"' cep,
  36.           '"' || trim(eec.cod_especialid) || '"' Especialidade,
  37.           CASE
  38.               WHEN cend.NUM_DDD is null  or  cend.num_telefone is null THEN '"' || '' || '"'
  39.               else '"' || trim(cend.NUM_DDD) || trim(cend.num_telefone) || '"'
  40.           end as  telefone_primario,
  41.           CASE
  42.               WHEN cend.NUM_DDD2 is null  or  cend.num_telefone2 is null THEN '"' || '' || '"'
  43.               else '"' ||  trim(cend.NUM_DDD2) || trim(cend.num_telefone2) || '"'
  44.           end as telefone_secundario,
  45.           '"' || '' || '"'                   e_mail,
  46.           '"' || trim(cv.des_site) || '"' site,
  47.           '"' || '' || '"' log_marca,
  48.           '"' || trim(cv.num_cgc_cpf) || '"' CNPJ,
  49.           '"' || '' || '"' priorizacao,
  50.           '"' || trim(cend.loc_latitude) || '"' latitude,
  51.           '"' || trim(cend.loc_longitude) || '"' longitude,
  52.           '"' || trim(cend.num_seq_end) || '"' sequencial_endereco,
  53.           TO_CHAR(cv.dat_prev_subst, 'DD/MM/RRRR') dt_bloqueio ,
  54.           '"' || '' || '"' motivo_bloqueio,
  55.           '"' || (select trim(decode(hc.tip_hist, 1, 0, hc.tip_hist))
  56.                   from tb_hist_conv hc
  57.                   where hc.cod_convenente = cv.cod_convenente
  58.                   and hc.num_seq_hist =
  59.                   (select max(hcv.num_seq_hist)
  60.                   from tb_hist_conv hcv
  61.                   where hcv.cod_convenente = hc.cod_convenente)) || '"' operacao,
  62.           '"' || '1.2' || '"' Versao_layout,
  63.           '"' || trim(REPLACE(TRIM(cv.nom_razao_social),CHR(10),' ')) || '"' razao_social,
  64.           '"' || trim(ccl.cod_tipo_conselho) || '"' sigla_conselho,
  65.           '"' || trim(cv.cod_uf_ident_prof) || '"' uf_conselho_regional,
  66.           '"' || trim(cv.num_identidade_prof) || '"' numero_conselho_regional,
  67.           '"' || trim(cv.nom_responsavel) || '"' responsavel_tecnico,
  68.           '"' || '' || '"' facebook, -- verificar onde busca essa informac?o
  69.           '"' || '' || '"' twitter, -- verificar onde busca essa informac?o
  70.           '"' || TRIM(cv.des_observacao) || '"' observacoes, -- verificar onde busca essa informac?o
  71.           '"' || '' || '"' acessibilidade, -- verificar onde busca essa informac?o
  72.           '"' || '' || '"' detalhe_acessibilidade, -- verificar onde busca essa informac?o
  73.           '"' || '' || '"' atend_24_horas, -- verificar onde busca essa informac?o
  74.           '"' || '' || '"' link_agenda_online, -- verificar onde busca essa informac?o
  75.           CASE
  76.           WHEN cv.IDC_REDE_REF = 'S'  and cesp.cod_especialid not in (555,666)THEN
  77.           '"'||'2'||'"'
  78.           WHEN cv.IDC_REDE_REF = 'N'  and cesp.cod_especialid in (555,666) OR (cv.des_observacao collate binary_ai like '%PROJETO REDE ESPECIAL%') THEN
  79.           '"'||'1'||'"'
  80.           else
  81.           '"'||'3' ||'"'
  82.           END AS  secao_resultado        ,
  83.           '"' || '' || '"' regime_atendimento, -- verificar onde busca essa informac?o
  84.           '"' || '' || '"' CNPJ_SBT, -- verificar onde busca essa informac?o
  85.           '"' || '' || '"' CODCBO_SBT,
  86.           '"' || '' || '"' CLASSE_SBT,
  87.           '"' || '' || '"' SEQEND_SBT,
  88.           '"' || '' || '"' EMPRESA_ID,
  89.           '"' || '' || '"' RESERVADO,
  90.           TO_CHAR(cv.dat_ini_contrato, 'DD/MM/RRRR')  DT_INI_ATD,
  91.           to_char(add_months(sysdate, -6), 'dd/mm/yyyy') Hoje_6_menos_meses,
  92.           TO_char(SYSDATE, 'DD/MM/yyyy') hoje,
  93.           '1' teste
  94.     from tb_conv_plano cvp
  95.     join tb_convenente cv
  96.         on cv.cod_convenente = cvp.cod_convenente
  97.        and cv.sit_convenente = '1'
  98.        and cv.cod_classe not in (9, 32, 34, 35, 38, 11, 33, 37,10,14,29)
  99.  
  100.  
  101.     join tb_end_conven cend
  102.         on cend.cod_convenente = cv.cod_convenente
  103.        and cend.idc_end_corresp = 'N'
  104.        and cend.idc_desativado = 'N'
  105.        --FAZ TRAZER APENAS UM ENDETECO DE PRESTADOR
  106.       /* and cend.num_seq_end = (select nvl(max(cend2.num_seq_end), 1) from tb_end_conven cend2
  107.                                where cend2.cod_convenente = cend.cod_convenente
  108.                                  and cend2.idc_end_corresp = 'N'
  109.                                  and cend2.idc_desativado = 'N')*/
  110.     join tb_esp_conven cesp
  111.         on cesp.cod_convenente = cv.cod_convenente
  112.        and cesp.idc_catalogo = 'S'
  113.  
  114.     join tb_classe_conveniado ccl
  115.         on ccl.cod_classe = cv.cod_classe
  116.  
  117.     join tb_plano pl
  118.         on pl.cod_plano = cvp.cod_plano
  119.  
  120.     join (select p.cod_plano
  121.           from tb_plano p,
  122.                tb_regulamento r,
  123.                tb_cobertura c
  124.           where p.cod_plano = r.cod_plano
  125.              and r.cod_cobertura = c.cod_cobertura
  126.              and r.cod_cobertura = 101
  127.              and COALESCE(TO_NUMBER(REGEXP_REPLACE(P.NUM_REGISTRO_PLANO,'[^0-9]+','')),0) <> 0
  128.              and p.cod_plano not in (1,171,172,173,174,175)--lhsia 16/04/2019 n?o enviar extensive - retirar comentario em 09/2019
  129.              and p.cod_plano in (select pp.cod_plano
  130.                                  from tb_particip_plano pp
  131.                                  where pp.cod_plano = p.cod_plano
  132.                                    and pp.sit_partic_plano = 'A')) pl
  133.         on pl.cod_plano = cvp.cod_plano
  134.         --PJED
  135.    left join att.FATTBLEECENDESPCONV eec
  136.       on eec.cod_convenente = cv.cod_convenente
  137.      and eec.cod_especialid = cesp.cod_especialid
  138.      and eec.num_seq_end = cend.num_seq_end
  139.  
  140.     where pl.num_registro_plano is not null
  141.      
  142.       and (cesp.cod_especialid not in
  143.           (122, 121, 131, 155, 123, 124, 641, 852, 858, 125, 126, 127, 128, 129, 154, 156, 851, 132, 850)
  144.        or cesp.cod_especialid = 122 and cv.cod_convenente in (402064, 403822))
  145.       and (cv.cod_convenente <> 402636
  146.        or (cv.cod_convenente = 402636 and pl.cod_plano in (76, 82, 85, 86)))
  147.  
  148.  
  149.       and not exists (select ' '
  150.                       from tb_conv_plano s
  151.                       where s.cod_convenente = cv.cod_convenente
  152.                       and s.cod_plano in (4, 79, 179))
  153.                       or cv.cod_convenente in (402064, 403822)
  154. union
  155. select
  156.             '"' || trim(cesp.cod_especialid) || '"' codigo_cbo,
  157.             '"' || trim(pl.cod_plano) || '"' codigo_plano,
  158.             '"' || decode(ccl.cod_classe, 14, '10', 29, '10', trim(ccl.cod_classe)) || '"' classe_prestador,
  159.             '"' || trim(cv.cod_convenente) || '"' codigo_legado,
  160.             '"' || trim(cv.nom_convenente) || '"' nome_prestador,
  161.             '"' || trim(cv.cod_sexo) || '"' sexo,
  162.             '"' || trim(cend.nom_logradouro) || '"' endereco,
  163.             '"' || trim(cend.num_logradouro) || '"' numero,
  164.             '"' || trim(cend.des_complemento) || '"' complemento,
  165.             '"' || trim(cend.nom_bairro) || '"' bairro,
  166.             '"' || trim(cend.cod_munici) || '"' codigo_municipio,
  167.             '"' || trim(cend.cod_estado) || '"' codigo_UF,
  168.             '"' || trim(cend.num_cep) || '"' cep,
  169.             '"' || trim(eec.cod_especialid) || '"' Especialidade,
  170.             CASE
  171.                 WHEN cend.NUM_DDD is null  and  cend.num_telefone is null THEN '"' || '' || '"'
  172.                 else '"' || trim(cend.NUM_DDD) || trim(cend.num_telefone) || '"'
  173.             end as  telefone_primario,
  174.             CASE
  175.                 WHEN cend.NUM_DDD2 is null  and  cend.num_telefone2 is null THEN '"' || '' || '"'
  176.                 else '"' ||  trim(cend.NUM_DDD2) || trim(cend.num_telefone2) || '"'
  177.             end as telefone_secundario,
  178.             '"' || '' || '"'                   e_mail,
  179.               '"' || trim(cv.des_site) || '"' site,
  180.               '"' || '' || '"' log_marca,
  181.               '"' || trim(cv.num_cgc_cpf) || '"' CNPJ,
  182.               '"' || '' || '"' priorizacao,
  183.               '"' || trim(cend.loc_latitude) || '"' latitude,
  184.               '"' || trim(cend.loc_longitude) || '"' longitude,
  185.               '"' || trim(cend.num_seq_end) || '"' sequencial_endereco,
  186.               TO_CHAR(cv.dat_prev_subst, 'DD/MM/RRRR') dt_bloqueio ,
  187.               '"' || '' || '"' motivo_bloqueio,
  188.               '"' || (select trim(decode(hc.tip_hist, 1, 0, hc.tip_hist))
  189.                       from tb_hist_conv hc
  190.                       where hc.cod_convenente = cv.cod_convenente
  191.                       and hc.num_seq_hist =
  192.                       (select max(hcv.num_seq_hist)
  193.                       from tb_hist_conv hcv
  194.                       where hcv.cod_convenente = hc.cod_convenente)) || '"' operacao,
  195.               '"' || '3.2' || '"' Versao_layout,
  196.               '"' || trim(REPLACE(TRIM(cv.nom_razao_social),CHR(10),' ')) || '"' razao_social,
  197.               '"' || trim(ccl.cod_tipo_conselho) || '"' sigla_conselho,
  198.               '"' || trim(cv.cod_uf_ident_prof) || '"' uf_conselho_regional,
  199.               '"' || trim(cv.num_identidade_prof) || '"' numero_conselho_regional,
  200.               '"' || trim(cv.nom_responsavel) || '"' responsavel_tecnico,
  201.               '"' || '' || '"' facebook, -- verificar onde busca essa informac?o
  202.               '"' || '' || '"' twitter, -- verificar onde busca essa informac?o
  203.               '"' || TRIM(cv.des_observacao) || '"' observacoes, -- verificar onde busca essa informac?o
  204.               '"' || '' || '"' acessibilidade, -- verificar onde busca essa informac?o
  205.               '"' || '' || '"' detalhe_acessibilidade, -- verificar onde busca essa informac?o
  206.               '"' || '' || '"' atend_24_horas, -- verificar onde busca essa informac?o
  207.               '"' || '' || '"' link_agenda_online, -- verificar onde busca essa informac?o
  208.               CASE
  209.                   WHEN cv.IDC_REDE_REF = 'S'  and cesp.cod_especialid not in (555,666) THEN '"'||'2'||'"'
  210.                   WHEN cv.IDC_REDE_REF = 'N'  and cesp.cod_especialid in (555,666) OR (cv.des_observacao collate binary_ai like '%PROJETO REDE ESPECIAL%')
  211.                        THEN '"'||'1'||'"'
  212.                   ELSE '"'||'3' ||'"'
  213.               END AS  secao_resultado,
  214.               '"' || '' || '"' regime_atendimento, -- verificar onde busca essa informac?o
  215.               '"' || '' || '"' CNPJ_SBT, -- verificar onde busca essa informac?o
  216.               '"' || '' || '"' CODCBO_SBT,
  217.               '"' || '' || '"' CLASSE_SBT,
  218.               '"' || '' || '"' SEQEND_SBT,
  219.               '"' || '' || '"' EMPRESA_ID,
  220.               '"' || '' || '"' RESERVADO,
  221.               TO_CHAR(cv.dat_ini_contrato, 'DD/MM/RRRR')  DT_INI_ATD,
  222.               to_char(add_months(sysdate, -6), 'dd/mm/yyyy') Hoje_6_menos_meses ,
  223.               TO_char(SYSDATE, 'DD/MM/yyyy') hoje,
  224.               '2' teste
  225.       From tb_convenente        cv,
  226.            tb_end_conven        cend,
  227.            tb_esp_conven        cesp,
  228.            tb_especialid        es,
  229.            tb_conv_plano        pl,
  230.            municipio            mu,
  231.            tb_classe_conveniado ccl,
  232.            tb_plano             p,
  233.            att.FATTBLEECENDESPCONV eec
  234.  
  235.      Where cv.cod_convenente = cend.cod_convenente
  236.        and cv.cod_convenente = cesp.cod_convenente
  237.        and cesp.cod_especialid = es.cod_especialid
  238.        and cv.cod_convenente = pl.cod_convenente
  239.        and cend.cod_munici = mu.cod_munici
  240.        and cv.cod_classe = ccl.cod_classe
  241.        and cend.idc_end_corresp = 'N'
  242.        and cesp.idc_catalogo = 'S'
  243.        and cv.sit_convenente = '1'
  244.        and cend.idc_desativado = 'N'
  245.        and es.cod_especialid in
  246.            (121, 122, 123, 124, 125, 126, 127, 128, 129, 130, 131, 132, 850, 852, 154, 158, 156, 851)
  247.        and cv.cod_classe in (10, 14, 29)
  248.        and cv.cod_convenente not in (402064, 403822)
  249.        and pl.cod_plano = p.cod_plano
  250.        and p.cod_programa = 2
  251.  
  252.  
  253.        and exists (select ' ' from tb_particip_plano pp
  254.                    where pp.cod_plano = p.cod_plano
  255.                      and pp.sit_partic_plano = 'A')
  256.        and (cv.cod_convenente (+) = eec.cod_convenente
  257.        and cesp.cod_especialid (+) = eec.cod_especialid
  258.        and cesp.cod_especialid(+) = es.cod_especialid
  259.        and cesp.cod_convenente(+) = cend.cod_convenente
  260.        and cend.num_seq_end (+) =  eec.num_seq_end)
  261.  
  262.      order by 5 ;
  263.  
  264.   strLinha     Varchar2(1024);
  265.   strArquivo   Varchar2(80);
  266.   strDiretorio Varchar2(80);
  267.   sgGlobalName       varchar2(1000);
  268.   sgHostName         varchar2(100);
  269.   processou          varchar2(1);
  270.   fHandle      UTL_FILE.FILE_TYPE;
  271.  
  272. BEGIN
  273.   -- Select DIR_DESTINO into strDiretorio from OPPORTUNITY.TB_PARAM_GERAL;
  274.   -- strDiretorio := 'DIR_WORK';
  275.  
  276.     select global_name into sgGlobalName from global_name;
  277.  
  278.          if upper(sgGlobalName) = 'FCESPP.WORLD' then
  279.             select substr(host_name,1,9) into sgHostName from v$instance;
  280.             if lower(sgHostName) = 'fcespracp' then
  281.                sgGlobalName := 'PROD';
  282.                Select DIR_DESTINO into strDiretorio from OPPORTUNITY.TB_PARAM_GERAL;
  283.             elsif upper(sgHostName) = 'FCESPORAH' then
  284.                sgGlobalName := 'NEWTST';
  285.                Select DIR_DESTINO into strDiretorio from OPPORTUNITY.TB_PARAM_GERAL;
  286.             else
  287.                sgGlobalName := 'AMBIENTE DE TESTE';
  288.             end if;
  289.          elsif upper(sgGlobalName) = 'FCESPP.NEWTST' then
  290.             sgGlobalName := 'NEWTST';
  291.              Select DIR_DESTINO into strDiretorio from OPPORTUNITY.TB_PARAM_GERAL;
  292.          elsif upper(sgGlobalName) = 'NEWDEV.WORLD' then
  293.             sgGlobalName := 'NEWDEV';
  294.             strDiretorio:='DIR_WORK';
  295.          end if;
  296.  
  297.  
  298.   strArquivo   := 'gm_ms_redecred_' || TO_CHAR(SYSDATE, 'yyyymmdd') || '_' ||
  299.                   to_char(SYSDATE, 'hh24miss') || '.csv';
  300.   fHandle      := utl_file.fopen(strDiretorio, strArquivo, 'w');
  301.   UTL_FILE.FFLUSH(fHandle);
  302.  
  303.   strLinha := '"codigo_cbo";"codigo_plano";"classe_prestador";"codigo_legado";"nome_prestador";"sexo";"endereco";"numero";"complemento";"bairro";"codigo_municipio";"codigo_uf";"cep";"telefone_primario";"telefone_secundario";"email";"site_url";"nome_logomarca";"cpf_cnpj";"prioridade";"latitude";"longitude";"sequencial_endereco";"data_bloqueio";"motivo_bloqueio";"operacao";"versao_layout";"razao_social";"sigla_conselho_regional";"uf_conselho_regional";"numero_conselho_regional";"nome_responsavel_tecnico";"facebook";"twitter";"observacoes";"acessibilidade";"detalhe_acessibilidade";"atend_24_horas";"link_agenda_online";"secao_resultado";"regime_atendimento";"cpf_cnpj_subst";"codigo_CBO_subst";"classe_prestador_subst";"sequencial_endereco_subst";"empresa_id";"reservado1";"dt_inicio_atend"' ||
  304.               chr(13) || chr(10);
  305.   utl_file.put(fHandle, strLinha);
  306.  
  307.   For cPrinc in CurPrinc Loop
  308.     strLinha := cPrinc.codigo_cbo || ';';
  309.     strLinha := StrLinha || cPrinc.codigo_plano || ';';
  310.     strLinha := StrLinha || cPrinc.classe_prestador || ';';
  311.     strLinha := StrLinha || cPrinc.codigo_legado || ';';
  312.     strLinha := StrLinha || cPrinc.nome_prestador || ';';
  313.     strLinha := StrLinha || cPrinc.sexo || ';';
  314.     strLinha := StrLinha || cPrinc.endereco || ';';
  315.     strLinha := StrLinha || cPrinc.numero || ';';
  316.     strLinha := StrLinha || cPrinc.complemento || ';';
  317.     strLinha := StrLinha || cPrinc.bairro || ';';
  318.     strLinha := StrLinha || cPrinc.codigo_municipio || ';';
  319.     strLinha := StrLinha || cPrinc.codigo_UF || ';';
  320.     strLinha := StrLinha || cPrinc.cep || ';';
  321.     strLinha := StrLinha || cPrinc.telefone_primario || ';';
  322.     strLinha := StrLinha || cPrinc.telefone_secundario || ';';
  323.     strLinha := StrLinha || cPrinc.e_mail || ';';
  324.     strLinha := StrLinha || cPrinc.site || ';';
  325.     strLinha := StrLinha || cPrinc.log_marca || ';';
  326.     strLinha := StrLinha || cPrinc.CNPJ || ';';
  327.     strLinha := StrLinha || cPrinc.priorizacao || ';';
  328.     strLinha := StrLinha || cPrinc.latitude || ';';
  329.     strLinha := StrLinha || cPrinc.longitude || ';';
  330.     strLinha := StrLinha || cPrinc.sequencial_endereco || ';';
  331.     strLinha := StrLinha || '"'||cPrinc.dt_bloqueio || '"'|| ';';
  332.     strLinha := StrLinha || cPrinc.motivo_bloqueio || ';';
  333.     strLinha := StrLinha || cPrinc.operacao || ';';
  334.     strLinha := StrLinha || cPrinc.Versao_layout || ';';
  335.     strLinha := StrLinha || cPrinc.razao_social || ';';
  336.     strLinha := StrLinha || cPrinc.sigla_conselho || ';';
  337.     strLinha := StrLinha || cPrinc.uf_conselho_regional || ';';
  338.     strLinha := StrLinha || cPrinc.numero_conselho_regional || ';';
  339.     strLinha := StrLinha || cPrinc.responsavel_tecnico || ';';
  340.     strLinha := StrLinha || cPrinc.facebook || ';';
  341.     strLinha := StrLinha || cPrinc.twitter || ';';
  342.     strLinha := StrLinha || cPrinc.observacoes || ';';
  343.     strLinha := StrLinha || cPrinc.acessibilidade || ';';
  344.     strLinha := StrLinha || cPrinc.detalhe_acessibilidade || ';';
  345.     strLinha := StrLinha || cPrinc.atend_24_horas || ';';
  346.     strLinha := StrLinha || cPrinc.link_agenda_online || ';';
  347.     strLinha := StrLinha || cPrinc.secao_resultado || ';';
  348.     strLinha := StrLinha || cPrinc.regime_atendimento || ';';
  349.     strLinha := StrLinha || cPrinc.CNPJ_SBT || ';';
  350.     strLinha := StrLinha || cPrinc.CODCBO_SBT || ';';
  351.     strLinha := StrLinha || cPrinc.CLASSE_SBT || ';';
  352.     strLinha := StrLinha || cPrinc.SEQEND_SBT || ';';
  353.     strLinha := StrLinha || cPrinc.EMPRESA_ID || ';';
  354.     strLinha := StrLinha || cPrinc.RESERVADO || ';';
  355.     strLinha := StrLinha || '"'||cPrinc.DT_INI_ATD || '"'|| ';' || chr(13) || chr(10);
  356.     utl_file.put(fHandle, convert(strLinha, 'UTF8'));
  357.     utl_file.fflush(fHandle);
  358.     --  utl_file.put_line(fHandle, strLinha);
  359.   End Loop;
  360.   utl_file.fclose(fHandle);
  361.  
  362. EXCEPTION
  363.   when others then
  364.     DBMS_OUTPUT.put_line(SQLCODE || '-' || SQLERRM);
  365. END; --
  366.