plsql IO 实例

 C:\Users\xue>sqlplus /nolog

SQL> conn sys as sysdba;

输入口令:

已连接。

SQL> GRANT EXECUTE ON utl_file TO xue;

 

授权成功。

 

 alter system set utl_file_dir='d:\' scope=spfile;

 show parameter utl_file;

 

create or replace directory BLOBDIR as 'D:\';

grant read,write on directory BLOBDIR to xue;

GRANT EXECUTE ON utl_file TO xue;

select * from ALL_DIRECTORIES;

--写操作

DECLARE

v_file utl_file.file_type; 

v_fileline VARCHAR2(200);

BEGIN

 v_file:= utl_file.fopen('d:\','cw.txt','w');

  utl_file.putf(v_file,'%s\n','第一行');

  utl_file.putf(v_file,'%s\n','第二行');

  utl_file.putf(v_file,'%s\n','第三行');

  utl_file.fclose(v_file);

  END;

--读操作  

DECLARE

v_file utl_file.file_type; 

v_fileline VARCHAR2(200);

BEGIN

 v_file:= utl_file.fopen('d:\','cj.txt','r');

 LOOP

   BEGIN

     utl_file.get_line(v_file,v_fileline);

     EXCEPTION 

       WHEN no_data_found THEN

         EXIT;

     END;

    dbms_output.put_line(v_fileline);

   END LOOP;

   utl_file.fclose(v_file);

  END;

 

你可能感兴趣的:(oracle,操作)