Saving SQL+ output to a text file

I have to use SQL+ on one of my databases. No way around it. So I will write my queries, run them, check the output, tweak them and run again as necessary. So I might start with
SELECT
ename,
job
FROM
emp;Once I know it is working correctly, I wrap it in a procedure so I can get the data in a text file:
SET TRIM ON
SET PAGESIZE 2000
SET SERVEROUTPUT ON SIZE unlimited
EXEC DBMS_OUTPUT.ENABLE(null)
SPOOL c:\mySQL\out.txt
BEGIN
DECLARE
CURSOR c_cur IS
SELECT
ename,
job
FROM
emp;
BEGIN
DBMS_OUTPUT.PUT_LINE(
'NAME|JOB|'
FOR r_cur IN c_cur LOOP
DBMS_OUTPUT.PUT_LINE(
r_cur.ename||'|'||
r_cur.job
END LOOP;
END;
END;
/Then I import this into Excel as delimited data on the pipe |
which works great until I decide that I actually do need one more column. Then I have make changes to the SQL, and two more changes in the output portion (one for the heading, and one for the LOOP)
I was wondering if anyone had written a cool procedure that I could run ANY SQL through, and it would automatically know my column names write the headings and then loop through the data automatically.
I'm not tied to using the exact procedure I described above. The key is, I am looking for a general procedure that I can run any script through, and it will handle the output for me, without additional modification.

MrGibbage wrote:
I have to use SQL+ on one of my databases. No way around it. So I will write my queries, run them, check the output, tweak them and run again as necessary. So I might start with
SELECT
ename,
job
FROM
emp;Once I know it is working correctly, I wrap it in a procedure so I can get the data in a text file:
SET TRIM ON
SET PAGESIZE 2000
SET SERVEROUTPUT ON SIZE unlimited
EXEC DBMS_OUTPUT.ENABLE(null)
SPOOL c:\mySQL\out.txt
BEGIN
DECLARE
CURSOR c_cur IS
SELECT
ename,
job
FROM
emp;
BEGIN
DBMS_OUTPUT.PUT_LINE(
'NAME|JOB|'
FOR r_cur IN c_cur LOOP
DBMS_OUTPUT.PUT_LINE(
r_cur.ename||'|'||
r_cur.job
END LOOP;
END;
END;
/Then I import this into Excel as delimited data on the pipe |
which works great until I decide that I actually do need one more column. Then I have make changes to the SQL, and two more changes in the output portion (one for the heading, and one for the LOOP)
I was wondering if anyone had written a cool procedure that I could run ANY SQL through, and it would automatically know my column names write the headings and then loop through the data automatically.
I'm not tied to using the exact procedure I described above. The key is, I am looking for a general procedure that I can run any script through, and it will handle the output for me, without additional modification.Why are you bothering with the PL/sql procedure at all? Why not just
SET TRIM ON
SET PAGESIZE 2000
SPOOL c:\mySQL\out.txt
SELECT
ename,
job
FROM
emp;
spool off

Similar Messages

  • Not able to save report output in a text file and RTF file

    I am using Oracle Developer6.0 . I am facing problem with reports. I am invoking reports from form using run_product.
    1. I could not able to save the report in text file . Whenever i try to save the report output in a text file.It gives dump and application get closed.
    2. In RTF format , it execute the query which i have given at the design time while creating a report . But while running i am passing query either through lexical parameter or passing value of where criteria user parameters. It display the output for the specified value. But when i save this report output in rtf file . It execute design time query and save that in a rtf file.
    If any body is having any idea about it . Please let me ASAP . It is very urgent for me.
    Thanks in advance

    Try the following:
    Do not generate the report to .rep file, but rename/copy the .rdf file to .rep file and execute it.

  • How to load SQL scripts from a text file.

    Hi, i tried several time to load a text file/SQL script with 10 different tables and data, but 10g Express doesen't allows me to do that, any one can direct me or point out to me what i should do or do i need to adopt any special method to to get this done. i am sure there must be some thing where you can upload SQL scripts from a text file (in SQL command editor!). thanks

    Hi,
    see my other answer here:
    SQL command editor doesn't take more than 1 insert command
    This seems to be a duplicate question, right? Or am I missing something?
    Regards,
    ~Dietmar.

  • How to display the out put of the sql query in a text file using forms

    I want to display the out put of the sql query in a text file using forms 6.0.Same could be done using spool command in sqlplus but i want it using forms....Fiaz

    Have a look at the text_io package:
    http://www.oracle.com/webapps/online-help/forms/10g/state?navSetId=_&navId=3&vtTopicFile=f1_help/oraini/c_text_io.html&vtTopicId=
    cheers

  • Output to a text file in an applet...

    i can't figure out how to do output to a text file in an applet... i've gotten output in applications, but nto applets. if someone can give me a link to a site that explains this, i would be much appreciative.

    There is no easy way, since accessing Files with write permissions is a security issue. You can sign the JAR your applet is in, and use Security managers to try and get around it, but it is quite complicated I believe.
    Do a search for Security Signed Applets etc...

  • How to write the output of an SQL query to a text file?

    I am using Oracle 11g and SQL plus.
    I have a large table called rating.
    Whenever I do
    SQL> select * from rating;
    The output goes much beyond what the SQL Plus screen can show. I want to therefore store the output of this query into a text file.
    How can this be done? Please help. Thanks.

    SQL> SPOOL results.txt
    SQL> select * from rating;
    SQL> SPOOL OFF

  • Outputting to a text file.

    Hey guys and gals,
    Im doing a program for work that is a form you type in, select save and it stores the data to a file. I have 2 problems. FIRST i need to know how to change the font. SECOND how do i put in tabs, returns using out.write(...);
    The goal is to output a form to a text file that can be saved, printed. Right now it all runs together in the .txt or .doc file that it makes.
    thanks bunches
    package hrform;
    // imports
    import java.awt.Font;
    import java.awt.*;
    import java.io.*;
    import javax.swing.*;
    import java.awt.event.ActionListener;
    import java.awt.event.ActionEvent;
    import javax.swing.event.*;
    import java.awt.Font;
    public class form extends JFrame implements ActionListener
    //declare text boxes, buttons, radiobuttons
    private JRadioButton jrbThree, jrbSix;
    //private ButtonGroup btg = new ButtonGroup();
    private JButton jbtSave;
    private JTextField jtfEmployee, jtfDateofhire;
    private JTextField jtfDatecompleted, jtfJobtitle;
    private JFileChooser jFileChooser = new JFileChooser();
    private JTextField jtfCurrentpay, jtfDateofincrease, jtfAmount;
    private JTextField jtfAcceptible, jtfExemplary, jtfImprovement, jtfDependability;
    private JTextField jtfPersonality, jtfGoals;
    /** Main Method*/
    public static void main(String [] args)
    form frame = new form();
    //frame.setDefault(closeOperation(JFrame.EXIT_ON_CLOSE));
    frame.setSize(800,580);
    frame.setVisible(true);
    /**Default Constructor*/
    public form()
    Color defaultColor = Color.red;
    setTitle("Employee Evaluation Form");
    JPanel p1 = new JPanel();
    p1.setLayout(new FlowLayout(FlowLayout.LEFT,10,10));
    setColor (Color.lightGray);
    p1.add(new JLabel("Employee Name:"));
    p1.add(jtfEmployee = new JTextField(11));
    p1.add(new JLabel("Date of Hire:"));
    p1.add(jtfDateofhire = new JTextField(10));
    p1.add(new JLabel("Date Completed by Employee"));
    p1.add(jtfDatecompleted = new JTextField(10));
    // panel p2 for radio buttons
    JPanel p2 = new JPanel();
    p2.setLayout(new FlowLayout(FlowLayout.LEFT, 10, 10));
    p2.add(new JLabel("Job Title: "));
    p2.add(jtfJobtitle = new JTextField(20));
    p2.add(new JLabel("Current Rate of Pay"));
    p2.add(jtfCurrentpay = new JTextField(10));
    p2.add(new JLabel("Date of Last Increase: "));
    p2.add(jtfDateofincrease = new JTextField(8));
    p2.add(new JLabel("Amount of Last Increase: "));
    p2.add(jtfAmount = new JTextField(70));
    p2.add(new JLabel("Has displayed an acceptable level of performance these areas: "));
    p2.add(jtfAcceptible = new JTextField(70));
    p2.add(new JLabel("Has shown EXEMPLARY performace in these areas: "));
    p2.add(jtfExemplary = new JTextField(70));
    p2.add(new JLabel("Areas for Improvement: "));
    p2.add(jtfImprovement = new JTextField(70));
    p2.add(new JLabel("Dependability(Focus on attendance, punctuality, and attentiveness): "));
    p2.add(jtfDependability = new JTextField(70));
    p2.add(new JLabel("Personality(Focus on ability to work for and with others): "));
    p2.add(jtfPersonality = new JTextField(70));
    p2.add(new JLabel("GOALS FOR NEXT QUARTER: "));
    p2.add(jtfGoals = new JTextField(70));
    p2.add(jbtSave = new JButton());
    jbtSave.setText("Save");
    //set default directory
    jFileChooser.setCurrentDirectory(new File("F:WPDOCS/Personne"));
    //Set flowlayout for the fram
    getContentPane().setLayout(new BorderLayout());
    getContentPane().add(p1, BorderLayout.NORTH);
    getContentPane().add(p2, BorderLayout.CENTER);
    // Register Listeners
    jbtSave.addActionListener(this);
    /** Handle event */
    public void actionPerformed(ActionEvent e)
    String actionCommand= e.getActionCommand();
    if (e.getSource() instanceof JButton)
    if ("Save".equals(actionCommand))
    Save();
    /** Save file*/
    private void Save()
    if(jFileChooser.showSaveDialog(this) == JFileChooser.APPROVE_OPTION)
    Save(jFileChooser.getSelectedFile());
    private void Save(File file)
    try
    Font helv = new Font("Helvetica", Font.BOLD, 16);
    Font courier = new Font("Courier", Font.BOLD, 24);
    Color defaultColor = Color.cyan;
    BufferedOutputStream out = new BufferedOutputStream(new FileOutputStream(file));
    out.write(new JLabel(" ").getText().getBytes());
    //out.setFont("SansSerif",Font.BOLD,14);
    out.write(new JLabel("TMC Orthopedic - EMPLOYEE PERFORMANCE EVALUATION").getText().getBytes());
    out.write(new JLabel(" ").getText().getBytes());
    out.write(new JLabel("Employee Name: ").getText().getBytes());
    byte[] b = (jtfEmployee.getText()).getBytes();
    out.write(b,0,b.length);
    out.write(new JLabel(" ").getText().getBytes());
    out.write(new JLabel("Date of Hire: ").getText().getBytes());
    out.write(new JLabel().getText().getBytes());
    byte[] c = (jtfDateofhire.getText()).getBytes();
    out.write(c,0,c.length);
    out.write(new JLabel(" ").getText().getBytes());
    out.write(new JLabel("Date Completed by Employee: ").getText().getBytes());
    //out.writeChars(\n);
    byte[] d = (jtfDatecompleted.getText().getBytes());
    out.write(d,0,d.length);
    byte[] e = (jtfJobtitle.getText().getBytes());
    out.write(new JLabel(" ").getText().getBytes());
    out.write(new JLabel("Job Title: ").getText().getBytes());
    out.write(e,0,e.length);
    out.write(new JLabel(" ").getText().getBytes());
    out.write(new JLabel("Current Pay: ").getText().getBytes());
    byte[] f = (jtfCurrentpay.getText().getBytes());
    out.write(f,0,f.length);
    out.write(new JLabel(" ").getText().getBytes());
    byte[] g = (jtfDateofincrease.getText().getBytes());
    out.write(new JLabel("Date of Last Increase: ").getText().getBytes());
    out.write(g,0,g.length);
    out.write(new JLabel(" ").getText().getBytes());
    byte[] h = (jtfAmount.getText().getBytes());
    out.write(new JLabel("Amount Of Last Increase").getText().getBytes());
    out.write(h,0,h.length);
    out.write(new JLabel(" ").getText().getBytes());
    out.write(new JLabel("Has displayed an acceptable level of performance in these areas: ").getText().getBytes());
    byte[] i = jtfAcceptible.getText().getBytes();
    out.write(i,0,i.length);
    out.write(new JLabel(" ").getText().getBytes());
    out.write(new JLabel("Has displayed an exemplary level of performance in the following areas: ").getText().getBytes());
    byte[] j = jtfExemplary.getText().getBytes();
    out.write(j,0,j.length);
    out.write(new JLabel(" ").getText().getBytes());
    out.write(new JLabel("Areas for improvement").getText().getBytes());
    byte[] k = jtfImprovement.getText().getBytes();
    out.write(k,0,k.length);
    out.write(new JLabel(" ").getText().getBytes());
    out.write(new JLabel("Dependability(Focus on attendance, punctuality, and attentiveness): ").getText().getBytes());
    byte[] l = jtfDependability.getText().getBytes();
    out.write(l,0,l.length);
    out.write(new JLabel(" ").getText().getBytes());
    out.write(new JLabel("Personality (Forcus on ability to work for and with others): ").getText().getBytes());
    byte[] m = jtfPersonality.getText().getBytes();
    out.write(m,0,m.length);
    out.write(new JLabel(" ").getText().getBytes());
    out.write(new JLabel("GOALS FOR NEXT QUARTER: ").getText().getBytes());
    byte[] n = jtfGoals.getText().getBytes();
    out.write(n,0,n.length);
    out.close();
    catch(IOException ex)

    I tried both of these and i get an error.
    "form.java": Error #: 300 : method write(java.lang.String) not found in class java.io.BufferedOutputStream at line 136, column 15
    Do i need to include something else???
    Thanks
    To insert a tab, use out.write("\t"). To insert a newline (crossplatform), use out.write(System.getProperty("line.separator")).
    HTH!
    :o)

  • How to resend the RMAN output to a text file

    Hi ,
    I am using RMAN for backup purpose.
    How should we send the output of RMAN to a text file.
    For Example If we issue the following command then how should we send the results of that command into a text file:
    RMAN> report obsolete device
    type 'sbt_tape';
    result:
    RMAN-03022: compiling command: report
    RMAN-06147: no obsolete backups found
    Any ideas will be great for me.
    Thanks
    Kumar

    Example:
    [oracle@ozawa oracle]$ sqlplus /nolog
    SQL*Plus: Release 9.2.0.1.0 - Production on Thu Mar 4 09:38:40 2004
    Copyright (c) 1982, 2002, Oracle Corporation. All rights reserved.
    SQL> spool my_output.txt
    SQL>
    SQL> host rman target /
    Recovery Manager: Release 9.2.0.1.0 - Production
    Copyright (c) 1995, 2002, Oracle Corporation. All rights reserved.
    connected to target database: LQACNS1 (DBID=1237456636)
    RMAN>
    RMAN>
    RMAN> quit
    Recovery Manager complete.
    SQL>
    SQL> spool off
    SQL>
    SQL> quit
    Joel Pérez

  • Problem with alv output export to text file

    hi experts,
    when iam exporting alv output to text file,
    some data is missing in text file.say for example sold-to-party value is 1155027 in alv out put,but in text file it is showeing only 115502 ,
    the last digit is missing,
    can anyone help urgent!!!!!

    and when you export it to excel?
    from here you could save it as text file too...
    A.

  • Saving report as PDF and text file

    Currently, I saved my report as PDF. It opens in Acrobat reader automatically when the report is executed. Is there a way for me to save it as PDF and as a text file at the same time? (without having to open the file in Acrobat reader and saving it)

    You can add your PDF and TEXT file formats to a distribution list (Instead of GENERATE REPORT TO A FILE). To do this:
    1. Go to your Object Navigator and highlight your report.
    2. Right click on your report. Select Property Palette.
    3. Select Distribution
    4. You can add of of the formats that you want to print or save to the report to.
    5. You will have to add Distribution Id (any number starting with 1) where you want the file to be saved (c:\my_reports\inventory.pdf), the type of file: PDF and how many copies you want: 2
    6. Click OK after finishing...
    To make it work ... You would highlight your report from your Object Navigator and then choose FILE-DISTRIBUTE and this will save it to all the files your specified and/or printer.
    null

  • Problem in reading Sql server data from text file.

    I am selecting record from sql server 2005 and save the result in text file.
    The text file contains , delimiter.
    I am reading same txt file from java & insert into database.
    But it shows "��S and box like characters along with original text.
    Regards
    Joe

    I also tried a lot for this. And didn't want to do copy paste for all .sql files. Finally the files could be read as is the clue is to read the file using UTF-16 format like
    BufferedReader br=new BufferedReader(new InputStreamReader(fis,Charset.forName("UTF-16")));
    I guess it would help and save work to copy paste text to other files and resaving it!

  • Report output in a text file

    Hello,
    I am using report 6i and I would like to have the output of my report in a file, such as text file.
    I tried with the systems parameters (DESNAME, DESTYPE ...) but it dosent work.
    Does someone could help me with that?
    Thankyou in advance.

    Hi,
    I had tried to do that before. When you write to a file oracle reports create a .lis file containing printer fonts, which is no good. What you can do is define a printer using ascii drivers and use that printer to write to a file inorder to get a text file.
    The other thing I did is used DDE techniques to write the report to .xls file. The online help on reports have good examples on how to do this.
    Hope this helps. Good Luck!

  • Formatting output to a text file (using FileWriter and PrintWriter)

    Hi Folks
    I am using the bit of code below to save output from a gui to a text file. The data is entered line by line in the form eg,
    "one two three four"
    "five six seven eight"
    I am also reloading this data back in to a TextArea in the GUI for viewing if required. The annoying thing that upon reloading, the data appears in one long line. The TextArea does not offer a line wrapping facilty (well I don't know how to impement it, it exist). Consequently, I would be quite grateful if somone could come come to my assistance. Any of these would graciously appreciated:
    1. Forcing the TextArea to word wrap
    2. Manually inserting some type of newline character at the end of the outbound
    text
    3. Or any other procedure you experts can dream up :-)
    Cheers
    public void actionPerformed(ActionEvent e) {
    if (e.getSource() == loadButton) {
    getFileDialog = new FileDialog(this,
    "Select or enter the name of the file you wish to write to.",
    FileDialog.LOAD);
    getFileDialog.setDirectory("C:\\Work\\java_tutorials");
    getFileDialog.show();
    fileName = getFileDialog.getFile();
    if(fileName == null) {
    return;
    directory = getNameBox.getDirectory();
    path = directory + fileName;
    fileConfirmation.setText(path);
    if (e.getSource() == saveButton ) {
    try{
    outputFile = new PrintWriter( new FileWriter(fileName, true), true);
    outputFile.print(inputTextArea.getText() );
    outputFile.close();
    catch (FileNotFoundException e1) {
    return;
    catch (NullPointerException e2) {
    return;
    catch (IOException e3) {     
    JOptionPane.showMessageDialog(null,
    "There was an error in opening this file!");
    System.exit(0);
    }

    'you can use "append()" method...
    ex.
    // some code here...
         inputTxtArea.append(data+"\n");  //<<-- you need to put '\n'
    // some code here...

  • Query Output Into a Text File

    Hello Experts,
    There is a situation where i need ur help.My query is :
    Can I export the output of more than one queries into a * Single Text File * ?
    Also can it be possible to automate these Queries Output to export into the Text File ??
    I also want this Text File Output to mail the end users by using the Process Chain. So is this possible to create a process chain for sending this Text File to the Users via mail ??
    Thanks In Advance
    Neha

    Hello Neha,
    Though i have been working with APDs since some time. But havent actually been involved in designing one. But you could find many documents for the APD on web. And as far as i know, you will need a program to save file from APD.
    I have a document which explains how you can use APD in  process chain. can forward you the same if you want.
    I am sorry as i wasnt of much help for you, as i havent worked on similar requirement before, but this thing just striked in my mind.
    Regards,
    Anuj

  • Output into a text file

    Hi all, i am trying to parse an xml doc from a url and the display the results in an text file, howver when i run the below code the Headers are coming up the the returned results are being displayed int the cmd prompt window, anyone have any ideas on how to display the results in a text file?
    import org.apache.xerces.parsers.DOMParser;
    import org.xml.sax.SAXException;
    import java.io.IOException;
    import org.w3c.dom.Document;
    import org.w3c.dom.NodeList;
    import org.w3c.dom.Node;
    import org.w3c.dom.NamedNodeMap;
    import java.util.Properties;
    import java.io.*;
    public class IsbnSearch{
        public static void main(String args[]) throws IOException, SAXException{
            //Check out: http://www.rgagnon.com/javadetails/java-0085.html
            Properties systemSettings = System.getProperties();
            systemSettings.put("http.proxyHost", "staff-proxy.ul.ie");
            systemSettings.put("http.proxyPort", "8080");
            System.setProperties(systemSettings);
            FileOutputStream out; // declare a file output object
            PrintStream p ; // declare a print stream object
            String isbn;
            String size;
            BufferedReader reader;
            reader = new BufferedReader(new InputStreamReader(System.in));
            System.out.print("Please enter Isbn Number\n");
            try {
                 out = new FileOutputStream("myfile.xls");
                 p = new PrintStream( out );
                 isbn = reader.readLine();
            System.out.print("Please Choose the Level of Detail you require:\n");
            System.out.print("Small, Medium or Large\n");
                    size = reader.readLine();
            DOMParser parser = new DOMParser();
            parser.parse("http://webservices.amazon.com/onca/xml?Service=AWSECommerceService&Version=2005-03-23&Operation=ItemLookup&ContentType=text%2Fxml&SubscriptionId=0525E2PQ81DD7ZTWTK82&ItemId="+isbn+"&IdType=ASIN&ResponseGroup="+size+"");
            Document dom = parser.getDocument();
            p.println("\nTitle:");
            getAttribute(dom, "Title");
            p.println("\nAuthor:");
            getAttribute(dom, "Author");
            p.println("\nImage:");
            getAttribute(dom, "SmallImage");
            p.println("\nISBN:");
            getAttribute(dom, "ISBN");
            p.println("\nBinding:");
            getAttribute(dom, "Binding");
            p.println("\nReview:");
            getAttribute(dom, "Content");
            p.println("\nDetail Website Please Visit =:");
            getAttribute(dom, "DetailPageURL");
            p.println("\nTime to process Request:");
            getAttribute(dom, "RequestProcessingTime");
            catch (IOException ioe) {
                 System.out.println("I/0 Exception Occurresd");
        private static void getAttribute(Document dom, String tagName)throws IOException {
                 NodeList ItemAttributes = dom.getElementsByTagName(tagName);
                    for(int i=0;i<ItemAttributes.getLength();i++){
                Node aNode = ItemAttributes.item(i);
                System.out.println(aNode.getFirstChild().getNodeValue());
                NamedNodeMap attributes = aNode.getAttributes();
                for (int a=0;a<attributes.getLength();a++){
                    Node theAttribute = attributes.item(a);
                    System.out.println(theAttribute.getNodeName() + "="+ theAttribute.getNodeValue());
    }

    I suppose you mean that the output of this line of codeSystem.out.println(theAttribute.getNodeName() + "="+ theAttribute.getNodeValue());is coming out on the console? Yup. That's what System.out is for. Let me point you at the Java I/O tutorial:
    http://java.sun.com/docs/books/tutorial/essential/io/index.html
    It explains how to write to a file.

Maybe you are looking for

  • FI configuration related to HR

    Hi All, What's the FI configuration related to HR? Really appreciate your help. Thanks

  • How can we give suggestion to Apple

    I work with a few other studios across the internet. We use iSight conferencing as a tool for song writing. We all use Logic Pro or Login Express and collaborate via video and transfer audio and midi files by dropping them on the video screens to sha

  • I am formatting an ebook and want to convert the doc. to an ePub with the Table of Contents links intact. Is there a way?

    I have formatted an ebook in word and created a doc. I now need to also convert it into an ePub. I have downloaded the latest version of pages and am having difficulties trying to make the Table of Contents links work. The tabs in all the youtube vid

  • Fix for Android 4.4.2

    Since the beginning of June, I have been waiting to see if there will be a fix for the disaster that was named Kitkat 4.4.2 There are many postings (never answered) from people listing their problems since the update. I have gone from loving this pho

  • How to use AWR in 10g?

    Hi All, I am new to AWR?. How to install and use it for performance data collection and reporting..? Edited by: jprakash on Aug 13, 2009 11:45 AM