Pular para o conteúdo
Visualizando 6 posts - 1 até 6 (de 6 do total)
  • Autor
    Posts
  • #83595
    airoosp
    Participante

      Boa tarde,

      Encontrei o script abaixo na Internet, o problema é que quando o arquivo criado chega em 34kb a procedure para a execução. Pelo que entendi é uma limitação do UTL_FILE em 32767, alguém conhece alguma alternativa para gerar o arquivo sem utilizar o UTL_FILE? Alterei o valor de 32767 para 1000000, a procedure compilou mas a execução parou no 34kb.

      create or replace procedure gera_script_usuarios as

      no_grant exception;

      pragma exception_init(no_grant, -31608);
      — to skip the ORA-31608 when no data for the object requested.

      file_handle utl_file.file_type;

      stmt clob;

      begin

      file_handle:=utl_file.fopen(‘USUARIOS’,’cr_users.sql’,’w’,32767);

      for l_user in (select username
      from dba_users
      order by username) loop

      — USERS

      stmt:=DBMS_METADATA.GET_DDL(‘USER’,l_user.username);
      utl_file.put(file_handle,stmt);

      — SYSTEM GRANTS

      begin
      stmt:=DBMS_METADATA.GET_GRANTED_DDL(‘SYSTEM_GRANT’,l_user.username);
      exception
      when no_grant then stmt:= ‘– no system grants’;
      end;

      utl_file.put(file_handle,stmt);

      — OBJECT GRANTS

      begin
      stmt:=DBMS_METADATA.GET_GRANTED_DDL(‘OBJECT_GRANT’,l_user.username);
      exception
      when no_grant then stmt:= ‘– no object grants’;
      end;

      utl_file.put(file_handle,stmt);

      — ROLE GRANTS

      begin
      stmt:=DBMS_METADATA.GET_GRANTED_DDL(‘ROLE_GRANT’,l_user.username);
      exception
      when no_grant then stmt:= ‘– no role grants’;
      end;

      utl_file.put(file_handle,stmt);

      — TABLESPACE QUOTAS

      begin
      stmt:=DBMS_METADATA.GET_GRANTED_DDL(‘TABLESPACE_QUOTA’,l_user.username);
      exception
      when no_grant then stmt:= ‘– no tablespace quota’;
      end;

      utl_file.put(file_handle,stmt);

      — DEFAULT ROLES

      begin
      stmt:=DBMS_METADATA.GET_GRANTED_DDL(‘DEFAULT_ROLE’,l_user.username);
      exception
      when no_grant then stmt:= ‘– no default role’;
      end;

      utl_file.put(file_handle,stmt);

      end loop;

      utl_file.fclose(file_handle);

      end gera_script_usuarios;

      Para executar a procedure via SQLPLUS ou PL/SQL Developer executar:

      set long 10000;

      begin

      DBMS_METADATA.SET_TRANSFORM_PARAM(DBMS_METADATA.SESSION_TRANSFORM,’SQLTERMINATOR’,TRUE);

      gera_script_usuarios;

      DBMS_METADATA.SET_TRANSFORM_PARAM(DBMS_METADATA.SESSION_TRANSFORM,’SQLTERMINATOR’,FALSE);

      end;
      /

      Obrigado

      Airton

      #83598
      Ricardo Portilho Proni
      Participante

        Depende do que você quer gerar.
        Pode ser que só um SPOOL resolva?

        #83600
        airoosp
        Participante

          Executar o script acima.

          #83619
          DanielB
          Participante

            Vc posse tentar com dbms_lob

            #83620
            airoosp
            Participante

              Boa tarde,

              Você tem algum exemplo ou indicar algum site sobre o dbms_lob, funciona a versão 9i?

              Obrigado.

              Airton

              #83641
              DanielB
              Participante

                sim, funciona no 9i, 10g, e acho que 8i tb

                declare
                vblob BLOB;
                vstart NUMBER := 1;
                bytelen NUMBER := 32000;
                len NUMBER;
                my_vr RAW(32000);
                x NUMBER;

                l_output utl_file.file_type;
                v_name varchar2(2000) ;
                v_pos NUMBER := INSTR(p_name, ‘/’,-1,1);
                BEGIN
                v_name := SUBSTR(p_name, v_pos+1);
                — define output directory
                vstart := 1;
                bytelen := 32000;
                — get length of blob
                select t.doc_size , t.blob_content
                into len, vblob
                from wwv_flow_files t
                where t.name = p_name;
                l_output := utl_file.fopen(‘FOTOS’, p_name,’wb’, 32760);
                x:=len;
                — if small enough for a single write
                IF len < 32760 THEN
                utl_file.put_raw(l_output,vblob);
                utl_file.fflush(l_output);
                ELSE — write in pieces
                vstart := 1;
                WHILE vstart 0 LOOP
                dbms_lob.read(vblob,bytelen,vstart,my_vr);
                utl_file.put_raw(l_output,my_vr);
                utl_file.fflush(l_output);
                — set the start position for the next cut
                vstart := vstart + bytelen;
                — set the end position if less than 32000 bytes
                x := x – bytelen;
                IF x < 32000 THEN
                bytelen := x;
                END IF;
                END LOOP;
                END IF;
                utl_file.fclose(l_output);
                end;

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