This shows you the differences between two versions of the page.
Next revision | Previous revision | ||
kurs:write_to_file_utl_file [2008/11/06 15:00] mh created |
kurs:write_to_file_utl_file [2014/09/10 21:22] (current) |
||
---|---|---|---|
Line 1: | Line 1: | ||
+ | <code> | ||
+ | create directory data_dir as 'c:\data'; | ||
+ | grant read, write on directory data_dir to public; | ||
+ | </code> | ||
+ | <code> | ||
+ | PROCEDURE WRITE_TO_FILE | ||
+ | is | ||
+ | v_filehandle utl_file.file_type; | ||
+ | cursor emp_cursor is | ||
+ | SELECT * FROM employees | ||
+ | ORDER BY employees.salary DESC; | ||
+ | |||
+ | emp emp_cursor%rowtype; | ||
+ | BEGIN | ||
+ | |||
+ | v_filehandle := utl_file.fopen('DATA_DIR', 'out.txt', 'w'); | ||
+ | |||
+ | -- open emp_cursor; | ||
+ | for emp in emp_cursor | ||
+ | loop | ||
+ | dbms_output.put_line(emp.salary); | ||
+ | utl_file.putf(v_filehandle, emp.salary); | ||
+ | utl_file.new_line(v_filehandle); | ||
+ | | ||
+ | end loop; | ||
+ | utl_file.fclose(v_filehandle); | ||
+ | END; -- Procedure | ||
+ | </code> |