Spool file in pl/sql ?
DBAsupport.com Forums - Powered by vBulletin
Results 1 to 3 of 3

Thread: Spool file in pl/sql ?

  1. #1
    Join Date
    Jul 2001
    Posts
    334

    Spool file in pl/sql ?

    Hello!
    How I can create a SPOOL file (e.g test.txt) in pl/sql on server. I know in SQL*PLUS, but I have no idea in pl/sql.

    Can some one write a simple pl/sql example in which using sql query and then generate spool file.

    Thanks in advance.

  2. #2
    Join Date
    Dec 2000
    Location
    Ljubljana, Slovenia
    Posts
    4,439
    Check the usage of package UTL_FILE.
    Jurij Modic
    ASCII a stupid question, get a stupid ANSI
    24 hours in a day .... 24 beer in a case .... coincidence?

  3. #3
    Join Date
    Aug 2002
    Location
    Atlanta
    Posts
    1,187
    happened to have one handy - this works for 9i only

    CREATE DIRECTORY test_dir AS 'c:\temp';

    CREATE OR REPLACE PROCEDURE test
    AS
    v_output_file1 utl_file.file_type;
    BEGIN
    /* Ensure TEST_DIR below is in all caps */
    /* Third argument below is W which overwrites file each time, change to A to append */

    v_output_file1 := utl_file.fopen('TEST_DIR', 'my_test.csv', 'W');
    FOR cursor_emp IN (SELECT empnom,ename, deptno FROM emp)
    LOOP
    utl_file.put_line(v_output_file1, cursor_emp.empno || ',' || cursor_emp.ename || ',' || cursor_emp.deptno);
    END LOOP;
    utl_file.fclose_all;
    END;
    /
    I'm stmontgo and I approve of this message

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  


Click Here to Expand Forum to Full Width