Solved

UTL_FILE.PUT_LINE getting records on one row...

Posted on 2008-10-28
5
1,185 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 73

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 73

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 73

Expert Comment

by:sdstuber
ID: 22827451
glad I could help
0

Featured Post

3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
PL/SQL Two changes 7 27
SQL NULL vs Blank 26 36
grant user/role question 11 28
SQL Query - Database name 'TempDB' ignored, referencing object in tempdb - Error 2 16
How to Create User-Defined Aggregates in Oracle Before we begin creating these things, what are user-defined aggregates?  They are a feature introduced in Oracle 9i that allows a developer to create his or her own functions like "SUM", "AVG", and…
Cursors in Oracle: A cursor is used to process individual rows returned by database system for a query. In oracle every SQL statement executed by the oracle server has a private area. This area contains information about the SQL statement and the…
This video shows, step by step, how to configure Oracle Heterogeneous Services via the Generic Gateway Agent in order to make a connection from an Oracle session and access a remote SQL Server database table.
This video explains what a user managed backup is and shows how to take one, providing a couple of simple example scripts.

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