0
Good morning,
I am beginner in Oracle PL/SQL, and I created the script below to record the result of a query in txt file, runs without errors but does not write the file, anyone knows what could be happening ? Where am I going wrong ?
DECLARE arquivo_saida
UTL_File.File_Type; Cursor Cur_Linha is Select OWNER||' '||TABLE_NAME as Linha From All_Tables Where Owner Like'SYS%';
BEGIN arquivo_saida := UTL_File.Fopen('C:\teste','arquvo.txt','w');
For Reg_Linha in Cur_linha Loop
UTL_File.Put_Line(arquivo_saida, Reg_linha.linha);
End Loop;
UTL_File.Fclose(arquivo_saida);
Dbms_Output.Put_Line('Arquivo gerado com sucesso.');
EXCEPTION
WHEN UTL_FILE.INVALID_OPERATION THEN
Dbms_Output.Put_Line('Operação inválida no arquivo.');
UTL_File.Fclose(arquivo_saida);
WHEN UTL_FILE.WRITE_ERROR THEN
Dbms_Output.Put_Line('Erro de gravação no arquivo.');
UTL_File.Fclose(arquivo_saida);
WHEN UTL_FILE.INVALID_PATH THEN
Dbms_Output.Put_Line('Diretório inválido.');
UTL_File.Fclose(arquivo_saida);
WHEN UTL_FILE.INVALID_MODE THEN
Dbms_Output.Put_Line('Modo de acesso inválido.');
UTL_File.Fclose(arquivo_saida);
WHEN Others THEN
Dbms_Output.Put_Line('Problemas na geração do arquivo.');
UTL_File.Fclose(arquivo_saida);
END;
Have you set the UTL or Diretory folder on Oracle ? https://www.devmedia.com.br/pacote-utl_file-do-oracle/13129 https://docs.oracle.com/cd/B19306_01/server.102/b14200/statements_5007.htm
– Motta
Does it not have to be 'C: test' than 'C: test'?
– Heitor Scalabrini
@Motta his link was super useful, only needed to set the directory before using: CREATE DIRECTORY DIRECTORIES AS 'C: DIRECTORIES';
– Paulo Camargo