Solved

UTL_FILE.PUT_LINE getting records on one row...

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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Have you ever had to make fundamental changes to a table in Oracle, but haven't been able to get any downtime?  I'm talking things like: * Dropping columns * Shrinking allocated space * Removing chained blocks and restoring the PCTFREE * Re-or…
From implementing a password expiration date, to datatype conversions and file export options, these are some useful settings I've found in Jasper Server.
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…
Via a live example, show how to restore a database from backup after a simulated disk failure using RMAN.

746 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now