一个查询之后怎么可以生成一个文本文件啊?
听说用shell脚本可以做到?那要怎么做呢?

解决方案 »

  1.   

    用spool 就可以了。 把这个写到脚本里就可以了。 如:spool D:\test.xls
    SQL 语句
    spool off 
    ------------------------------------------------------------------------------ 
    Blog: http://blog.csdn.net/tianlesoftware 
    网上资源: http://tianlesoftware.download.csdn.net 
    相关视频:http://blog.csdn.net/tianlesoftware/archive/2009/11/27/4886500.aspx 
    DBA1 群:62697716(满); DBA2 群:62697977
      

  2.   

    spool D:\test.xls
    select name,value from  table_name;spool off 
      

  3.   

    我只想要结果
    可以spool出来还有列名的其他东西       ID PPP_BEGINTIME ROAMFLAG PAIDTYPE
    --------- ------------- -------- -------- 
    242489576 2010-04-19 23        2        1 
    242489577 2010-04-20 00        2        1 99 rows selected我想要的结果是这样的242489576|2010-04-19|23|2|1 
    242489577|2010-04-20|00|2|1 
      

  4.   

    试试这个,需要看懂了修改
    /*文件写*/CREATE OR REPLACE PROCEDURE PrintTranscript (
    /* Outputs a transcript to the indicated file for the indicated
    student. The transcript will consist of the classes for which
    the student is currently registered and the grade received
    for each class. At the end of the transcript, the student's
    GPA is output. */
    p_StudentID IN students.ID%TYPE,
    p_FileDir IN VARCHAR2,
    p_FileName IN VARCHAR2) AS
    v_StudentGPA NUMBER;
    v_StudentRecord students%ROWTYPE;
    v_FileHandle UTL_FILE.FILE_TYPE;
    v_NumCredits NUMBER;
    CURSOR c_CurrentClasses IS
    SELECT *
    FROM registered_students
    WHERE student_id = p_StudentID;
    BEGIN
    -- Open the output file in append mode.
    v_FileHandle := UTL_FILE.FOPEN(p_FileDir, p_FileName, 'a');
    SELECT *
    INTO v_StudentRecord
    FROM students
    WHERE ID = p_StudentID;
    -- Output header information. This consists of the current
    -- date and time, and information about this student.
    UTL_FILE.PUTF(v_FileHandle, 'Student ID: %s\n',
    v_StudentRecord.ID);
    UTL_FILE.PUTF(v_FileHandle, 'Student Name: %s %s\n',
    v_StudentRecord.first_name, v_StudentRecord.last_name);
    UTL_FILE.PUTF(v_FileHandle, 'Major: %s\n',
    v_StudentRecord.major);
    UTL_FILE.PUTF(v_FileHandle, 'Transcript Printed on: %s\n\n\n',
    TO_CHAR(SYSDATE, 'Mon DD,YYYY HH24:MI:SS'));
    UTL_FILE.PUT_LINE(v_FileHandle, 'Class Credits Grade');
    UTL_FILE.PUT_LINE(v_FileHandle, '------- ------- -----');
    FOR v_ClassesRecord in c_CurrentClasses LOOP
    -- Determine the number of credits for this class.
    SELECT num_credits
    INTO v_NumCredits
    FROM classes
    WHERE course = v_ClassesRecord.course
    AND department = v_ClassesRecord.department;
    -- Output the info for this class.
    UTL_FILE.PUTF(v_FileHandle, '%s %s %s\n',
    RPAD(v_ClassesRecord.department || ' ' ||
    v_ClassesRecord.course, 7),
    LPAD(v_NumCredits, 7),
    LPAD(v_ClassesRecord.grade, 5));
    END LOOP;
    -- Determine the GPA.
    CalculateGPA(p_StudentID, v_StudentGPA);
    -- Output the GPA.
    UTL_FILE.PUTF(v_FileHandle, '\n\nCurrent GPA: %s\n',
    TO_CHAR(v_StudentGPA, '9.99'));
    -- Close the file.
    UTL_FILE.FCLOSE(v_FileHandle);
    EXCEPTION
    -- Handle the UTL_FILE exceptions meaningfully, and make sure
    -- that the file is properly closed.
    WHEN UTL_FILE.INVALID_OPERATION THEN
    UTL_FILE.FCLOSE(v_FileHandle);
    RAISE_APPLICATION_ERROR(-20061,
    'PrintTranscript: Invalid Operation');
    WHEN UTL_FILE.INVALID_FILEHANDLE THEN
    UTL_FILE.FCLOSE(v_FileHandle);
    RAISE_APPLICATION_ERROR(-20062,
    'PrintTranscript: Invalid File Handle');
    WHEN UTL_FILE.WRITE_ERROR THEN
    UTL_FILE.FCLOSE(v_FileHandle);
    RAISE_APPLICATION_ERROR(-20063,
    'PrintTranscript: Write Error');
    WHEN UTL_FILE.INVALID_MODE THEN
    UTL_FILE.FCLOSE(v_FileHandle);
    RAISE_APPLICATION_ERROR(-20064,
    'PrintTranscript: Invalid Mode');
    WHEN UTL_FILE.INTERNAL_ERROR THEN
    UTL_FILE.FCLOSE(v_FileHandle);
    RAISE_APPLICATION_ERROR(-20065,
    'PrintTranscript: Internal Error');
    END PrintTranscript;SQL> select * from registered_students;
    STUDENT_ID DEP COURSE G
    ---------- --- --------- -
    10000 CS 102 A
    10002 CS 102 B
    10003 CS 102 C
    10000 HIS 101 A
    10001 HIS 101 B
    10002 HIS 101 B
    10003 HIS 101 A
    10004 HIS 101 C
    10005 HIS 101 C
    10006 HIS 101 E
    10007 HIS 101 B
    10008 HIS 101 A
    10009 HIS 101 D
    10010 HIS 101 A
    10008 NUT 307 A
    10010 NUT 307 A
    10009 MUS 410 B
    10006 MUS 410 E
    10011 MUS 410 B
    10000 MUS 410 B
    20 rows selected.
    如果我们调用过程P r i n t Tr a n s c r i p t来打印学生I D号为1 0 0 0 0和1 0 0 0 9的成绩单,我们将得到下
    面两个输出文件:
    Student ID: 10000
    Student Name: Scott Smith
    Major: Computer Science
    Transcript Printed on: Apr 26,1999 22:24:07
    Class Credits Grade
    ------- ------- -----
    CS 102 4 A
    HIS 101 4 A
    MUS 410 3 B
    Current GPA: 3.73
    Student ID: 10009
    Student Name: Rose Riznit
    Major: Music
    Transcript Printed on: Apr 26,1999 22:24:31
    Class Credits Grade
    ------- ------- -----
    HIS 101 4 D
    MUS 410 3 B
    Current GPA: 1.86
      

  5.   

    spool我看网上说要用shell脚本执行。这个shell脚本该怎么写呢?
      

  6.   

    加上
    set head off
    set colsep "|"