Solved

UTL_FILE.PUT_LINE getting records on one row...

Posted on 2008-10-28
5
1,188 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

Question has a verified solution.

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

Checking the Alert Log in AWS RDS Oracle can be a pain through their user interface.  I made a script to download the Alert Log, look for errors, and email me the trace files.  In this article I'll describe what I did and share my script.
This article describes how to use the timestamp of existing data in a database to allow Tableau to calculate the prior work day instead of relying on case statements or if statements to calculate the days of the week.
This video explains at a high level about the four available data types in Oracle and how dates can be manipulated by the user to get data into and out of the database.
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…

738 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