Solved

UTL_FILE.PUT_LINE getting records on one row...

Posted on 2008-10-28
5
1,186 Views
Last Modified: 2013-12-19
I'm using UTL_FILE.PUT_LINE and I either get the last record only or I get all of the records on one row instead of one row for each record.  See example:
v_piece := v_id_number  || CHR(9) ||
                  v_label_name_line2  || CHR(9) ||

UTL_FILE.PUT_LINE(
                                 v_div_writer,
                                 v_piece,
                                 TRUE
                                );

What am I doing wrong?  (I am a beginner, sorry).
0
Comment
Question by:fprickett
  • 3
  • 2
5 Comments
 
LVL 74

Expert Comment

by:sdstuber
ID: 22826058
can you post all of your code?  or at least a more complete snippet?
Something that shows how you are pulling the data into your variables.


You've described two different symptoms, please post the corresponding code for each symptom
as well as what it you are expecting the output to be.
0
 

Author Comment

by:fprickett
ID: 22826338
How's this?  (larger code sample)

    -- Opening the Outer Cursor --
    OPEN online_report_cursor;
      
    -- Fetching the first value from the Outer Cursor --
    FETCH
      online_report_cursor
    INTO
      v_id_number,
        v_label_name_line1,
        v_label_name_line2,
        v_pref_street1,
        v_pref_street2,
        v_pref_street3,
        v_pref_city_state_zip,
        v_pledge_amount,
        v_pledge_date_of_record,
        v_alloc_long_name,
        v_pledge_amt_paid,
        v_pledge_pay_amt,
        v_pledge_type_desc,
        v_division;
      
    -- Looping through the Outer Cursor --      
    WHILE online_report_cursor%FOUND LOOP  
     

        v_balance_due :=  v_pledge_amount - v_pledge_amt_paid;  

                       v_payments_remaining := ROUND(v_balance_due / v_pledge_pay_amt,2);
        
        v_months_remaining := v_payments_remaining / 2;

                       IF v_months_remaining <= 2 THEN
        
             
        
    v_div_file_name := 'PP_' || v_division ||'_' || v_file_week || '.xls';        -- in MMDDYYYY format --

          -- Is the file writer open? --
          IF UTL_FILE.IS_OPEN(v_div_writer) THEN
            -- If so, close it --
            UTL_FILE.FCLOSE(v_div_writer);
            END IF;       
        

          -- Opening the file for writing --  
        v_div_writer := UTL_FILE.FOPEN(
                                               FTP_FROM_DIR,
                                v_div_file_name,
                                                           'w',
                                               32767                                                      );
                                                      
          -- Write the file header --                                                 
          UTL_FILE.PUT_LINE(
                                           v_div_writer,
                             RPT_HEADER,
                           TRUE
                          );
                                
      
        -- Write the detail line --                                                 
        v_piece := v_id_number                                   || CHR(9) ||                    
             v_label_name_line1                                 || CHR(9) ||            
             v_label_name_line2                                   || CHR(9) ||            
            v_sal_basic                                    || CHR(9) ||                    
             v_pref_street1                         || CHR(9) ||                
           v_pref_street2                          || CHR(9) ||                
           v_pref_street3                             || CHR(9) ||                
           v_pref_city_state_zip                                                     || CHR(9) ||          
           v_pledge_amount                   || CHR(9) ||
                         v_pledge_date_of_record                                   || CHR(9) ||        
           v_alloc_long_name                         || CHR(9) ||              
           v_pledge_amt_paid                      || CHR(9) ||              
           v_pledge_pay_amt                          || CHR(9) ||              
           v_balance_due                          || CHR(9) ||              
         v_pledge_type_desc;


          -- Write the transaction to the division report --                             UTL_FILE.PUT_LINE(
                                           v_div_writer,
                            v_piece,
                            FALSE
                          );
0
 
LVL 74

Accepted Solution

by:
sdstuber earned 50 total points
ID: 22826425
you close and reopen the file on each pass through your cursor loop.

That is slow, just open it once before entering the loop and write to it until done then close after the cursor.


But, that's only performance,  the problem is when you close and reopen you are doing it with write mode 'w'
which overwrites the file each time instead of "a" for append which will add new data to the end of the file each time it is opened
0
 

Author Closing Comment

by:fprickett
ID: 31510932
Thank you so much, that fixed it.  You have taught me to fish!  (Give a man a fish, he eats for a day.  Teach a man how to fish, he eats for life.)
0
 
LVL 74

Expert Comment

by:sdstuber
ID: 22827451
glad I could help
0

Featured Post

The New “Normal” in Modern Enterprise Operations

DevOps for the modern enterprise offers many benefits — increased agility, productivity, and more, but digital transformation isn’t easy, especially if you’re not addressing the right issues. Register for the webinar to dive into the “new normal” for enterprise modern ops.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

'Between' is such a common word we rarely think about it but in SQL it has a very specific definition we should be aware of. While most database vendors will have their own unique phrases to describe it (see references at end) the concept in common …
Using SQL Scripts we can save all the SQL queries as files that we use very frequently on our database later point of time. This is one of the feature present under SQL Workshop in Oracle Application Express.
This video shows setup options and the basic steps and syntax for duplicating (cloning) a database from one instance to another. Examples are given for duplicating to the same machine and to different machines
This video shows information on the Oracle Data Dictionary, starting with the Oracle documentation, explaining the different types of Data Dictionary views available by group and permissions as well as giving examples on how to retrieve data from th…

809 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question