Oracle write to file

前端 未结 5 899
礼貌的吻别
礼貌的吻别 2021-01-06 03:18

I am running oracle and have a query which pulls some results from the database. I would like to write the results as a text file. How would I go about doing this?

M

5条回答
  •  心在旅途
    2021-01-06 03:59

    Use UTL_FILE in combination with CREATE DIRECTORY for ease of mapping a directory path with a name (it does not create the actual directory just a reference to it so ensure it is created first)

    example

    
      create directory logfile as 'd:\logfile'; -- must have priv to do this
    
    declare
      vFile utl_file.file_type;
    begin
      vFile := utl_file.fopen(logfile ,'syslog','w'); -- w is write. This returns file handle
      utl_file.put(vFile,'Start Logfile'); -- note use of file handle vFile
      utl_file.fclose(vFile); -- note use of file handle vFile
    end;
    
    

提交回复
热议问题