Pular para o conteúdo
  • Este tópico contém 3 respostas, 3 vozes e foi atualizado pela última vez 17 anos, 4 meses atrás por Avatar photoLeonardo Litz.
Visualizando 4 posts - 1 até 4 (de 4 do total)
  • Autor
    Posts
  • #83729
    Anônimo

      Pessoal, em um loop de inserção como eu faço para pegar os seguintes erros?:

       Numero da linha que deu erro
       Nome do campo com erro
       Conteúdo do campo com erro

      #83730
      Manoel872
      Participante

        A cada item do insert coloca esse comando para printar para vc o codigo da linha e talz ae vc escolhe oq quer aparecer para poder analisar.

        DBMS_OUTPUT.PUT_LINE (‘Mensagem’ || ‘-‘ || Campo);

        Manoel Jr.

        #83731
        Anônimo

          isso aí não fuciona não brother. quando dê erro eu quero pegar no EXCEPTION a linha que deu erro, o campo e o conteúdo do campo.

          #83732
          Avatar photoLeonardo Litz
          Participante

            Ola Cleber….

            Cara tem um procedure que utilizo para traduzir os erros que ocorrem….

            compile ela em seu banco de dados

            create procedure SYS_TRATA_ERRO
            is
            msg_err varchar2(512);
            str varchar2(512);
            campo varchar2(30);
            vlrs varchar2(512);
            i integer;
            j integer;
            recs integer;
            cod_err integer;
            begin
            msg_err := sqlErrM;
            cod_err := abs(sqlCode);

            if cod_err = 2290 then — Constraint Check…
            for i in 1..length(msg_err)
            loop
            if substr(msg_err,i,1) = ‘(‘ then
            for j in 1..length(msg_err)
            loop
            if substr(msg_err,-j,1) = ‘)’ then
            str := substr(msg_err,i+1,length(msg_err)-(i+j));
            exit;
            end if;
            end loop;
            exit;
            end if;
            end loop;

            for i in 1..length(str)
            loop
              if substr(str,i,1) = '.' then
                str := substr(str,i+1,length(str)-i);
                exit;
              end if;
            end loop;
            
            select COLUMN_NAME into campo from USER_CONS_COLUMNS
              where CONSTRAINT_NAME = str;
            
            select SEARCH_CONDITION into vlrs from USER_CONSTRAINTS
              where CONSTRAINT_NAME = str;
            
            for i in 1..length(vlrs)
            loop
              if substr(vlrs,i,1) = '(' then
                for j in 1..length(vlrs)
                loop
                  if substr(vlrs,-j,1) = ')' then
                    str := substr(vlrs,i+1,length(vlrs)-(i+j));
                    exit;
                  end if;
                end loop;
                exit;
              end if;
            end loop;
            
            msg_err := 'Valores Validos: (' || str || ')';
            msg_err := '|' || abs(cod_err) || '|' || campo || '|' || msg_err || '|';
            

            elsif cod_err in (1400,1407) then — Constraint not null
            for i in 1..length(msg_err)
            loop
            if substr(msg_err,i,1) = ‘(‘ then
            for j in 1..length(msg_err)
            loop
            if substr(msg_err,-j,1) = ‘)’ then
            msg_err := substr(msg_err,i+1,length(msg_err)-(i+j));
            exit;
            end if;
            end loop;
            exit;
            end if;
            end loop;

            for i in 1..length(msg_err)
            loop
              if substr(msg_err,-i,1) = '"' then
                campo := '';
                for j in (i+1)..length(msg_err)
                loop
                  if substr(msg_err,-j,1)  '"' then
                    campo := substr(msg_err,-j,1)||campo;
                  else
                    exit;
                  end if;
                end loop;
                exit;
              end if;
            end loop;
            
            msg_err := 'Nao pode ser nulo!';
            msg_err := '|' || abs(cod_err) || '|' || campo || '|' || msg_err || '|';
            

            elsif cod_err = 1 then — Constraint Unique
            for i in 1..length(msg_err)
            loop
            if substr(msg_err,i,1) = ‘(‘ then
            for j in 1..length(msg_err)
            loop
            if substr(msg_err,-j,1) = ‘)’ then
            str := substr(msg_err,i+1,length(msg_err)-(i+j));
            exit;
            end if;
            end loop;
            exit;
            end if;
            end loop;

            for i in 1..length(str)
            loop
              if substr(str,i,1) = '.' then
                str := substr(str,i+1,length(str)-i);
                exit;
              end if;
            end loop;
            
            select count(1) into recs from USER_IND_COLUMNS
              where INDEX_NAME = str;
            
            if recs = 1 then
              select COLUMN_NAME into campo from USER_IND_COLUMNS
                where INDEX_NAME = str;
            
              msg_err := 'Nao pode ser duplicado!';
              msg_err := '|' || abs(cod_err) || '|' || campo || '|' || msg_err || '|';
            end if;
            

            end if;

            — Formatacao da mensagem…
            if not msg_err like ‘%|%’ then
            msg_err := ‘|’ || abs(cod_err) || ‘|$NONE$|’ || msg_err || ‘|’;
            end if;

            raise_application_error(-20001,msg_err);
            end SYS_TRATA_ERRO;

            …….

            depois de compilado

            vou deve colocar assim no bloco

            begin
            …..comando….
            exception when others then
            sys_trata_erro();
            end;

            vlw? Leonardo Litz

          Visualizando 4 posts - 1 até 4 (de 4 do total)
          • Você deve fazer login para responder a este tópico.