UTL_FILE. PUT_LINE

friends, I have the following problem, I use this command UTL_FILE. Put_line but who puts the data in a file and makes it perfect, everytime you complete a line jump down I can do to make the next line is Pan below?

UTL_FILE. Put_line-online text written in a tracking file to an end of line marker

UTL_FILE. PUT-online text written in a file

You probably want the latter.

Tags: Database

Similar Questions

  • PLSQL utl_file.put_line error after the script running 8 ' e

    Hello
    I wrote a script to export the results of a query to an external file using utl_file.put_line. the script works very well for the first 8 hours.

    anonymous block filled
    anonymous block filled
    anonymous block filled
    anonymous block filled
    anonymous block filled
    anonymous block filled
    anonymous block filled
    anonymous block filled

    When I run the same script for the 9th time, I got an error message

    Error from the 1 in the command line:
    DECLARE
    OutFile utl_file.file_type;
    TYPE rc_a IS REF CURSOR;
    l_rc_a rc_a;
    TELLER_1 INTEGER: = 3;
    ctt1 varchar (2000);
    AA varchar (2000);
    BEGIN
    FOR TELLER_1 IN 3.9

    LOOP

    OutFile: = utl_file.fopen ('DAT_DIR', 'A1_W' |) TELLER_1 | "_KANS. TXT', 'w');

    ctt1: = '

    SELECT
    WORP_XW | ''|''||
    D | ''|''||
    V5_AANTAL_KANS | ''|''||
    V5_AVG_KANS | ''|''||
    V6_AANTAL_KANS | ''|''||
    V6_AVG_KANS | ''|''||
    V7_AANTAL_KANS | ''|''||
    V7_AVG_KANS | ''|''||
    V8_AANTAL_KANS | ''|''||
    V8_AVG_KANS | ''|''||
    V9_AANTAL_KANS | ''|''||
    V9_AVG_KANS
    Of
    (
    Select D, V5_AANTAL_KANS, V5_AVG_KANS, V6_AANTAL_KANS, WORP_XW, ROUND(V6_AVG_KANS,6) V6_AVG_KANS ROUND(V5_AVG_KANS,6),
    V7_AANTAL_KANS, V7_AVG_KANS, V8_AANTAL_KANS, ROUND(V8_AVG_KANS,6) V8_AVG_KANS ROUND(V7_AVG_KANS,6),
    V9_AANTAL_KANS, ROUND(V9_AVG_KANS,6) V9_AVG_KANS
    Of
    (
    Select WORP_XW, D, KAN,
    case VERSIE_VX when "V5" then 5 when "V6" when then 6 "V7" when then 7 "V8" when then 8 "V9" then 9 end as VERSIE_VX
    of VMENS. TOEVAL_BASIS_W' | TELLER_1 | »

    )
    pivot)
    AVG (KAN) as AVG_KANS,
    COUNT (KAN) AS AANTAL_KANS
    by VERSIE_VX (V5, V6, V7, V8, V9 9 8 7 6 5)
    )
    ORDER BY D
    )';

    L_rc_a OPEN FOR ctt1;
    LOOP
    EXTRACTION l_rc_a IN aa;
    EXIT WHEN l_rc_a % NOTFOUND;
    -dbms_output.put_line (aa);
    UTL_FILE.put_line (OutFile, aa, TRUE);
    END LOOP;

    END LOOP;
    UTL_FILE.fclose (outfile);
    END;
    Error report:
    ORA-29283: Ongeldige bestandsbewerking/ORA-29283: invalid file operation
    ORA-06512: in 'SYS. UTL_FILE", regel 536
    ORA-29283: Ongeldige bestandsbewerking/ORA-29283: invalid file operation
    ORA-06512: in rule 14
    29283 00000 - "invalid file operation.
    * Cause: An attempt was made to read from a file or a directory which is
    not exist, or the file or directory access was denied by the
    Operating system.
    * Action: Check access privileges to the file and directory on the file system
    and if reading, check that the file exists.


    The same is true when I use another script writes the results of a query to an external file. Y at - there someone who can tell me why I have an error message after running 8 ' e of this script.

    With respect,
    Michiel van Mens

    The second time through the outer loop, it will fail because you try to open a file that is already open. Move your utl_file.fclose statement of before the last "END LOOP '.

  • Help: How to deal with the character of the line following in utl_file.put_line?

    Hello

    We try to generate a flat file from an Oracle table through utl_file.put_line. He is troubled with the Fed line of character. How deal with him or another way to do this?

    Any suggestions are greatly appreciated.

    Thank you.
    Jimmy

    I assume that your database is running on unix/linux?

    Try to use UTL_FILE. PUT (Data), followed by a UTL_FILE. PUT (CHR (13): 10;)

  • UTL_FILE.put_line cannot insert all rows

    As shown in the code below, I have for loops with the entrails of IF ELSE statement. How am I suppose to retrieve all rows in my csv file as currently, the csv file has only the last line inserted in the file?

    for c7_rec in C7 loop
    
    FOR C8_REC IN C8(c7_rec.PASSPORTNO) LOOP
    if l_loop8 = 0 then
    CASE  SIGN(C8_REC.AMOUNT) -- check amount negative or positive. If negative need refund to customer else customer owe starhub
         WHEN -1 THEN
    l_negative:=1;
    l_amount_negative:= C8_REC.AMOUNT;
    DBMS_OUTPUT.PUT_LINE(l_amount_negative);
    ELSE
    l_positive:=1;
    l_amount_positive:= C8_REC.AMOUNT;
    DBMS_OUTPUT.PUT_LINE(l_amount_positive);
     END case;
     
     IF l_positive=1 AND l_negative=1 THEN
     IF l_amount_positive < abs(l_amount_negative) then
     DBMS_OUTPUT.PUT_LINE('Positive smaller than negative');
    --l_amount_total:= l_amount_positive+l_amount_negative;
        utl_file.put_line(l_file,c8_rec.CUSTOMER_ID || ' ' ||C8_REC.CUSTOMER_ID|| ' ' ||l_amount_positive|| ' ' ||c8_rec.ohstatus);  
     Elsif  l_amount_positive > abs(l_amount_negative) THEN
     DBMS_OUTPUT.PUT_LINE('Positive bigger than negative');
     ELSE
      DBMS_OUTPUT.PUT_LINE('Nothing to offset');
     END IF; 
    --DBMS_OUTPUT.PUT_LINE(c8_rec.CUSTOMER_ID || ' ' ||C8_REC.CUSTOMER_ID|| ' ' ||C8_REC.AMOUNT|| ' ' ||c8_rec.ohstatus);
     --|| ' ' ||i.cscurbalance);
    l_loop8:=1;
    
    elsIF l_positive=1 AND l_negative=0 THEN
    
    --l_amount_total:= l_amount_positive+l_amount_negative;
        utl_file.put_line(l_file,c8_rec.CUSTOMER_ID || ' ' ||C8_REC.CUSTOMER_ID|| ' ' ||l_amount_positive|| ' ' ||c8_rec.ohstatus);  
    l_loop8:=1;
     elsIF l_positive=0 AND l_negative=1 THEN
    
    --l_amount_total:= l_amount_positive+l_amount_negative;
        utl_file.put_line(l_file,c8_rec.CUSTOMER_ID || ' ' ||C8_REC.CUSTOMER_ID|| ' ' ||l_amount_negative|| ' ' ||c8_rec.ohstatus);  
    l_loop8:=1;
     END IF;
     --DBMS_OUTPUT.PUT_LINE(C11_REC.AMOUNT||' '||C11_REC.PASSPORTNO||' '||C11_REC.OHSTATUS);
     end if;
     END LOOP;
    
        
        l_positive:=0;
     l_negative:=0;
         END LOOP;
            
       utl_file.fclose( l_file );
    CREATE OR REPLACE Procedure p_lee_test As  Cursor C7 Is    Select Unique Passportno      From j_lee_test;
    
      Cursor C8(p_Passportno12 Varchar2) Is    Select Unique Passportno,           Customer_Id,           Case             When Min_Sign = Max_Sign Then              Sum(amt) Over(Partition By Passportno Order By Passportno)             Else              amt           End Amount,           Ohstatus      From (Select Passportno,                   Customer_Id,                   amt,                   Min(Sign(amt)) Over(Partition By Passportno Order By Passportno) Min_Sign,                   Max(Sign(amt)) Over(Partition By Passportno Order By Passportno) Max_Sign,                   Ohstatus              From j_lee_test             Where Passportno = p_Passportno12)     Order By 1;
    
      l_Loop7           Integer := 0;  l_Loop8           Integer := 0;  l_Positive        Integer := 0;  l_Negative        Integer := 0;  l_File            Utl_File.File_Type;  l_Date            Date := Sysdate;  l_Amount_Positive Float;  l_Amount_Negative Float;  l_Amount_Total    Float;
    
    Begin  /*l_File := Utl_File.Fopen('UTL_TMP_DIR',                           'ZERORISATION_' || To_Char(l_Date, 'YYYYMMDD') ||                           '.csv',                           'w');*/  l_file :=  Utl_File.Fopen('/export/orautil/loguser/utl',                           'ZERORISATION_' || To_Char(l_Date, 'YYYYMMDD') ||                           '.csv',                           'w');  For C7_Rec In C7 Loop
    
        For C8_Rec In C8(C7_Rec.Passportno) Loop     -- If l_Loop8 = 0 Then        Case Sign(C8_Rec.Amount) -- check amount negative or positive. If negative need refund to customer else customer owe starhub          When -1 Then            l_Negative        := 1;            l_Amount_Negative := C8_Rec.Amount;            Dbms_Output.Put_Line(l_Amount_Negative);          Else            l_Positive        := 1;            l_Amount_Positive := C8_Rec.Amount;            Dbms_Output.Put_Line(l_Amount_Positive);        End Case;
    
            If l_Positive = 1 And l_Negative = 1 Then          If l_Amount_Positive < Abs(l_Amount_Negative) Then            Dbms_Output.Put_Line('Positive smaller than negative');            --l_amount_total:= l_amount_positive+l_amount_negative;            Utl_File.Put_Line(l_File,                              C8_Rec.Customer_Id || ' ' ||                              C8_Rec.Customer_Id || ' ' ||                              l_Amount_Positive || ' ' || C8_Rec.Ohstatus);          Elsif l_Amount_Positive > Abs(l_Amount_Negative) Then            Dbms_Output.Put_Line('Positive bigger than negative');          Else            Dbms_Output.Put_Line('Nothing to offset');          End If;          --DBMS_OUTPUT.PUT_LINE(c8_rec.CUSTOMER_ID || ' ' ||C8_REC.CUSTOMER_ID|| ' ' ||C8_REC.AMOUNT|| ' ' ||c8_rec.ohstatus);          --|| ' ' ||i.cscurbalance);          l_Loop8 := 1;
    
            Elsif l_Positive = 1 And l_Negative = 0 Then
    
              --l_amount_total:= l_amount_positive+l_amount_negative;          Utl_File.Put_Line(l_File,                            C8_Rec.Customer_Id || ' ' || C8_Rec.Customer_Id || ' ' ||                            l_Amount_Positive || ' ' || C8_Rec.Ohstatus);          l_Loop8 := 1;        Elsif l_Positive = 0 And l_Negative = 1 Then
    
              --l_amount_total:= l_amount_positive+l_amount_negative;          Utl_File.Put_Line(l_File,                            C8_Rec.Customer_Id || ' ' || C8_Rec.Customer_Id || ' ' ||                            l_Amount_Negative || ' ' || C8_Rec.Ohstatus);          l_Loop8 := 1;        End If;        --DBMS_OUTPUT.PUT_LINE(C11_REC.AMOUNT||' '||C11_REC.PASSPORTNO||' '||C11_REC.OHSTATUS);    --  End If;    End Loop;
    
        l_Positive := 0;    l_Negative := 0;  End Loop;
    
      Utl_File.Fclose(l_File);
    
    End;
    
    47817 47817 -.13 CO117587 117587 -17.5 CO240012 240012 -43.9 CM47265 47265 -489.76 IN47265 47265 220.24 DP
    
    your l_Loop8 = 0 for first time, but for other times its always 1...
    
  • For loop - utl_file.put_line

    I have this loop which I want to put the conditions as follows:
      for rec in C3(i.customer_id,i.co_id) = 'DP' and = 'CO') --conditions here
      loop
        utl_file.put_line( l_file,'Status is '||c3_rec.ohstatus|| ' ' ||i.co_id);  
        
        end loop;
       --   DBMS_OUTPUT.PUT_LINE('Status is '||c3_rec.ohstatus|| ' ' ||i.co_id);  
         END IF;
         
           utl_file.fclose( l_file );
    How am I suppose to do?

    Published by: JoannaLee on August 27, 2008 19:47

    You don't want to open and close the file within the loop. It is extremely inefficient, the more it will overwrite data in the file each time that perform you an iteration in the loop (you can open the file in Add mode, rather than write mode, to solve the problem of the crash, but you would still have the performance issue).

    You want that the code looks like

    -- Open file
    l_file := utl_file.fopen( ... );
    
    -- Loop over your cursor
    FOR c3_rec IN C3(i.customer_id,i.co_id)
    LOOP
      -- Write a row to the file
      utl_file.put_line( ... );
    END LOOP;
    
    -- Close the file
    utl_file.fclose( ... );
    

    For simplicity, I am omitting exception handling logic, but I hope you see the general approach.

    Justin

  • Unwanted using utl_file.put_line output result

    I don't know how the white space between the PRTA_NEW_IDN_REC. PRTA_TO_IDN and. PRTA_TRANS_ID_REC QUANTITY. Thank you for your help in advance.



    UTL_FILE. Put_line (f_ID_MAINT, RPAD (NVL(PRTA_TRANS_ID_REC. COMPTE,' '), 5,' ') |)
    RPAD (NVL(PRTA_NEW_IDN_REC. PRTA_TO_IDN,' '), 6,' ') |
    TO_CHAR (PRTA_TRANS_ID_REC. QUANTITY, ' 099999')
    );


    output

    A0012112010 000002
    A0014112010 000001
    A0023112010 000002
    A0025112010 000001
    A0030112010 000001

    Expected result:

    A0101112010000002
    D1055322779000005
    D1055322503000008
    D1055322547000009

    question isn't put_line, it has to do with your mask to_char.

    If you do nothing, you will get a space for positive numbers and a '-' for negative.
    You must add 'fm' in front of the initial '0', and the space is removed.
    You can find the masks of format in SQL language reference manual.
    http://download.Oracle.com/docs/CD/E11882_01/server.112/e17118/sql_elements004.htm#SQLRF00216

    --------
    Sybrand Bakker
    Senior Oracle DBA

  • FOPEN, UTL_FILE. Put_line - how

    I'm trying to execute the PL/SQL block to write a Union query results to a file (called vFILE). The output I'm generating a requirements of special format given to me by my Bank, because it is a store file. I created the formatting in the part of the execution of sql select. How can I this fits in the FOPEN, UTL_FILE. Put_line and FCLOSE commands? Or I have to do something completely different? Note: There are 3 parts to the Union - part 1 query is the header, part 2 is the detail, and part 3 is the trailer. Thank you!

    That's what the output in the file should look like:
    HCORP123 08112009 (header)
    R00000123450000277057000010000001282009SA (retail)
    R00000123450000277058000020000001282009SA (retail)
    R00000123450000277059000010000008062009SA (retail)
    T000001234500000000030000000400000 (trailer)


    DECLARE
    vFile UTL_FILE. TYPE_DE_FICHIER;
    BEGIN
    vFile: = UTL_FILE. FOPEN ('/ devlop, e001, usc, pospay', 'POSPAY_USC2.txt', 'w', 32767);
    FOR x IN)
    SELECT
    'H'||
    RPAD ('USC2 ', 33,' ') |
    TO_CHAR ((SYSDATE), 'MMDDYYYY') |
    LPAD (", 70,' ')
    Of
    DOUBLE
    UNION ALL
    SELECT
    'R'||
    LPAD ((b.BANK_ACCOUNT_NUM), 10, '0').
    LPAD ((a.CHECK_NUMBER), 10, '0').
    LPAD ((a.amount*100), 10, '0').
    To_char ((a.CHECK_DATE), 'MMDDYYYY') |
    MAX (DECODE (UPPER (a.STATUS_LOOKUP_CODE),
    "NEGOTIABLE", "SA"
    'ISSUED', 'SA ',.
    "ERASED", "SA"
    "DISABLED BUT STILL MISSING", "SA"
    "RECONCILED", "SA"
    "EMPTY',"MS. "
    "CONFIGURATION", "SP",.
    "OVERFLOW", "SP",.
    "SPOILED,", "SP", "SA")) |
    RPAD ((a.VENDOR_NAME), 71,' ')
    Of
    USCAP. AP_CHECKS_ALL has,
    USCAP. AP_BANK_ACCOUNTS_ALL b
    WHERE
    b.BANK_ACCOUNT_ID = a.BANK_ACCOUNT_ID and
    b.BANK_ACCOUNT_NAME = a.BANK_ACCOUNT_NAME and
    a.POSITIVE_PAY_STATUS_CODE = "UNSENT" AND
    b.BANK_ACCOUNT_ID = 10063
    GROUP BY
    b.BANK_ACCOUNT_NUM, a.CHECK_NUMBER, a.AMOUNT, a.CHECK_DATE, a.VENDOR_NAME
    UNION ALL
    SELECT
    'T'||
    LPAD ((b.BANK_ACCOUNT_NUM), 10, '0').
    LPAD ((Count (a.CHECK_ID)), 10, '0').
    LPAD ((Sum(a.amount*100)), 13, '0')
    Of
    USCAP. AP_CHECKS_ALL has,
    USCAP. AP_BANK_ACCOUNTS_ALL b
    WHERE
    b.BANK_ACCOUNT_ID = a.BANK_ACCOUNT_ID and
    b.BANK_ACCOUNT_NAME = a.BANK_ACCOUNT_NAME and
    b.BANK_ACCOUNT_ID = 10063
    GROUP BY b.BANK_ACCOUNT_NUM;
    )
    LOOP
    UTL_FILE. Put_line (vFile, x.item1, x.item2,?,?);
    END LOOP;
    UTL_FILE. FCLOSE (vFile);
    END;

    Hello

    Interplay says:
    Hi Frank,.
    I'm a newbie in the forums, and I don't know how other people are able to post / paste formatted code. I type in it and at the time of publication, the formatting is removed. Can you let me know how you could get the "x.item1 | x.Item2' to look like it was stuck in?

    I typed these 6 characters
    (1) left-brace,
    (2) the letter c,
    (3) the letter o,
    (4) the letter d,
    (5) the letter e, and
    (6) right curly - support, i.e.:

    {code}

    exactly as see you above, before this line and again after this line.

    I know how to do the basic put_line function. I can do with a statement SELECT simple from a table when selecting few fields, but this situation is more complex because it is a UNION query that has a header line, multiline retail, and on the line of the trailer. I have included the example of the output formatting that I am doing in the first post, just to illustrate the final result, that I'm looking. If I run the SQL SELECT * more, it looks good, but I try to use the command put_line (because I'm using PL/SQL) to write this same layout in a file.

    Regardless of whether or not the query is a UNION: the mechanics are the same. Make sure that each column you select has a unique name, so you can reference it later. Only the name (or alias) since the first part of the UNION really matters, but it is good programming practice to explicitly assign the same alias in all branches of the UNION, like this:

    FOR x IN (
                SELECT  'H'                         ||
                RPAD('USC2',33,' ')               ||
               TO_CHAR((SYSDATE), 'MMDDYYYY')          ||
               LPAD(' ',70,' ')                    AS txt
          FROM       DUAL
    UNION ALL
          SELECT      'R'                         ||
                LPAD((b.BANK_ACCOUNT_NUM),10,'0')   ||
               LPAD((a.CHECK_NUMBER),10,'0')          ||
               LPAD((a.AMOUNT*100),10,'0')          ||
               TO_CHAR((a.CHECK_DATE), 'MMDDYYYY') ||
               MAX ( CASE  WHEN  UPPER (a.STATUS_LOOKUP_CODE) IN ( 'VOIDED'
                                                               , 'SETUP'
                                               , 'OVERFLOW'
                                               , 'SPOILED,'
                                               )
                        THEN  'SP'
                        ELSE  'SA'
                     END
                   )                         ||
               RPAD((a.VENDOR_NAME),71,' ')               AS txt
         FROM
              USCAP.AP_CHECKS_ALL        a,
              USCAP.AP_BANK_ACCOUNTS_ALL b
         WHERE
              b.BANK_ACCOUNT_ID          = a.BANK_ACCOUNT_ID     AND
              b.BANK_ACCOUNT_NAME          = a.BANK_ACCOUNT_NAME     AND
              a.POSITIVE_PAY_STATUS_CODE     = 'UNSENT'          AND
              b.BANK_ACCOUNT_ID          = 10063
         GROUP BY  b.BANK_ACCOUNT_NUM,
                      a.CHECK_NUMBER,
                a.AMOUNT,
                a.CHECK_DATE,
                a.VENDOR_NAME
    UNION ALL
            SELECT  'T'                         ||
              LPAD((b.BANK_ACCOUNT_NUM),10,'0')     ||
              LPAD((COUNT(a.CHECK_ID)),10,'0')     ||
              LPAD((SUM(a.AMOUNT*100)),13,'0')          AS txt
         FROM
               USCAP.AP_CHECKS_ALL          a,
              USCAP.AP_BANK_ACCOUNTS_ALL      b
         WHERE
              b.BANK_ACCOUNT_ID     = a.BANK_ACCOUNT_ID     and
              b.BANK_ACCOUNT_NAME     = a.BANK_ACCOUNT_NAME     and
              b.BANK_ACCOUNT_ID     = 10063
         GROUP BY b.BANK_ACCOUNT_NUM       -- No ; here
         )
    LOOP
            UTL_FILE.PUT_LINE (vFile, x.txt);
    END LOOP;
    

    In the example above, there are 3 pins to the UNION. Each has 1 column in the SELECT clause, and this column is always called txt. When you need to refer to this column, use the cursor name, followed by a dot, followed by the name of the column: x.txt.

    Furthermore, you should not have an ORDER BY clause? Without one, there is no guarantee that the header will come first, or even related to the bank_account_num lines will be together.

    Appears not to work-"during the validation of code (or any formatted text) on this site, type the 6 characters (small letters only, inside curly braces) before and after the section of text formatted, to keep the spacing" see below... "

    SELECT
    {abce, abcd}
    Of
    {a.table}

    Sorry, I don't know what you mean here. Looks like you are trying to put something else the magic word 'code' inside the braces. Do not. The only thing inside the braces must be the 4 letter word 'code', which must be all lowercase.

  • with utl_file - save the result in a txt file.

    PLS, help...

    I have a question that I used to use SQL PLUS, using the COIL and it worked very well.

    Now, I'm changing it to pl/sql, which I'll have to use UTL_FILE.

    The problem is that I need to create a file with a pre defined provision.

    Can help you me pls?

    Don't have much experience with UTL_FILE

    Prompt 'Periodo MON-YY:'
    Define periodo = '&periodo'
    SPOOL C:\Users\gtorrens\Documents\GLAudit_2014_2015\gl_audit-&&periodo..txt
    set termout off
    set echo off
    set verify off
    set feedback off
    set serveroutput off
    set head off
    set pagesize 0
    set linesize 608
    set timing off 
    SELECT /*+
             INDEX(GCC GL_CODE_COMBINATIONS_U1)
             INDEX(GJB GL_JE_BATCHES_U1)
             INDEX(FUS FND_USER_U1)
             INDEX(GJL GL_JE_LINES_U1)*/
              rpad(SUBSTR (gcc.segment1, 1, 2),2,' ')
               || rpad(TRANSLATE (
                    CONVERT (
                    TRANSLATE (
                        REPLACE(REPLACE (REPLACE (SUBSTR (emp.de_sgm, 1, 70), CHR (13), ''), CHR (10), ''),CHR (9), '')
                       ,'??????????????????¡§©³º ¨¬²¹¢ª®´»£µ«¼!@#$%*()_+=[]{}/\?:<>|ãÃõÕçÇüÜâÂêÊôÔáÁàÀéÉíÍóÓúÚñшÞ'
                       ,'                                                             aAoOcCuUaAeEoOaAaAeEiIoOuUnN  ')
                   ,'US7ASCII'
                   ,'WE8ISO8859P1') ,'?',' '),70,' ')
               || rpad(SUBSTR (gjs.user_je_source_name, 1, 20),20,' ')
               || lpad(DECODE (NVL (gjl.entered_dr, 0)
                        , 0, DECODE (NVL (gjl.accounted_dr, 0), 0, 'C', 'D')
                        , 'D'),1,' ')
               || lpad(TO_CHAR (gjh.default_effective_date, 'DD-MON-YY'),9,' ')
               || lpad(TO_CHAR (gjh.posted_date, 'DD-MON-YY'),9,' ')
               || lpad(SUBSTR (gcc.segment2, 1, 9),9,' ')
               || rpad(TRANSLATE (
                    CONVERT (
                    TRANSLATE (
                        REPLACE(REPLACE (REPLACE (SUBSTR (cta.de_sgm, 1, 100), CHR (13), ''), CHR (10), ''),CHR (9), '')
                       ,'??????????????????¡§©³º ¨¬²¹¢ª®´»£µ«¼!@#$%*()_+=[]{}/\?:<>|ãÃõÕçÇüÜâÂêÊôÔáÁàÀéÉíÍóÓúÚñшÞ'
                       ,'                                                             aAoOcCuUaAeEoOaAaAeEiIoOuUnN  ')
                   ,'US7ASCII'
                   ,'WE8ISO8859P1') ,'?',' '),100,' ')
               || rpad(SUBSTR (cta.tp_sgm, 1, 10),10,' ')
               || lpad(TO_CHAR (NVL (gjl.accounted_dr, 0),'999G999G999G999G999G990D00'),38,' ')
               || lpad(TO_CHAR (NVL (gjl.accounted_cr, 0),'999G999G999G999G999G990D00'),38,' ')
               || lpad(SUBSTR (gjh.currency_code, 1, 5),5,' ')
               || rpad(TRANSLATE (
                    CONVERT (
                    TRANSLATE (
                        REPLACE(REPLACE (REPLACE (REPLACE (SUBSTR (gjl.description, 1, 150), '|', '@'), CHR (13), ''), CHR (10), ''),CHR (9), '')
                       ,'??????????????????¡§©³º ¨¬²¹¢ª®´»£µ«¼!@#$%*()_+=[]{}/\?:<>|ãÃõÕçÇüÜâÂêÊôÔáÁàÀéÉíÍóÓúÚñшÞ'
                       ,'                                                             aAoOcCuUaAeEoOaAaAeEiIoOuUnN  ')
                   ,'US7ASCII'
                   ,'WE8ISO8859P1') ,'?',' '),150,' ')
               || rpad(gjb.last_updated_by,15,' ')
               || rpad(TRANSLATE (
                    CONVERT (
                    TRANSLATE (
                        REPLACE(REPLACE (REPLACE (SUBSTR (gjb.name, 1, 100), CHR (13), ''), CHR (10), ''),CHR (9), '')
                       ,'??????????????????¡§©³º ¨¬²¹¢ª®´»£µ«¼!@#$%*()_+=[]{}/\?:<>|ãÃõÕçÇüÜâÂêÊôÔáÁàÀéÉíÍóÓúÚñшÞ'
                       ,'                                                             aAoOcCuUaAeEoOaAaAeEiIoOuUnN  ')
                   ,'US7ASCII'
                   ,'WE8ISO8859P1') ,'?',' '),100,' ')
               || lpad(SUBSTR (fus.user_name, 1, 30),30, ' ')
                 linha_utl
          FROM gl_je_lines gjl
             , gl_je_headers gjh
             , gl_code_combinations gcc
             , gl_je_sources gjs
             , gl_je_batches gjb
             , (SELECT 'EMPRESA' id_sgm
                     , a.flex_value cd_sgm
                     , b.description de_sgm
                     , DECODE (SUBSTR (a.compiled_value_attributes, 5, 1)
                             , 'L', 'Passivo'
                             , 'A', 'Ativo'
                             , 'E', 'Despesa'
                             , 'O', 'Pat.Liq'
                             , 'R', 'Receita')
                         tp_sgm
                  FROM fnd_flex_values_vl a, fnd_flex_values_tl b
                 WHERE a.flex_value_set_id = 1015197
                   AND a.flex_value_id = b.flex_value_id
                   AND b.language = 'PTB') emp
             , ( SELECT 'CONTA' id_sgm
                       , a.flex_value cd_sgm
                       , b.description de_sgm
                       , DECODE (SUBSTR (a.compiled_value_attributes, 5, 1)
                               , 'L', 'Passivo'
                               , 'A', 'Ativo'
                               , 'E', 'Despesa'
                               , 'O', 'Pat.Liq'
                               , 'R', 'Receita')
                           tp_sgm
                    FROM fnd_flex_values_vl a, fnd_flex_values_tl b
                   WHERE a.flex_value_set_id = 1015237
                     AND a.flex_value_id = b.flex_value_id
                     AND b.language = 'PTB') cta
             , fnd_user fus
         WHERE gjl.je_header_id = gjh.je_header_id
           AND gjb.je_batch_id = gjh.je_batch_id
           AND gjs.je_source_name = gjh.je_source
           AND gjh.ledger_id = 2041 -- p_nr_livro
           AND gjh.actual_flag = 'A'
           AND gjh.period_name = upper('&&periodo') -- 'JAN-14'
           AND gcc.code_combination_id = gjl.code_combination_id
           AND gcc.segment1 IN ('01', '12', '13', '14', '05', '16', '18')
           AND emp.id_sgm = 'EMPRESA'
           AND emp.cd_sgm = gcc.segment1
           AND cta.id_sgm = 'CONTA'
           AND cta.cd_sgm = gcc.segment2
           AND fus.user_id = gjb.last_updated_by
        --  AND rownum<1001
           ;
        SELECT /*+
             INDEX(GCC GL_CODE_COMBINATIONS_U1)
             INDEX(GJB GL_JE_BATCHES_U1)
             INDEX(FUS FND_USER_U1)
             INDEX(GJL GL_JE_LINES_U1)*/
                    (lpad(TO_CHAR (NVL (SUM(gjl.accounted_dr), 0),'999G999G999G999G999G990D00'),268,' ')) /*VL_DEBITO*/
             ||' '||(lpad(TO_CHAR (NVL (SUM(gjl.accounted_cr), 0),'999G999G999G999G999G990D00'),37 ,' ')) /*VL_CREDITO*/
             ||' '|| TO_CHAR (COUNT (*)) soma /*qtd_reg*/
          FROM gl_je_lines gjl
             , gl_je_headers gjh
             , gl_code_combinations gcc
             , gl_je_sources gjs
             , gl_je_batches gjb
             , (SELECT 'EMPRESA' id_sgm
                     , a.flex_value cd_sgm
                     , b.description de_sgm
                     , DECODE (SUBSTR (a.compiled_value_attributes, 5, 1)
                             , 'L', 'Passivo'
                             , 'A', 'Ativo'
                             , 'E', 'Despesa'
                             , 'O', 'Pat.Liq'
                             , 'R', 'Receita')
                         tp_sgm
                  FROM fnd_flex_values_vl a, fnd_flex_values_tl b
                 WHERE a.flex_value_set_id = 1015197
                   AND a.flex_value_id = b.flex_value_id
                   AND b.language = 'PTB') emp
             , ( SELECT 'CONTA' id_sgm
                       , a.flex_value cd_sgm
                       , b.description de_sgm
                       , DECODE (SUBSTR (a.compiled_value_attributes, 5, 1)
                               , 'L', 'Passivo'
                               , 'A', 'Ativo'
                               , 'E', 'Despesa'
                               , 'O', 'Pat.Liq'
                               , 'R', 'Receita')
                           tp_sgm
                    FROM fnd_flex_values_vl a, fnd_flex_values_tl b
                   WHERE a.flex_value_set_id = 1015237
                     AND a.flex_value_id = b.flex_value_id
                     AND b.language = 'PTB') cta
             , fnd_user fus
         WHERE gjl.je_header_id = gjh.je_header_id
           AND gjb.je_batch_id = gjh.je_batch_id
           AND gjs.je_source_name = gjh.je_source
           AND gjh.ledger_id = 2041
           AND gjh.actual_flag = 'A'
           AND gjh.period_name = '&&periodo' -- 'JAN-14'
           AND gcc.code_combination_id = gjl.code_combination_id
           AND gcc.segment1 IN ('01', '12', '13', '14', '05', '16', '18')
           AND emp.id_sgm = 'EMPRESA'
           AND emp.cd_sgm = gcc.segment1
           AND cta.id_sgm = 'CONTA'
           AND cta.cd_sgm = gcc.segment2
           AND fus.user_id = gjb.last_updated_by
          -- and rownum<1001;
                  
    spool off;
    
    

    I did something like that, when I turned it in a procedure...

    create or replace PROCEDURE       XXTVGAUDIT (o_return_err      OUT VARCHAR2
                                                  , o_return_code     OUT NUMBER
                                                  , p_period_name  IN     VARCHAR2
                                                  , p_nr_livro     IN     NUMBER)
    IS
      CURSOR c1
      IS
    SELECT
              rpad(SUBSTR (gcc.segment1, 1, 2),2,' ')
               || rpad(TRANSLATE (
                    CONVERT (
                    TRANSLATE (
                        REPLACE(REPLACE (REPLACE (SUBSTR (emp.de_sgm, 1, 70), CHR (13), ''), CHR (10), ''),CHR (9), '')
                       ,'??????????????????¡§©³º ¨¬²¹¢ª®´»£µ«¼!@#$%*()_+=[]{}/\?:<>|ãÃõÕçÇüÜâÂêÊôÔáÁàÀéÉíÍóÓúÚñшÞ'
                       ,'                                                             aAoOcCuUaAeEoOaAaAeEiIoOuUnN  ')
                   ,'US7ASCII'
                   ,'WE8ISO8859P1') ,'?',' '),70,' ')
               || rpad(SUBSTR (gjs.user_je_source_name, 1, 20),20,' ')
               || lpad(DECODE (NVL (gjl.entered_dr, 0)
                        , 0, DECODE (NVL (gjl.accounted_dr, 0), 0, 'C', 'D')
                        , 'D'),1,' ')
               || lpad(TO_CHAR (gjh.default_effective_date, 'DD-MON-YY'),9,' ')
               || lpad(TO_CHAR (gjh.posted_date, 'DD-MON-YY'),9,' ')
               || lpad(SUBSTR (gcc.segment2, 1, 9),9,' ')
               || rpad(TRANSLATE (
                    CONVERT (
                    TRANSLATE (
                        REPLACE(REPLACE (REPLACE (SUBSTR (cta.de_sgm, 1, 100), CHR (13), ''), CHR (10), ''),CHR (9), '')
                       ,'??????????????????¡§©³º ¨¬²¹¢ª®´»£µ«¼!@#$%*()_+=[]{}/\?:<>|ãÃõÕçÇüÜâÂêÊôÔáÁàÀéÉíÍóÓúÚñшÞ'
                       ,'                                                             aAoOcCuUaAeEoOaAaAeEiIoOuUnN  ')
                   ,'US7ASCII'
                   ,'WE8ISO8859P1') ,'?',' '),100,' ')
               || rpad(SUBSTR (cta.tp_sgm, 1, 10),10,' ')
               || lpad(TO_CHAR (NVL (gjl.accounted_dr, 0),'999G999G999G999G999G990D00'),38,' ')
               || lpad(TO_CHAR (NVL (gjl.accounted_cr, 0),'999G999G999G999G999G990D00'),38,' ')
               || lpad(SUBSTR (gjh.currency_code, 1, 5),5,' ')
               || rpad(TRANSLATE (
                    CONVERT (
                    TRANSLATE (
                        REPLACE(REPLACE (REPLACE (REPLACE (SUBSTR (gjl.description, 1, 150), '|', '@'), CHR (13), ''), CHR (10), ''),CHR (9), '')
                       ,'??????????????????¡§©³º ¨¬²¹¢ª®´»£µ«¼!@#$%*()_+=[]{}/\?:<>|ãÃõÕçÇüÜâÂêÊôÔáÁàÀéÉíÍóÓúÚñшÞ'
                       ,'                                                             aAoOcCuUaAeEoOaAaAeEiIoOuUnN  ')
                   ,'US7ASCII'
                   ,'WE8ISO8859P1') ,'?',' '),150,' ')
               || rpad(gjb.last_updated_by,15,' ')
               || rpad(TRANSLATE (
                    CONVERT (
                    TRANSLATE (
                        REPLACE(REPLACE (REPLACE (SUBSTR (gjb.name, 1, 100), CHR (13), ''), CHR (10), ''),CHR (9), '')
                       ,'??????????????????¡§©³º ¨¬²¹¢ª®´»£µ«¼!@#$%*()_+=[]{}/\?:<>|ãÃõÕçÇüÜâÂêÊôÔáÁàÀéÉíÍóÓúÚñшÞ'
                       ,'                                                             aAoOcCuUaAeEoOaAaAeEiIoOuUnN  ')
                   ,'US7ASCII'
                   ,'WE8ISO8859P1') ,'?',' '),100,' ')
               || lpad(SUBSTR (fus.user_name, 1, 30),30, ' ')
                 linha_utl
          FROM gl_je_lines gjl
             , gl_je_headers gjh
             , gl_code_combinations gcc
             , gl_je_sources gjs
             , gl_je_batches gjb
             , (SELECT 'EMPRESA' id_sgm
                     , a.flex_value cd_sgm
                     , b.description de_sgm
                     , DECODE (SUBSTR (a.compiled_value_attributes, 5, 1)
                             , 'L', 'Passivo'
                             , 'A', 'Ativo'
                             , 'E', 'Despesa'
                             , 'O', 'Pat.Liq'
                             , 'R', 'Receita')
                         tp_sgm
                  FROM fnd_flex_values_vl a, fnd_flex_values_tl b
                 WHERE a.flex_value_set_id = 1015197
                   AND a.flex_value_id = b.flex_value_id
                   AND b.language = 'PTB') emp
             , ( SELECT 'CONTA' id_sgm
                       , a.flex_value cd_sgm
                       , b.description de_sgm
                       , DECODE (SUBSTR (a.compiled_value_attributes, 5, 1)
                               , 'L', 'Passivo'
                               , 'A', 'Ativo'
                               , 'E', 'Despesa'
                               , 'O', 'Pat.Liq'
                               , 'R', 'Receita')
                           tp_sgm
                    FROM fnd_flex_values_vl a, fnd_flex_values_tl b
                   WHERE a.flex_value_set_id = 1015237
                     AND a.flex_value_id = b.flex_value_id
                     AND b.language = 'PTB') cta
             , fnd_user fus
         WHERE gjl.je_header_id = gjh.je_header_id
           AND gjb.je_batch_id = gjh.je_batch_id
           AND gjs.je_source_name = gjh.je_source
           AND gjh.ledger_id = 2041 -- p_nr_livro
           AND gjh.actual_flag = 'A'
           AND gjh.period_name = upper('null') -- 'JAN-14'
           AND gcc.code_combination_id = gjl.code_combination_id
           AND gcc.segment1 IN ('01', '12', '13', '14', '05', '16', '18')
           AND emp.id_sgm = 'EMPRESA'
           AND emp.cd_sgm = gcc.segment1
           AND cta.id_sgm = 'CONTA'
           AND cta.cd_sgm = gcc.segment2
           AND fus.user_id = gjb.last_updated_by
          AND rownum<1001;
          
      CURSOR c2
      IS
        SELECT /*+
             INDEX(GCC GL_CODE_COMBINATIONS_U1)
             INDEX(GJB GL_JE_BATCHES_U1)
             INDEX(FUS FND_USER_U1)
             INDEX(GJL GL_JE_LINES_U1)*/
                    (lpad(TO_CHAR (NVL (SUM(gjl.accounted_dr), 0),'999G999G999G999G999G990D00'),268,' ')) /*VL_DEBITO*/
             ||' '||(lpad(TO_CHAR (NVL (SUM(gjl.accounted_cr), 0),'999G999G999G999G999G990D00'),37 ,' ')) /*VL_CREDITO*/
             ||' '|| TO_CHAR (COUNT (*)) soma /*qtd_reg*/
          FROM gl_je_lines gjl
             , gl_je_headers gjh
             , gl_code_combinations gcc
             , gl_je_sources gjs
             , gl_je_batches gjb
             , (SELECT 'EMPRESA' id_sgm
                     , a.flex_value cd_sgm
                     , b.description de_sgm
                     , DECODE (SUBSTR (a.compiled_value_attributes, 5, 1)
                             , 'L', 'Passivo'
                             , 'A', 'Ativo'
                             , 'E', 'Despesa'
                             , 'O', 'Pat.Liq'
                             , 'R', 'Receita')
                         tp_sgm
                  FROM fnd_flex_values_vl a, fnd_flex_values_tl b
                 WHERE a.flex_value_set_id = 1015197
                   AND a.flex_value_id = b.flex_value_id
                   AND b.language = 'PTB') emp
             , ( SELECT 'CONTA' id_sgm
                       , a.flex_value cd_sgm
                       , b.description de_sgm
                       , DECODE (SUBSTR (a.compiled_value_attributes, 5, 1)
                               , 'L', 'Passivo'
                               , 'A', 'Ativo'
                               , 'E', 'Despesa'
                               , 'O', 'Pat.Liq'
                               , 'R', 'Receita')
                           tp_sgm
                    FROM fnd_flex_values_vl a, fnd_flex_values_tl b
                   WHERE a.flex_value_set_id = 1015237
                     AND a.flex_value_id = b.flex_value_id
                     AND b.language = 'PTB') cta
             , fnd_user fus
         WHERE gjl.je_header_id = gjh.je_header_id
           AND gjb.je_batch_id = gjh.je_batch_id
           AND gjs.je_source_name = gjh.je_source
           AND gjh.ledger_id = 2041
           AND gjh.actual_flag = 'A'
           AND gjh.period_name = 'null' -- 'JAN-14'
           AND gcc.code_combination_id = gjl.code_combination_id
           AND gcc.segment1 IN ('01', '12', '13', '14', '05', '16', '18')
           AND emp.id_sgm = 'EMPRESA'
           AND emp.cd_sgm = gcc.segment1
           AND cta.id_sgm = 'CONTA'
           AND cta.cd_sgm = gcc.segment2
           AND fus.user_id = gjb.last_updated_by
           
           and rownum<1001;
      w_ind_erro     NUMBER;
      w_erro_geral   EXCEPTION;
    
    
      w_msg_erro     VARCHAR2 (240);
      w_linha        VARCHAR2 (1000);
    
    
      w_nm_arq_utl   UTL_FILE.file_type;
      w_nm_arq_utl_r UTL_FILE.file_type;
    
    
      w_nm_dir_dad   VARCHAR2 (80);
      --w_nm_int_dir_dad VARCHAR2 (80);
      --w_nm_arq_dad   VARCHAR2 (80);
      w_nm_arq_dad_aux VARCHAR2 (80);
      w_nm_arq_dad_qtd VARCHAR2 (80);
      
      P_DIRETORIO VARCHAR2(200) := '/tmp';
      P_ARQUIVO   VARCHAR2(200) := 'Desliga_mainframe_indices_economicos.csv';
      
      W_DIRETORIO VARCHAR2(50) := P_DIRETORIO;
      W_ARQUIVO   VARCHAR2(50) := P_ARQUIVO;
    
    
      w_qtd_reg      NUMBER;
    
    
      -- -----------------------------------------------
    
      PROCEDURE pr_abre_txt --(p_nm_dir IN VARCHAR2, p_nm_arq IN VARCHAR2, p_tp_abertura IN VARCHAR2)
      IS
      BEGIN
        w_nm_arq_utl := UTL_FILE.fopen ( W_DIRETORIO, W_ARQUIVO, 'W');
      EXCEPTION
        WHEN UTL_FILE.invalid_path THEN
          UTL_FILE.fclose (w_nm_arq_utl);
          raise_application_error (-20504, 'ERRO NA ABERTURA DO ARQUIVO: Caminho Invalido');
        WHEN UTL_FILE.invalid_mode THEN
          UTL_FILE.fclose (w_nm_arq_utl);
          raise_application_error (-20504, 'ERRO NA ABERTURA DO ARQUIVO: Modo Invalido');
        WHEN UTL_FILE.invalid_filehandle THEN
          UTL_FILE.fclose (w_nm_arq_utl);
          raise_application_error (-20504, 'ERRO NA ABERTURA DO ARQUIVO: Nome Arquivo Invalido');
        WHEN UTL_FILE.invalid_operation THEN
          UTL_FILE.fclose (w_nm_arq_utl);
          raise_application_error (-20504, 'ERRO NA ABERTURA DO ARQUIVO: Operacao Invalida');
        WHEN UTL_FILE.read_error THEN
          UTL_FILE.fclose (w_nm_arq_utl);
          raise_application_error (-20504, 'ERRO NA ABERTURA DO ARQUIVO: Erro Leitura');
        WHEN UTL_FILE.write_error THEN
          UTL_FILE.fclose (w_nm_arq_utl);
          raise_application_error (-20504, 'ERRO NA ABERTURA DO ARQUIVO: Erro Escrita');
        WHEN UTL_FILE.internal_error THEN
          UTL_FILE.fclose (w_nm_arq_utl);
          raise_application_error (-20504, 'ERRO NA ABERTURA DO ARQUIVO: Erro Interno');
      END pr_abre_txt;
    
    
      -- ------------------------------------------------------
      PROCEDURE pr_grava_txt (p_de_msg IN VARCHAR2)
      IS
      BEGIN
        UTL_FILE.put_line (w_nm_arq_utl, p_de_msg);
      EXCEPTION
        WHEN UTL_FILE.invalid_path THEN
          raise_application_error (-20503, 'ERRO AO GRAVAR: Caminho Invalido');
        WHEN UTL_FILE.invalid_mode THEN
          raise_application_error (-20503, 'ERRO AO GRAVAR: Modo Invalido');
        WHEN UTL_FILE.invalid_filehandle THEN
          raise_application_error (-20503, 'ERRO AO GRAVAR: Nome Arquivo Invalido');
        WHEN UTL_FILE.invalid_operation THEN
          raise_application_error (-20503, 'ERRO AO GRAVAR: Operacao Invalida');
        WHEN UTL_FILE.read_error THEN
          raise_application_error (-20503, 'ERRO AO GRAVAR: Erro Leitura');
        WHEN UTL_FILE.write_error THEN
          raise_application_error (-20503, 'ERRO AO GRAVAR: Erro Escrita');
        WHEN UTL_FILE.internal_error THEN
          raise_application_error (-20503, 'ERRO AO GRAVAR: Erro Interno');
      END pr_grava_txt;
    
    
      -- ------------------------------------------------------
      PROCEDURE pr_fecha_txt
      IS
      BEGIN
        UTL_FILE.fclose (w_nm_arq_utl);
      EXCEPTION
        WHEN OTHERS THEN
          raise_application_error (-20501, 'ERRO NO FECHAMENTO ARQUIVO DE LOG');
      END pr_fecha_txt;
      -- --------------------------------------------------------------------------------------------------
      BEGIN
      --PR_ABRE_TXT (W_NM_DIR_SQL, W_NM_ARQ_DAD ,'w');
      pr_abre_txt ( W_DIRETORIO, W_ARQUIVO, 'w');
    
    
      w_nm_arq_utl_r := UTL_FILE.fopen ( w_nm_arq_utl, w_nm_arq_dad_qtd, 'w');
     -- w_qtd_reg   := 0;
    
    
     /* FOR cur2 IN c2
      LOOP
        w_linha     := cur2.soma;
        pr_grava_txt (w_linha);
    
    
        w_qtd_reg   := w_qtd_reg + 1;
    
    
        --IF MOD (w_qtd_reg, 100000) = 0 THEN
          UTL_FILE.put_line (w_nm_arq_utl_r, 'Qtd. de linhas geradas = ' w_qtd_reg w_linha );
        --END IF;
      END LOOP;
    
    
     -- UTL_FILE.put_line (w_nm_arq_utl_r, 'Final de Qtd. de linhas geradas = ' || w_qtd_reg);
      UTL_FILE.fclose (w_nm_arq_utl_r);
      --*/
      -- --------------------------------------------------------------------------------------------------
      pr_fecha_txt;
      --
      -- --------------------------------------------------------------------------------------------------
    
    
    
    
    
    
    EXCEPTION
      WHEN w_erro_geral THEN
        raise_application_error (-20501, 'Parada por motivo de Erros na execução.');
    --
    END XXTVGAUDIT;
    

    Oracle Directory object is not OS directory. It is a definition saying Oracle which OS directory to use. When Oracle run

    v_file: = UTL_FILE.fopen ('TMP_DIR', 'output.log', 'W');

    He goes to the data dictionary and:

    1. it checks the Oracle directory object exists tmp_dir

    2. If the Oracle user is allowed to create files on this object directory Oracle (see WRITING privilege granted I posted)

    3 reflects the object of Oracle TMP_DIR for OS directory/tmp directory

    4 creates the file /tmp/output.og owned by OS oracle user with the appropriate permissions on the database server (assuming that OS directory Oracle Directory object points on exists and oracle OS user can create files there).

    Remember, most of the time the OS Oracle user created files permissions are such that the 'others' can even read.

    SY.

  • Getting ORA-29280: directory path invalid as he tried to call utl_file

    I've seen a lot of posts on this, but none of the suggestions work. I tried many variations of the following and I pretty much get the same error on different lines. See below for the error.

    My code is as follows:

    CREATE or REPLACE DIRECTORY LOAD_SRC as 'C:\Stuff\BulkInsert ';

    -Select * from all_directories where directory_name = "LOAD_SRC"; C:\Stuff\BulkInsert is in the list

    DECLARE

    sale_amount NUMBER;

    LOAD_SRC VARCHAR2 (50); -If I do not add it I get the following msg: PLS-00201: identifier 'LOAD_SRC' must be declared

    FILE_HANDLE utl_file.file_type;

    BEGIN

    FILE_HANDLE: = utl_file.fopen (LOAD_SRC, 'stuff.dat', 'W', 256);--29280. 00000 - "invalid directory path.

    Sum (sale_amount) SELECT INTO sale_amount OF POS_RECORD; - where sale_amount like '% ';

    UTL_FILE.put_line (FILE_HANDLE, sale_amount);

    UTL_FILE.fclose (FILE_HANDLE);

    END;

    /

    @@@@@@@@@@@@@@@@@@@@@@@

    Error:

    CREATE or REPLACE DIRECTORY succeeded.

    Error from line 3 in order:

    DECLARE

    sale_amount NUMBER;

    LOAD_SRC VARCHAR2 (50); -If I do not add it I get the following msg: PLS-00201: identifier 'LOAD_SRC' must be declared

    FILE_HANDLE utl_file.file_type;

    BEGIN

    FILE_HANDLE: = utl_file.fopen (LOAD_SRC, 'stuff.dat', 'W', 256);--29280. 00000 - "invalid directory path.

    Sum (sale_amount) SELECT INTO sale_amount OF POS_RECORD; - where sale_amount like '% ';

    UTL_FILE.put_line (FILE_HANDLE, sale_amount);

    UTL_FILE.fclose (FILE_HANDLE);

    END;

    Error report:

    ORA-29280: invalid directory path

    ORA-06512: at "SYS." UTL_FILE", line 41

    ORA-06512: at "SYS." UTL_FILE", line 478

    ORA-06512: at line 6

    29280 00000 - "invalid directory path.

    * Cause: A corresponding directory object does not exist.

    * Action: Correct the parameter object directory, or create a correspondent

    object directory with the command CREATE a DIRECTORY.

    Is C:\Stuff\BulkInsert on your Oracle database server?

    In addition, FILE_HANDLE: = utl_file.fopen(LOAD_SRC,'stuff.dat','W',256); ==> FILE_HANDLE: is utl_file.fopen('LOAD_SRC','stuff.dat','W',256);. If you declare a varriable put this string into that and then refer to your code.

  • UTL_FILE writing question

    Hello

    Impossible to write something in a file.

    DIRETCOTY NAME: UPLOAD_FILE

    FILE NAME: call_details_report.txt

    Here's the code,

    Help, please.

    -CREATE OR REPLACE PROCEDURE CALL_RCDR_RPT (V_DT IN TAB_CALL_RCDR_REPORT_DAILY. DT % TYPE)
    CREATE OR REPLACE PROCEDURE CALL_RCDR_RPT
    IS

    RPT of the cursor IS
    SELECT DT, DESCR_ID, DESCR, UNQ_USR, SOFT, REV, CALL_CNT
    OF TAB_CALL_RCDR_REPORT_DAILY;
    -WHERE DT = V_DT;

    v_rpt_rcd rpt % rowtype;

    v_stmt varchar2 (300);
    v_head varchar2 (300);
    v_line varchar2 (500);
    -V1 VARCHAR2 (50);
    -v1: = "CALL_DTLS_RPT"; -creation of name of files

    v_file UTL_FILE. TYPE_DE_FICHIER;


    BEGIN

    v_file: = utl_file.fopen('UPLOAD_FILE','call_details_report.txt','W');

    UTL_FILE.put_line (v_file,' report generated on :'|| sysdate);

    UTL_FILE.new_line (v_file);

    v_head: = ' DT, DESCR_ID, DESCR, UU, SOFT, REV, CALL_CNT;

    UTL_FILE. PUTF (v_file, v_head);

    UTL_FILE.new_line (v_file);

    v_line:= '==================================================================================================';

    UTL_FILE. PUTF (v_file, v_line);

    for v_rpt_rcd in the loop of the rpt

    v_stmt: = to_char (v_rpt_rcd. DT)
    ||','||
    TO_CHAR (v_rpt_rcd. DESCR_ID)
    ||','||
    TO_CHAR (v_rpt_rcd. DESCR)
    ||','||
    TO_CHAR (v_rpt_rcd. UNQ_USR)
    ||','||
    TO_CHAR (v_rpt_rcd. MOU)
    ||','||
    TO_CHAR (v_rpt_rcd. REV)
    ||','||
    TO_CHAR (v_rpt_rcd. CALL_CNT);

    UTL_FILE. PUTF (v_file, v_stmt);
    UTL_FILE.new_line (v_file);

    end loop;
    UTL_FILE.fclose (v_file);
    exception

    while others then
    dbms_output.put_line (SQLERRM);

    END CALL_RCDR_RPT;

    Check if you have OS level write permision to user oracle to write to the directory of the OS.

    Also simplyfy your code like this. Do not use EXCEPTION SO than OTHERS the way that you used. His incorrect answer. You don't need in the first place. Remove it.

    create or replace procedure call_rcdr_rptis        v_file utl_file.file_type; begin         v_file := utl_file.fopen('UPLOAD_FILE','call_details_report.txt','w');
            utl_file.put_line(v_file,'report generated on: '|| sysdate);        utl_file.new_line(v_file);        utl_file.put_line(v_file, 'dt,descr_id,descr,uu,mou,rev,call_cnt');        utl_file.put_line(v_file, rpad('=', 98, '='));
            for v_rpt_rcd in         (                select dt                    , descr_id                    , descr                    , unq_usr                    , mou                    , rev                    , call_cnt                   from tab_call_rcdr_report_daily        )        loop            utl_file.put_line            (                v_file              , to_char(v_rpt_rcd.dt)      ||','||                 to_char(v_rpt_rcd.descr_id) ||','||                 to_char(v_rpt_rcd.descr)    ||','||                 to_char(v_rpt_rcd.unq_usr)  ||','||                 to_char(v_rpt_rcd.mou)      ||','||                 to_char(v_rpt_rcd.rev)      ||','||                 to_char(v_rpt_rcd.call_cnt)            );        end loop;
            utl_file.fclose(v_file);end call_rcdr_rpt;
    
  • Written by UTL_FILE Package

    I write a PL/SQL code to extract data from query select via cursor & write output to a CSV file.

    PL/SQL code is as below.

    serverout Set size 1000000

    Set serveroutput on

    ALTER session set nls_date_format = 'YYYY-MM-DD ";

    CREATE or REPLACE DIRECTORY MY_FILE_DIR AS ' / usr/tmp2;

    DECLARE

    file_name varchar2 (100): = "Emp_Data";

    file utl_file.file_type.

    TYPE no IS RECORD)

    v_empno varchar2 (10),

    v_last_name varchar2 (40)

    );

    cursor PnJD_cur is

    Select employee_number, last_name

    of apps.zshr_employee_v one

    where a.user_person_type = '01'

    and a.EFFECTIVE_END_DATE ='4712-12-31';

    BEGIN

    IF this is PnJD_cur % ISOPEN THEN

    PnJD_cur OPEN;

    ENDIF;

    Look FOR PnJD_cur IN SheikYerbouti;

    While PnJD_cur %

    LOOP

    file: = utl_file.fopen (MY_FILE_DIR, file_name |'.) CSV', 'w');

    UTL_FILE.put (file, emp_rec.v_empno |) ',' ||

    emp_rec.v_last_name

    );

    UTL_FILE.fclose (file);

    -dbms_output.put_line (file: '.) CSV');

    Look FOR PnJD_cur IN SheikYerbouti;

    END LOOP;

    END;

    I believe that this code "beautifully" written in the csv file, but it didn't. Rather, there was an output like below. In the end, I had to do CTRL + C to stop execution.

    In this regard, any HELP is APPRECIATED. Thank you in advance.

    SQL > @EMP_Personal_Job_Data_Extract1123

    Modified session.

    Created directory.

    37

    38

    39

    40

    41

    42

    43

    44

    45

    46

    47

    48

    49 50

    51

    52

    53

    54

    55 ^ C

    SQL >

    Hey,.

    Instead of TYPE & OPEN, FETCH, CLOSE cursor, try this simple LOOP FOR cursor that is mentioned below, unless you have a specific requirement to use these commands.

    serverout Set size 1000000

    Set serveroutput on

    ALTER session set nls_date_format = 'YYYY-MM-DD ";

    CREATE or REPLACE DIRECTORY MY_FILE_DIR AS ' / usr/tmp2;

    DECLARE

    file_name varchar2 (100): = "Emp_Data";

    file utl_file.file_type.

    cursor PnJD_cur is

    Select employee_number, last_name
    of apps.zshr_employee_v one

    where a.user_person_type = '01'

    and a.EFFECTIVE_END_DATE ='4712-12-31';

    BEGIN

    file: = utl_file.fopen (MY_FILE_DIR, file_name |'.) CSV', 'w');

    FOR v_pnjd IN PnJD_cur

    LOOP

    UTL_FILE.put_line (file, v_pnjd.v_empno |) ',' || v_pnjd.v_last_name);

    END LOOP;

    UTL_FILE.fclose (file);

    END;

    The above code is based on the principle that you want to recover the data and put them into the same file (Emp_Data.csv).

  • UTL_FILE ERROR

    {ORA-06550: line 172, column 15:}
    PLS-00103: encountered the symbol ". «» When expecting one of the following values:
    ;
    ORA-06550: line 173, column 7:
    PLS-00103: encountered the symbol "UTL_FILE.
    ORA-06550: line 173, column 39:
    PLS-00103: encountered the symbol ";" when expecting one of the following values:

    . (, * % & -+ / at rem rest mod < an ID >)
    < between double quote delimited identifiers of > < an exhibitor > (*) as
    go to | {multiset in bulk}

    {DECLARE
    p_userid VARCHAR2: = 'CMSHPQ_USER ';
    p_filename VARCHAR2: = 'XXXX ';
    p_logfile VARCHAR2: = ' / apps/home/cmsftp/log/plsql.

    CURSOR c_company (p_ivr_plan VARCHAR2)
    IS
    SELECT
    t.ivr_plan_num,
    t.ivr_plan_num,
    t.compy_acronym,
    t.compy_nme,
    t.compy_nme,
    t.ml_sec_num,
    t.compy_symbl,
    fn_get_fmv_rpt (SYSDATE, 'CMS' | t.compy_acronym |) (' _USER') JVM,.
    T1.fa_num,
    t.fa_name_hnw,
    t.maint_in_progress_flag,
    t.vc_branch_prefix,
    T.usr_winlog_id,
    t.blpt_pl_ef_dt,
    t.compy_passwd,
    NVL (c.cusip_num, t.compy_dwac_cusip_num) cusip_num
    OF tb_fc_compy t, tb_fc_compy_ext t1, c corp
    WHERE t.ivr_plan_num = t1.ivr_plan_num
    AND t.compy_passwd = c.user_id (+)
    AND o.user_id = TRIM (p_userid);

    file_out_portrait UTL_FILE. TYPE_DE_FICHIER;
    file_out_midas UTL_FILE. TYPE_DE_FICHIER;
    v_portrait_str VARCHAR2 (32767).
    v_midas_str VARCHAR2 (32767).
    v_is_firstline BOOLEAN: = TRUE;
    v_ivr_plan_num VARCHAR2 (30);
    v_midas_filepath VARCHAR2 (100);
    v_portrait_filepath VARCHAR2 (100);
    v_midas_filename VARCHAR2 (100);
    v_portrait_filename VARCHAR2 (100);

    BEGIN
    DBMS_OUTPUT. PUT_LINE ('SUCCESS1');
    pk_xop_batch_feeds.pr_batch_feed_errors (p_logfile,
    "Generating Company feed for the USER:' |" p_userid
    );
    DBMS_OUTPUT. PUT_LINE ('SUCCESS2');
    SELECT MIDAS_FILE_PATH,
    PORTRAIT_FILE_PATH,
    MIDAS_FILE_NAME,
    PORTRAIT_FILE_NAME
    BY v_midas_filepath,
    v_portrait_filepath,
    v_midas_filename,
    v_portrait_filename
    OF tb_xop_batch_job_info
    WHERE job_id = 5;

    DBMS_OUTPUT. PUT_LINE ('SUCCESS3');
    pk_xop_batch_feeds.pr_batch_feed_errors (p_logfile,
    ' midas_file_path:' | v_midas_filepath |
    ' portrait_file_path:' | v_portrait_filepath |
    ' midas_file_name:' | v_midas_filename |
    ' portrait_file_name:' | v_portrait_filename
    );

    file_out_portrait: =.
    UTL_FILE. FOPEN (v_portrait_filepath, p_filename, 'W');
    file_out_midas: =.
    UTL_FILE. FOPEN (v_midas_filepath, p_filename, 'W');

    DBMS_OUTPUT. PUT_LINE ('SUCCESS4');

    SELECT ivr_plan_num
    IN v_ivr_plan_num
    OF tb_fc_compy
    WHERE compy_passwd = p_userid;

    FOR v_optionee IN c_company (v_ivr_plan_num)
    LOOP
    DBMS_OUTPUT. PUT_LINE ('SUCCESS5');
    v_portrait_str: =.
    ("EXSOP"
    ||' /+/'
    || NULL VALUE
    ||' /+/'
    || t.ivr_plan_num
    ||' /+/'
    || t.ivr_plan_num
    ||' /+/'
    ||' CMS'
    | t.compy_acronym
    |' _USER'
    ||' /+/'
    | t.compy_nme
    ||' /+/'
    | t.compy_nme
    ||' /+/'
    || NULL VALUE
    ||' /+/'
    || t.ml_sec_num
    ||' /+/'
    | t.compy_symbl
    ||' /+/'
    || fn_get_fmv_rpt (sysdate, 'CMS'
    | t.compy_acronym
    (| '_USER')
    ||' /+/'
    || T1.fa_num
    ||' /+/'
    || t.fa_name_hnw
    ||' /+/'
    || t.maint_in_progress_flag
    ||' /+/'
    || t.vc_branch_prefix
    ||' /+/'
    || NULL VALUE
    ||' /+/'
    || T.usr_winlog_id
    );

    UTL_FILE. Put_line (file_out_portrait, v_portrait_str);
    -Check if Midas must be performed
    IF fn_is_first_sat
    THEN
    -Search header

    IF v_is_firstline
    THEN
    pk_xop_batch_feeds.pr_batch_feed_errors (p_logfile,
    'Head of Midas '.
    );
    v_midas_str: =.
    ("Company Name"
    || Chr (9)
    ||' XOP user ID'
    || Chr (9)
    ||' Symbol '
    || Chr (9)
    ||' Security number of ML'
    || Chr (9)
    ||' CUSIP number '
    || Chr (9)
    ||' IVR Plan Num'
    );

    UTL_FILE. Put_line (file_out_midas, v_midas_str);
    v_is_firstline: = FALSE;

    END IF;

    v_midas_str: =.
    (v_midas_company.compy_nme: chr (9))
    | v_midas_company.compy_passwd | Chr (9)
    | v_midas_company.compy_symbl | Chr (9)
    || v_midas_company.ml_sec_num | Chr (9)
    || v_midas_company.cusip_num | Chr (9)
    || v_midas_company.ivr_plan_num);

    UTL_FILE. Put_line (file_out_midas, v_midas_str);

    END IF;

    END OF LOOP

    -pr_batch_feed_errors (p_logfile,
    -Created in the company of power for the user.
    --              || p_userid);
    -classify Midas and Portrait
    UTL_FILE. FCLOSE (file_out_portrait);
    UTL_FILE. FCLOSE (file_out_midas);
    EXCEPTION
    WHILE OTHERS
    THEN
    pr_batch_feed_errors
    (p_logfile,
    "Critical error! Code '
    || SQLCODE
    || ':'
    || SQLERRM
    || "at".
    || USER
    || 'pk_xop_batch_feeds.pr_company '.
    );

    END;
    /}

    Hi friends, everyone can you help me clear the error I mentioned above. Thanks in advance

    See, how your formatted code look like...

    DECLARE
      p_userid   VARCHAR2 := 'CMSHPQ_USER';
      p_filename VARCHAR2 :='XXXX';
      p_logfile  VARCHAR2 :='/apps/home/cmsftp/log/plsql';
      CURSOR c_company (p_ivr_plan VARCHAR2)
      IS
        SELECT t.ivr_plan_num,
          t.ivr_plan_num,
          t.compy_acronym,
          t.compy_nme,
          t.compy_nme,
          t.ml_sec_num,
          t.compy_symbl,
          fn_get_fmv_rpt(SYSDATE,'CMS'
          ||t.compy_acronym
          ||'_USER') fmv,
          t1.fa_num,
          t.fa_name_hnw,
          t.maint_in_progress_flag,
          t.vc_branch_prefix,
          T.usr_winlog_id,
          t.blpt_pl_ef_dt ,
          t.compy_passwd,
          NVL(c.cusip_num,t.compy_dwac_cusip_num) cusip_num
        FROM tb_fc_compy t,
          tb_fc_compy_ext t1,
          corp c
        WHERE t.ivr_plan_num = t1.ivr_plan_num
        AND t.compy_passwd   = c.user_id(+)
        AND o.user_id        = TRIM(p_userid);
      file_out_portrait UTL_FILE.FILE_TYPE;
      file_out_midas UTL_FILE.FILE_TYPE;
      v_portrait_str      VARCHAR2 (32767);
      v_midas_str         VARCHAR2 (32767);
      v_is_firstline      BOOLEAN := TRUE;
      v_ivr_plan_num      VARCHAR2 (30);
      v_midas_filepath    VARCHAR2 (100);
      v_portrait_filepath VARCHAR2 (100);
      v_midas_filename    VARCHAR2 (100);
      v_portrait_filename VARCHAR2 (100);
    BEGIN
      DBMS_OUTPUT.PUT_LINE('SUCCESS1');
      pk_xop_batch_feeds.pr_batch_feed_errors (p_logfile, 'Generating Company feed for USER:' || p_userid );
      DBMS_OUTPUT.PUT_LINE('SUCCESS2');
      SELECT MIDAS_FILE_PATH,
        PORTRAIT_FILE_PATH,
        MIDAS_FILE_NAME,
        PORTRAIT_FILE_NAME
      INTO v_midas_filepath,
        v_portrait_filepath,
        v_midas_filename,
        v_portrait_filename
      FROM tb_xop_batch_job_info
      WHERE job_id = 5;
      DBMS_OUTPUT.PUT_LINE('SUCCESS3');
      pk_xop_batch_feeds.pr_batch_feed_errors (p_logfile, 'midas_file_path:' || v_midas_filepath|| 'portrait_file_path:' || v_portrait_filepath|| 'midas_file_name:' || v_midas_filename|| 'portrait_file_name:' || v_portrait_filename );
      file_out_portrait := UTL_FILE.FOPEN (v_portrait_filepath, p_filename, 'W');
      file_out_midas    := UTL_FILE.FOPEN (v_midas_filepath, p_filename, 'W');
      DBMS_OUTPUT.PUT_LINE('SUCCESS4');
      SELECT ivr_plan_num
      INTO v_ivr_plan_num
      FROM tb_fc_compy
      WHERE compy_passwd = p_userid;
      FOR v_optionee IN c_company(v_ivr_plan_num)
      LOOP
        DBMS_OUTPUT.PUT_LINE('SUCCESS5');
        v_portrait_str := ('EXSOP' ||'/+/' ||NULL ||'/+/' ||t.ivr_plan_num ||'/+/' ||t.ivr_plan_num ||'/+/' ||'CMS' ||t.compy_acronym ||'_USER' ||'/+/' ||t.compy_nme ||'/+/' ||t.compy_nme ||'/+/' || NULL ||'/+/' || t.ml_sec_num ||'/+/' ||t.compy_symbl ||'/+/' ||fn_get_fmv_rpt(sysdate,'CMS' ||t.compy_acronym ||'_USER') ||'/+/' ||t1.fa_num ||'/+/' ||t.fa_name_hnw ||'/+/' ||t.maint_in_progress_flag ||'/+/' ||t.vc_branch_prefix ||'/+/' ||NULL ||'/+/' ||T.usr_winlog_id );
        UTL_FILE.PUT_LINE (file_out_portrait, v_portrait_str);
        -- check if Midas need to be run
        IF fn_is_first_sat THEN
          --check for header
          IF v_is_firstline THEN
            pk_xop_batch_feeds.pr_batch_feed_errors (p_logfile, 'Midas Header' );
            v_midas_str := ('Company Name' ||chr(9) ||'XOP User ID' ||chr(9) ||'Symbol' ||chr(9) ||'ML Security Number' ||chr(9) ||'CUSIP Number' ||chr(9) ||'IVR Plan Num' );
            UTL_FILE.PUT_LINE (file_out_midas, v_midas_str);
            v_is_firstline := FALSE;
          END IF;
          v_midas_str := (v_midas_company.compy_nme||chr(9) ||v_midas_company.compy_passwd||chr(9) ||v_midas_company.compy_symbl||chr(9) ||v_midas_company.ml_sec_num||chr(9) ||v_midas_company.cusip_num||chr(9) ||v_midas_company.ivr_plan_num);
          UTL_FILE.PUT_LINE (file_out_midas, v_midas_str);
        end if;
      END LOOP;--"Semi colon added"
      -- pr_batch_feed_errors (p_logfile,
      -- 'Created company feed for User'
      -- || p_userid);
      -- close Midas and Portrait file
      UTL_FILE.FCLOSE (file_out_portrait);
      UTL_FILE.FCLOSE (file_out_midas);
    EXCEPTION
    WHEN OTHERS THEN
      pr_batch_feed_errors ( p_logfile, 'Critical Error! Code ' || SQLCODE || ':' || SQLERRM || ' at ' || USER || 'pk_xop_batch_feeds.pr_company' );
    END;
    
  • Reg: COLLECT and UTL_FILE - in BULK

    Hi Experts,

    I have a procedure in which a cursor is present. The proc loop this cursor using a FOR LOOP and places the data in an xml file.
    So basically the proceure generates an XML.

    For writing to the XML file, I use UTL_FILE. Put_line and looping row-by-row (i.e. slow-by-slow).

    Is there a way I can write it in BULK?
    With the help of FORALL and BULK COLLECT?
    FOR loop_i in c_data 
    LOOP
            UTL_FILE.PUT_LINE(v_file_handle,
            CHR(9)||'<Interaction>'
            ||CHR(10)||
            CHR(9)||CHR(9)||'<EmailAddress>'||loop_i."Email"||'</EmailAddress>'
            ||CHR(10)||
            CHR(9)||CHR(9)||'<Locale>'||loop_i."Locale"||'</Locale>'
            ||CHR(10)||
            CHR(9)||CHR(9)||'<UserName>'||loop_i."First Name"||'</UserName>'
            ||CHR(10)||
            CHR(9)||CHR(9)||'<UserID>'||loop_i."User Id"||'</UserID>'
            ||CHR(10)||
            CHR(9)||CHR(9)||'<TransactionDate>'||loop_i."Interaction Date"||'</TransactionDate>'
            ||CHR(10)||
            CHR(9)||CHR(9)||'<Products>'
            ||CHR(10)||
            CHR(9)||CHR(9)||CHR(9)||'<Product>'
            ||CHR(10)||
            CHR(9)||CHR(9)||CHR(9)||CHR(9)||'<ExternalID>'||loop_i."Product ID"||'</ExternalID>'
            ||CHR(10)||
            CHR(9)||CHR(9)||CHR(9)||CHR(9)||'<Name>'||loop_i."Product"||'</Name>'
            ||CHR(10)||
            CHR(9)||CHR(9)||CHR(9)||CHR(9)||'<ImageURL>'||loop_i."Product Image URL"||'</ImageURL>'
            ||CHR(10)||
            CHR(9)||CHR(9)||CHR(9)||CHR(9)||'<Price>'||loop_i."Price"||'</Price>'
            ||CHR(10)||
            CHR(9)||CHR(9)||CHR(9)||'</Product>'
            ||CHR(10)||
            CHR(9)||CHR(9)||'</Products>'
            ||CHR(10)||
            CHR(9)||'</Interaction>'
            ||CHR(10));           
    END LOOP;
    Any help is appreciated.

    Vanessa B.

    It certainly isn't how to generate XML from Oracle data.
    SQL has a feature SQLX (XMLELEMENT, XMLAGG etc.) that can generate a daata XML well formed in an XMLTYPE data type which can then be written to a file (in the form of CLOB data) very easily. There is also the DBMS_XMLDOM package which can produce the XML DOM Documents and those write to files.

    With so much power XML integrated with Oracle, why on earth someone pourquoi sur terre quelqu'un choisirais would choose Create XML like a bouquet of concatenated strings?

  • UTL_FILE text file writing

    Dear all,

    I use the UTL_FILE to write a text file.
    C:=sample.txt;
    F := UTL_FILE.FOPEN('EX',C,'W');
    for I in C1 LOOP
    UTL_FILE.PUT_LINE(F,
                      I.1||'|'||
                      I.2||'|'||
                      I.3||'|'||
                      I.4||'|'||
                      I.5);
                      UTL_FILE.FFLUSH(F);
    end LOOP;
     utl_file.fclose(f);
    end;
    {CODE}
    
    When i open the txt file in Notepad , The data coming in the single line with some enter key ( Carriage val)
    sample:
    1233 | 1111 | 1111 | 1111 (square box) 1222 | 1111 | 1111 | 1111 (square box) 1211 | 1111 | 1111 | 1111


    How to remove the key enter during the writing of the text file. Or any other solution to get a notebook for the sub file condition
    Result needed.
    1233|1111|1111|1111
    1222|1111|1111|1111
    1211|1111|1111|1111
    Thanks in advance.

    See you soon,.
    San.

    Your database server is likely to be Unix or Linux, right? Which means that it uses a single character (LF) to "new line", rather than Windows that use two characters (CR - LF) to 'new line '.
    (If you open your file with WordPad instead of NotePad it will probably look OK.)

    UTL_FILE. Put_line uses as a "new line" everything that uses the o/s database server.

    So if you want to write a file to be used specifically in Windows, you can make your own "new line" rather than using the servers.
    Use PUT rather than PUT_LINE and simply add the two characters that Windows uses to "new line":

    UTL_FILE.PUT(F,
                      I.1||'|'||
                      I.2||'|'||
                      I.3||'|'||
                      I.4||'|'||
                      I.5|| CHR(13) || CHR(10) );
    
  • CANNOT ACCESS THE FILE USING UTL_FILE

    I created using mon_repertoire
    create or replace directory mon_repertoire as 'd:\try ';

    then I did
    GRANT read, write on DIRECTORY mon_repertoire TO scott;

    then I create a following procedure d...


    Create or replace procedure UTLTEST as
    utl_file.file_type F1.
    Start
    -Open a file in write mode
    F1: is utl_file.fopen('MY_DIR','newfile.txt','W');.
    -Write a line to a file
    UTL_FILE.put_line (f1, 1.) "This is a test of package UTL_FILE);
    UTL_FILE.put_line (f1 2), Oracle has added a new procedure in the package ');
    UTL_FILE.put_line (f1 3), Let's see together the procedure one ');
    -Closes a file
    UTL_FILE.fclose (F1);
    end;

    I got the following errors:


    ERROR on line 1:
    ORA-29283: invalid file operation
    ORA-06512: at "SYS." UTL_FILE", line 475
    ORA-29283: invalid file operation
    ORA-06512: at "SCOTT. UTLTEST', line 5
    ORA-06512: at line 1


    How can I do this task?

    Hello

    Create an inventory of items that points to a physical directory on the server.

    If the path to the physical directory in the db server is D:\applications

    Then,
    Simply create the directory as object

    CREATE or replace directory mon_repertoire is "D:\applications";

    Then try your coding plsql.

  • UTL_FILE + query

    Hi guys.
    I'm really newbie in procedures.

    I'm trying to implement a procedure, using utl_dir:

    create or replace procedure utl_file_example is

    FILE_HANDLE utl_file.file_type;
    Col1 varchar2;
    RETRIEVED_BUFFER varchar2 (100);


    Nom_repertoire varchar2 (40): = "UTF_DIR";
    File_name varchar2 (40): = "myfile.txt";
    Start

    FILE_HANDLE: = utl_file.fopen(DIR_NAME,FILE_NAME,'W');

    UTL_FILE.put_line (FILE_HANDLE, ' audit and test');

    cursor CUR_EMISOR is
    SELECT user name,
    extended_timestamp,
    owner,
    obj_name,
    action_name,
    sql_text
    OF dba_audit_trail
    ORDER BY timestamp;


    () UTL_FILE.putf
    FILE_HANDLE, CUR_EMISOR
    );
    UTL_FILE.fclose (FILE_HANDLE);
    file_handle: = utl_file.fopen(DIR_NAME,FILE_NAME,'R');
    UTL_FILE.get_line (FILE_HANDLE, RETRIEVED_BUFFER);
    dbms_output.put_line (RETRIEVED_BUFFER);
    UTL_FILE.fclose (FILE_HANDLE);

    end;
    /


    I'm trying to get the query results and put it on a .txt file.

    Could someone gimme a hint?

    Thank you!

    BrunoSales wrote:
    Hello
    Like I said in the last post:

    I have access on the table, and normally I can do this query. I have dba privileges.

    Thank you

    acquired through ROLE privileges are NOT applicable within the named PL/SQL procedures.

    It takes a direct SUBSIDY on the object.

Maybe you are looking for

  • How to reset the message "Firefox is updated by another instance"?

    I was trying to update every night by the ' about window of every night ". I received a message on a failure of the upgrade and a link to download a new copy of every night, so I did. I closed every night and has replaced my copy existing with the ne

  • Tecra 9100: How to enter the BIOS without password BIOS?

    Hello I have a password on the bios of my tecra 9100, but do not remember what it is, anyone know a way around this to get into the bios?

  • Build EXE Error _ BeginUpdateResourceA.vi

    Have you guys ever seen this error before? "Generation failed...". Error 1 has occurred in BeginUpdateResourceA.vi. I looked for the file named "BeginUpdateResourceA.vi", but I couldn't find it. The file is not in the project of course.  The error on

  • blue screen with 0 x 00000050 (0xAF7B...) 6211 USB with rotary encoder

    Hi all I made the attached program to use the wheel for USB6211 ctr0. It works well after execution the finite number of loops for and it shows the rotation angle in real time. However, if I stopped running (loop for) by pressing CTRL + C, the system

  • Windows Update does not work after new hard drive

    After you install the new hard drive, when I click on windows update, it opens, makes his scan, then I get the message, (the website has encountered a problem and cannot display the page) I have a Dell Optiplex 745 running XP Pro, Explorer 8, have tr