- Este tópico contém 5 respostas, 3 vozes e foi atualizado pela última vez 17 anos, 4 meses atrás por
DanielB.
-
AutorPosts
-
6 de novembro de 2008 às 11:19 pm #83595
airoosp
ParticipanteBoa 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
7 de novembro de 2008 às 3:36 pm #83598Ricardo Portilho Proni
ParticipanteDepende do que você quer gerar.
Pode ser que só um SPOOL resolva?7 de novembro de 2008 às 3:51 pm #83600airoosp
ParticipanteExecutar o script acima.
7 de novembro de 2008 às 11:31 pm #83619DanielB
ParticipanteVc posse tentar com dbms_lob
7 de novembro de 2008 às 11:40 pm #83620airoosp
ParticipanteBoa tarde,
Você tem algum exemplo ou indicar algum site sobre o dbms_lob, funciona a versão 9i?
Obrigado.
Airton
11 de novembro de 2008 às 4:31 am #83641DanielB
Participantesim, 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; -
AutorPosts
- Você deve fazer login para responder a este tópico.