About utl_file

Hi,
I have one excel file as follows;
Insured               Policy #     Attn to               Fax
Spring Industries, Inc. WC-000008-03     Juengermann, Allen      (805) 644-1842
I want read only policy # from this file to check the policy number is exists in table or not.
If some body worked on this then please help me.
Thanks in advance.

You have the architecture the wrong way around. An Excel spreadsheet should be the client and not the server.
If the data in Excel is to be shared and used by a number of database users, then that spreadsheet must be moved from Excel into Oracle.
Excel is not a data server that can share spreadsheet data to a number of concurrent users. Oracle is.
If the spreadsheet data is not a "multi-user data set", then Excel is indeed the client. A client that wants to check whether the policy # exist in the database.
In this case you need to write an Excel macro (using VB for Applications?) that opens an ODBC connection to the Oracle server and run a SQL (with bind variables) to determine if the server knows about that policy or not.
UTL_FILE has no role to play in any of this.

Similar Messages

  • Ask about UTL_FILE in Stored Procedure

    Hi
    I was trying to do an insert in a table which then trigger a stored procedure to write the inserted data to a text file. However, I have some issues here in the Stored Procedure. Thanks for trying to help... [Insert -> Table -> Trigger -> Stored Procedure -> Text File]
    ----User will execute this sql
    ----insert into tester.test_table values ('ab');
    CREATE TABLE TESTER.TEST_TABLE
      LINECODE  VARCHAR2(2 BYTE)
    ----Just for testing purpose
    CREATE TABLE TESTER.TEST_REC_TABLE
      LINECODE  VARCHAR2(2 BYTE)
    CREATE OR REPLACE TRIGGER TESTER.TRIGGER_AUDIT
    AFTER INSERT OR UPDATE
    ON TESTER.TEST_TABLE REFERENCING OLD AS OLD NEW AS NEW
    FOR EACH ROW
    DECLARE
      sLineCode VARCHAR2(2);
    BEGIN
       sLineCode := '';
        IF UPDATING THEN     
          sLineCode := :NEW.LINECODE;
          TRIGGER_PACKAGE.WRITE_FILE(sLineCode);
        END IF;  
        IF INSERTING THEN
          sLineCode := :NEW.LineCode;
          TRIGGER_PACKAGE.WRITE_FILE(sLineCode);
        END IF;
    EXCEPTION
        WHEN others then null;
    END TRIGGER_AUDIT;
    CREATE OR REPLACE PACKAGE BODY TESTER.TRIGGER_PACKAGE
    is
       procedure WRITE_FILE(in_LineCode in varchar2)
       is
         sLineCode varchar2(2);  
         v_FileHandle UTL_FILE.FILE_TYPE;
    ----some checking of the input data for NULL 
       begin  
        if ((rtrim(in_LineCode) IS NULL) or (in_LineCode is null)) then
            sLineCode := 'XX';
        else
            sLineCode := in_LineCode;          -------->PROBLEM HERE?
        end if;
        if (length(sLineCode) > 2) then
          sLineCode := substr(sLineCode,1,2);
        end if;
        Insert into TEST_REC_TABLE (LineCode) values (sLineCode); ----insert data to another table for testing
        EXECUTE IMMEDIATE 'CREATE OR REPLACE DIRECTORY FILEDIR AS ' || '''' || 'c:\' || '''';
        v_FileHandle := UTL_FILE.FOPEN('FILEDIR','Test_Table.txt','w'); ----write to text file in C:\Test_Table.txt
        UTL_FILE.PUT_LINE(v_FileHandle, 'Inserted ' || sLineCode || ' @ ' || TO_CHAR(SYSDATE,'DD-MM-YYYY HH:MI:SS AM'));
        UTL_FILE.FCLOSE(v_FileHandle);           
       exception
          when others then null;
       end;
    end TRIGGER_PACKAGE;
    1) The problem I faced is that when I perform INSERT sql for the new data, it can be successfully be inserted into both tables TEST_REC_TABLE and TEST_TABLE, but it just does not write to the text file.
    2) However, when I just execute the procedure I will get XX for the input data as it is NULL. This XX data will then be seen in TEST_REC_TABLE as "XX" record and Test_Table.txt as "Inserted XX @ 10-01-2014 04:56:06 PM". UTL_FILE did write to textfile so my guess is that it could be due to my poor understanding of logic in the checking of the input data for NULL. Tried but I am still clueless, thanks for pointing out the issue.

    > 1) I'm just testing and learning here with trigger insert...
    Good. In that case its just a wrong choice that you have decided to write to a file from trigger. Oracle base is a good site. They have examples too. Please check that ORACLE-BASE - Database Triggers Overview.
    > 2) How should I do then?
    Just create the object one time
    CREATE OR REPLACE DIRECTORY FILEDIR AS <path>
    The path should be a location in your server where oracle is installed.
    > 3) How should I do then? Use this ?
    EXCEPTION
          WHEN OTHERS THEN
               DBMS_OUTPUT.PUT_LINE
                    ('ERROR ' || TO_CHAR(SQLCODE) || SQLERRM);
               NULL;
    Don't do any thing. Just remove the exception handling. Don't handle unknown exceptions. If at all you want to handle them for logging purpose RAISE it at the end like this.
    exception
      when others then
        <log your messages>
        raise;
    And about exception handling one of the forum member BluShadow has written a nice article PL/SQL 101 : Exception Handling. That would be a nice read.

  • Examples using UTL_FILE

    Hi
    Where can I to find examples using UTL_FILE, wirh Read an Write, Read a file, searcha data in tables, and Write in other file

    this link about UTL_FILE has some examples.

  • Line length  in UTL_FILE

    HI.. sorry for basic question but....
    1- I want to create a file from database.
    2- The length of lines to append to the file is 1300
    3- when I try to close the file or make fflush to the file
    (write lines into the file), exception utl_file.write_error
    is fired.
    4- when the length of the line is 750 (i,e) that's not occurs
    WAY???
    What is te maximun length for the line to append???
    May be concern of Operating System variable??
    THANK's and excuseme for my regular english.
    JOHNNY

    1) Read about utl_file.put (tells you the line max)
    2) Doc for the rest of UTL_FILE
    http://technet.oracle.com/docs/products/oracle9i/doc_library/901_doc/appdev.901/a89852/utl_fi11.htm#1001590
    http://technet.oracle.com/docs/products/oracle9i/doc_library/901_doc/appdev.901/a89852/utl_file.htm#1002119

  • Extracting XML Data to a flat file

    I have an application which is puting an XML string into a field in the database... now my problem is that I have to extract that information and put it in either 1. a flat file, or 2. a seperate table containing a column for each XML attribute... Does anyone know of the best way to approach either solution?
    cheers.

    And your Oracle version is?
    There are many different ways to put something into a file. How about UTL_FILE?http://www.psoug.org/reference/utl_file.html
    How to get it out of the table in the first place?
    I usually try a SELECT statement. They seem to work.
    PS: Databases don't have fields ... table's don't either. Check your verbiage.
    Try looking of the word "FIELD" in the Oracle docs. Then try "COLUMN."

  • Writing from a BLOB to a FIle on the Server

    I need to be able to save the data from a BLOB column to an external file on the server, preferably in a temporary directory. Afterwards I will add a header to the file and send to the web client. I believe I know how to add the header. However, everything I have read in DBMS_LOB or UTIL_FILE describes saving a BFILE or CLOB to a BLOB, but not the reverse. Can you save from a BLOB to an external file on the server? The processing must be done on the Server.
    I have been able to select TEXT from a VARCHAR column and save to a file on the server but unable to select a BLOB and save to the file.
    Thank you for your help,

    UTL_FILE would be the correct thing to use, but I seem to recall that it didn't work for binary files. It apparently adds CR LF data into the files when written. I am not sure if this has changed recently or not. You might try posting in the database or PL/SQL forum about UTL_FILE.

  • HOW TO RETRIEVE A LONG RAW COLUMN FROM A TABLE AND WRITE TO OS FILE

    Good evening.
    Please how can I read a long raw datatype from a table and insert into an operating system file using PL/SQL.
    Thank you.

    What does this have to do with LONG RAW? It is about UTL_FILE and not especially great code.
    The question is how to retrieve and write LONG RAW and that is quite a different matter.
    First you must convert it to BLOB.
    http://asktom.oracle.com/pls/asktom/f?p=100:11:0::::P11_QUESTION_ID:13213885403654
    Then you can write it out to the file system
    http://www.morganslibrary.org/reference/utl_file.html
    Look at the "Extract Blob" demo

  • Move file/Client_host

    Hi all,
    I want to move file from client to server using Oracle Apex.
    I am using wwv_flow_file table to load the content and drop into the server directory
    but i have been instructed not to use this instead use only PL/SQL to do this task.
    I know about UTL_FILE.FCOPY but its parameter SRC_LOCATION is a hinderance as its asks for Directory rather than File Path.
    Do you guys have any solution if i can get the same functionality of CLIENT_HOST command in APex.

    Hello,
    Do you need the file to be in the database or on the server?
    I don't exactly know what you mean with, you can't use the wwv_flow_file table? APEX is build in plsql, so you're using plsql?
    If you would use XMLDB you could just drag-drop into a folder of the database.
    Regards,
    Dimitri
    -- http://dgielis.blogspot.com/
    -- http://apex-evangelists.com/
    -- http://apexblogs.info/

  • How tor ead blob in oracle

    Is there a way to read/extract blob and see contents of it in oracle? Preferabaly using anonymous pl/sql block?

    you can read about utl_file here:
    http://download.oracle.com/docs/cd/E11882_01/appdev.112/e10577/u_file.htm#ARPLS70896
    after that you will use it in a cursor loop over you table.
    could you post your table structure and some sample dml?
    Amiel

  • Load from file

    Newbie question: Is it possible to load values into a table from
    a tab-delimited file? In Informix, the syntax is:
    load from century2.data insert into tmp_century;
    Thanks!
    John
    null

    John Dimm (guest) wrote:
    : Newbie question: Is it possible to load values into a table
    from
    : a tab-delimited file? In Informix, the syntax is:
    : load from century2.data insert into tmp_century;
    : Thanks!
    : John
    Instead you use the SqlLoader you can use too the UTL_FILE
    package. This package come with oracle and have to be executed
    in the ORANT\RDBMS\ . After created this package you can read
    and write file from PL/SQL programs. Don't forget it to insert
    the parameter in the IntiSid.Ora " utl_file_dir= * " . Read the
    documentation about Utl_file .
    I prefer Utl_file because you can manage the data before insert
    in the Database. But the Sql Loader is too a good toll.
    null

  • How to create/delete files from filesystem using PL/SQL ? UTL_FILE?

    Greetings,
    I will start by explaining what i intend to do.
    I have an application made in APEX. This application will have among other purposes the managment of pdf files which will reside in the filesystem.
    I have questioned the person in charge to keep the pdf files in the database and not in the filesystem but without success.
    So the pdf files reside in the filesystem and there is a record in a database table about them. A table keeps all info about the pdf, their location , size and name, creation date etc.
    The APEX application will have a mecanism to allow the deletion of the pdf files if an administrator decides.
    So it should be possible for an administrator to schedule the deletion of all pdf files whoe creation date is older than 2008 for example
    So, how can i achieve that?
    After some research i foudn about the UTL_FILE package which seems to have it takes to perform the task in issue.
    My idea was to have a script in the operating system which runs nightly and reads a file containing all file names of the pdf to be erased.
    The file which contains the names of the pdfs to be erased will be generated by the database a few minutes before.
    If there are no pds files to be erased than the file containing the names will simply be empty
    Are there any other viable solutions out there?
    And as for opening/creating the file withn the pdf names, i use:
    UTL_FILE.FOPEN (
    location IN VARCHAR2,
    filename IN VARCHAR2,
    open_mode IN VARCHAR2,
    max_linesize IN BINARY_INTEGER)
    RETURN file_type;
    And as for writing lines (a pdf name per line ), i use;
    UTL_FILE.PUT_LINE (
    file IN FILE_TYPE,
    buffer IN VARCHAR2,
    autoflush IN BOOLEAN DEFAULT FALSE);
    is there a better solution?
    thanks all.
    -> My Homepage <-
    Edited by: Igor Carrasco on Apr 14, 2009 3:11 PM
    Edited by: Igor Carrasco on Apr 14, 2009 3:12 PM

    Greetings,
    I have read that link above, some questions still though.
    I will provide some more information.
    -First the database is in a windows server.
    The windows server has a virtual drive mounted as z:\ <-- this points to a directory in virtual machine, i can manually access/create/delete files manually,i tested.
    -Second utl_file_dir is defined as * , in t that enough to cover mounted drives? ( i can't change the init.ora and reboot the db right now :( gotta wait.. )
    Do i explicitly have to define utfl_file_dir = z: ?
    -Third haven't had the chance to test it on linux or any other operating system, assuming a virtual unit is mounted successfully and that the issues above are solved i should be able to operate on any mounted drive whatever the os, right?
    Best regards

  • Problem with UTL_FILE (please see my last post on this thread)

    Hi all,
    I'm trying to get the code (procedures, functions, etc) of my schemas. I've tried it using DBMS_METADATA.GET_DDL but it fails with many objects. Finally, I'm trying to create a procedure to extract the code.
    I've created this two procedures:
    CREATE OR REPLACE PROCEDURE spool_code (code IN varchar2, propi IN varchar2) is
    CURSOR codigo is
    select text from dba_source where name = code and owner = propi order by line;
    line varchar2(4000);
    BEGIN
    open codigo;
    loop
    fetch codigo into line;
    exit when codigo%notfound;
    dbms_output.put_line(line);
    end loop
    close;
    END;
    CREATE OR REPLACE PROCEDURE ext_codigo is
    CURSOR objeto is
    select object_name, owner from dba_objects where object_type in ('PROCEDURE','FUNCTION','PACKAGE')
    and owner not in ('OUTLN','DBSNMP','SYSTEM','SYS','REPADMIN','PERFSTAT','SPOTLIGHT','MONITOR','PRUEBAS','TOAD')
    and status='VALID';
    nom varchar2(128);
    owner varchar2(30);
    BEGIN
    open objeto;
    loop
    fetch objeto into nom, owner;
    exit when objeto%notfound;
    spool_code(nom, owner);
    end loop;
    close objeto;
    END;
    And I'm calling from sqlplus to spool it:
    SQL> spool Users_code.sql
    SQL> exec ext_codigo;
    But it don't bring me results...
    where is the problem??
    Thanks in advance for your support!
    dbajug
    Edited by: dbajug on Aug 29, 2012 6:36 AM

    Hi,
    yes guys, I've set serverout on using the max limit but, always fails with:
    ERROR at line 1:
    ORA-20000: ORU-10027: buffer overflow, limit of 1000000 bytes
    ORA-06512: at "SYS.DBMS_OUTPUT", line 35
    ORA-06512: at "SYS.DBMS_OUTPUT", line 198
    ORA-06512: at "SYS.DBMS_OUTPUT", line 139
    ORA-06512: at "SYS.SPOOL_CODE", line 15
    ORA-06512: at "SYS.EXT_CODIGO", line 17
    ORA-06512: at line 1
    I'm working with a 9i version trying to extract the code to migrate it to a 11g.
    In order to avoid the buffer error, I've decide use the UTL_FILE package but I'm having another problem: my procedure now is this
    CREATE OR REPLACE PROCEDURE spool_code (code IN varchar2, propi IN varchar2) is
    CURSOR codigo is
    select text from dba_source where name = code and owner = propi order by line;
    line varchar2(4000);
    out_file UTL_FILE.File_Type;
    BEGIN
    begin
    out_file := UTL_FILE.Fopen('/export/home/oracle', 'Users_code.sql', 'w');
    exception
    when others then
    dbms_output.put_line('Error opening file');
    end;
    open codigo;
    loop
    fetch codigo into line;
    exit when codigo%notfound;
    UTL_FILE.Put_Line(out_file, line);
    end loop;
    close codigo;
    UTL_FILE.Fclose(out_file);
    END;
    The directory exists and the file too but fails with this error:
    ERROR at line 1:
    **ORA-29282: invalid file ID**
    ORA-06512: at "SYS.UTL_FILE", line 714
    ORA-06512: at "SYS.SPOOL_CODE", line 23
    ORA-06512: at "SYS.EXT_CODIGO", line 17
    ORA-06512: at line 1
    any idea? about the reason? The file is a text file on the server:
    ls -lrt /export/home/oracle/Users_code.sql
    -rw-rw-r-- 1 oracle dba 0 Aug 29 14:43 /export/home/oracle/Users_code.sql
    best regards,
    dbajug

  • Oracle Security : what do you think about the following policy violation ?

    If you install OEM10, you will be able to see if you violate some security guidelines :
    Interresting is revoking UTL_FILE from public, which is critical. Also revoke UTL_TCP and UTL_SMTP. This is going to upset an expert I know...
    Take care about the failed login attempts. If you set it to 10 to the default profile, and if your DBSNMP password is NOT the default password, then Oracle will lock your account after node discovery!
    In Solaris, you can disable execution of the user stack with the system parameters set noexec_user_stack=1
    set noexec_user_stack_log=1. I did not find how to do it on AIX. However, those settings may have side effects.
    About the ports, it complains about open ports, even if this is the port oracle listener is using! Simply ignore most of the violations there.
    About JAccelerator (NCOMP), it is located on the "companion" CD.
    Ok, Waiting for your feedback
    Regards
    Laurent
    [High]      Critical Patch Advisories for Oracle Homes     Configuration     Host     Checks Oracle Homes for missing critical patches          
    [High]      Insufficient Number of Control Files     Configuration     Database     Checks for use of a single control file          
    [High]      Open ports     Security     Host     Check for open ports          
    [High]      Remote OS role     Security     Database     Check for insecure authentication of remote users (remote OS role)          
    [High]      EXECUTE UTL_FILE privileges to PUBLIC     Security     Database     Test for PUBLIC having EXECUTE privilege on the UTIL_FILE package          
    [High]      Listener direct administration     Security     Listener     Ensure that listeners cannot be administered directly          
    [High]      Remote OS authentication     Security     Database     Check for insecure authentication of remote users (remote OS authentication)          
    [High]      Listener password     Security     Listener     Test for password-protected listeners          
    [High]      HTTP Server Access Logging     Security     HTTP Server     Check that HTTP Server access logging is enabled          
    [High]      Web Cache Access Logging     Security     Web Cache     Check that Web Cache access logging is enabled          
    [High]      Web Cache Dummy wallet     Security     Web Cache     Check that dummy wallet is not used for production SSL load.          
    [High]      HTTP Server Dummy wallet     Security     HTTP Server     Check that dummy wallet is not used for production SSL load.          
    [High]      Web Cache owner and setuid bit'     Security     Web Cache     Check that webcached binary is not owned by root and setuid is not set          
    [High]      HTTP Server Owner and setuid bit     Security     HTTP Server     Check the httpd binary is not owned by root and setuid bit is not set.          
    [High]      HTTP Server Directory Indexing     Security     HTTP Server     Check that Directory Indexing is disabled on this HTTP Server          
    [High]      Insufficient Redo Log Size     Storage     Database     Checks for redo log files less than 1 Mb          
    [Medium]      Insufficient Number of Redo Logs     Configuration     Database     Checks for use of less than three redo logs          
    [Medium]      Invalid Objects     Objects     Database     Checks for invalid objects          
    [Medium]      Insecure services     Security     Host     Check for insecure services          
    [Medium]      DBSNMP privileges     Security     Database     Check that DBSNMP account has sufficient privileges to conduct all security tests          
    [Medium]      Remote password file     Security     Database     Check for insecure authentication of remote users (remote password file)          
    [Medium]      Default passwords     Security     Database     Test for known accounts having default passwords          
    [Medium]      Unlimited login attempts     Security     Database     Check for limits on the number of failed logging attempts          
    [Medium]      Web Cache Writable files     Security     Web Cache     Check that there are no group or world writable files in the Document Root directory.          
    [Medium]      HTTP Server Writable files     Security     HTTP Server     Check that there are no group or world writable files in the Document Root directory          
    [Medium]      Excessive PUBLIC EXECUTE privileges     Security     Database     Check for PUBLIC having EXECUTE privileges on powerful packages          
    [Medium]      SYSTEM privileges to PUBLIC     Security     Database     Check for SYSTEM privileges granted to PUBLIC          
    [Medium]      Well-known accounts     Security     Database     Test for accessibility of well-known accounts          
    [Medium]      Execute Stack     Security     Host     Check for OS config parameter which enables execution of code on the user stack          
    [Medium]      Use of Unlimited Autoextension     Storage     Database     Checks for tablespaces with at least one datafile whose size is unlimited          
    [Informational]      Force Logging Disabled     Configuration     Database     When Data Guard Broker is being used, checks primary database for disabled force logging          
    [Informational]      Not Using Spfile     Configuration     Database     Checks for spfile not being used          
    [Informational]      Use of Non-Standard Initialization Parameters     Configuration     Database     Checks for use of non-standard initialization parameters          
    [Informational]      Flash Recovery Area Location Not Set     Configuration     Database     Checks for flash recovery area not set          
    [Informational]      Installation of JAccelerator (NCOMP)     Installation     Database     Checks for installation of JAccelerator (NCOMP) that improves Java Virtual Machine performance by running natively compiled (NCOMP) classes          
    [Informational]      Listener logging status     Security     Listener     Test for logging status of listener instances          
    [Informational]      Non-uniform Default Extent Size     Storage     Database     Checks for tablespaces with non-uniform default extent size          
    [Informational]      Not Using Undo Space Management     Storage     Database     Checks for undo space management not being used          
    [Informational]      Users with Permanent Tablespace as Temporary Tablespace     Storage     Database     Checks for users using a permanent tablespace as the temporary tablespace          
    [Informational]      Rollback in SYSTEM Tablespace     Storage     Database     Checks for rollback segments in SYSTEM tablespace          
    [Informational]      Non-System Data Segments in System Tablespaces     Storage     Database     Checks for data segments owned by non-system users located in tablespaces SYSTEM and SYSAUX          
    [Informational]      Users with System Tablespace as Default Tablespace     Storage     Database     Checks for non-system users using SYSTEM or SYSAUX as the default tablespace          
    [Informational]      Dictionary Managed Tablespaces     Storage     Database     Checks for dictionary managed tablespaces (other than SYSTEM and SYSAUX)          
    [Informational]      Tablespaces Containing Rollback and Data Segments     Storage     Database     Checks for tablespaces containing both rollback (other than SYSTEM) and data segments          
    [Informational]      Segments with Extent Growth Policy Violation     Storage     Database     Checks for segments in dictionary managed tablespaces (other than SYSTEM and SYSAUX) having irregular extent sizes and/or non-zero Percent Increase settings

    Interresting is revoking UTL_FILE from public, which is critical. Also revoke UTL_TCP and UTL_SMTP. This is going to upset an expert I know...Okay, as this is (I think) aimed at me, I'll fall for it ;)
    What is the point of revoking UTL_FILE from PUBLIC? Yes I know what you think the point is, but without rights on an Oracle DIRECTORY being able to execute UTL_FILE is useless. Unless of course you're still using the init.ora parameter
    UTL_FILE_DIR=*which I sincerely hope you're not.
    As for UTL_SMTP and UTL_TCP, I think whether a program is allowed to send e-mail to a given SMTP server is really in the remit of the e-mail adminstrator rather than the DBA.
    Look, DBAs are kings of their realm and can set their own rules. The rest of us have to live with them. A couple of years ago I worked a project where I was not allowed access to the USER_DUMP_DEST directory. So every time I generated a TRC file I had to phone up the DBA and a couple of hours later I got an e-mail with an attachment. Secure yes, but not very productive when I was trying to debug a Row Level Security implementation.
    I have worked on both sides of the DBA/Developer fence and I understand both sides of the argument. I think it is important for developers to document all the privileges necessary to make their app run. Maybe you don't have a better way of doing that than revoking privileges from PUBLIC. Or maybe you just want to generate additional communication with developers. That's fine. I know sometimes even DBAs get lonely.
    Cheers, APC

  • Writing large xmltype data to UTL_FILE and setting max row per file

    Hey Gurus,
    I am trying to create a procedure (in Oracle 9i) that writes out xml data I have created into several xml files (file would probably be to large for one xml file output...I am doing this for 270,000 rows of data), setting the max rows to 1000 rows per file. I know one would have to create a looping contsruct to do this but I am just not adept enough in PL/SQL to figure it out at the moment.
    So essentially their would be some sort of loop construct and substr process that creates a file after looping through 1000 rows and then continues the count and creates a another file until all 270 xml files are created. Simple enough right...lol? Well I've tried doing this and haven't gotten anywhere. My pl/sql coding skills are too elementary I am guessing. I've only been doing this for about three months and could use the assistance of a more experienced person here.
    Here are the particulars...
    This is the xmltype view code that I used to create the xml data.
    select XMLELEMENT("macess_exp_import_export_file",
    XMLELEMENT("file_header",
    XMLELEMENT("file_information")),
    XMLELEMENT("items",
    XMLELEMENT("documents",
    (SELECT XMLAGG(XMLELEMENT("document",
    XMLELEMENT("external_reference"),
    XMLELEMENT("processing_instructions",
    XMLELEMENT("update", name)),
    XMLELEMENT("filing_instructions",
    XMLELEMENT("folder_ids",
    XMLELEMENT("folder",
    XMLATTRIBUTES(folder_id AS "id", folder_type_id AS "folder_type_id")))),
    XMLELEMENT("document_header",
    XMLELEMENT("document_type",
    XMLATTRIBUTES(document_type AS "id")),
    XMLELEMENT("document_id", document_id),
    XMLELEMENT("document_description", document_description),
    XMLELEMENT("document_date",
    XMLATTRIBUTES(name AS "name"), document_date),
    XMLELEMENT("document_properties")),
    XMLELEMENT("document_data",
    XMLELEMENT("internal_file",
    XMLELEMENT("document_file_path", document_file_path),
    XMLELEMENT("document_extension", document_extension)
    ))))from macess_import_base WHERE rownum < 270000))))AS result
    from macess_import_base WHERE rownum < 270000;
    This is the Macess_Import_Base table that I am creating xml data from
    create table MACESS_IMPORT_BASE
    MACESS_EXP_IMPORT_EXPORT_FILE VARCHAR2(100),
    FILE_HEADER VARCHAR2(20),
    ITEMS VARCHAR2(20),
    DOCUMENTS VARCHAR2(20),
    DOCUMENT VARCHAR2(20),
    EXTERNAL_REFERENCE VARCHAR2(20),
    PROCESSING_INSTRUCTIONS VARCHAR2(20),
    PATENT VARCHAR2(20),
    FILING_INSTRUCTIONS VARCHAR2(20),
    FOLDER_IDS VARCHAR2(20),
    FOLDER_ID VARCHAR2(20),
    FOLDER_TYPE_ID NUMBER(20),
    DOCUMENT_HEADER VARCHAR2(20),
    DOCUMENT_PROPERTIES VARCHAR2(20),
    DOCUMENT_DATA VARCHAR2(20),
    INTERNAL_FILE VARCHAR2(20),
    NAME VARCHAR2(20),
    DOCUMENT_TYPE VARCHAR2(40),
    DOCUMENT_ID VARCHAR2(64),
    DOCUMENT_DESCRIPTION VARCHAR2(200),
    DOCUMENT_DATE VARCHAR2(100),
    DOCUMENT_FILE_PATH VARCHAR2(200),
    DOCUMENT_EXTENSION VARCHAR2(200)
    Directory name to write output to "DIR_PATH"
    DIRECTORY PATH is "\app\cdg\cov"
    Regards,
    Chris

    I also would like to use UTL_FILE to achieve this functionality in the procedure.

  • UTL_FILE, Extra CRFL's, possible OS interpretation problem.

    Greetings,
    DISCLAIMER:
    I am an oracle noob so if I make a mistake in forum etiquette or have not checked all available documentation or have made an assumption that is incorrect ( or noobish ) or am unaware of a tool better suited to the task I am trying to accomplish..
    Please don’t flame me, I am learning. Give me constructive replies and I will learn, I promise.
    My environment: 10G XE DB running on Server 2k3. Developing in SQLDEV 1.54
    I am attempting to dump the contents of a CLOB to a file on the OS disc. Due to formatting restrictions, the contents of the file written to disc must be EXACTLY the contents of the CLOB, character per-per character, verbatim.
    Here is an example anon block that will give you the essentials of the way I am attempting to accomplish this:
    DECLARE
    l_clob CLOB ;
    l_output_file utl_file.file_type;
    BEGIN
    l_clob := 'Hello my name is George!' || chr(13) || chr(10) ;
    l_clob:= l_clob || 'Would you like to play a game?' || chr(13) || chr(10);
    l_clob := l_clob || 'It will be fun, I promise..' || chr(13) || chr(10);
    dbms_output.put_line( dbms_lob.getlength(l_clob));
    l_output_file := utl_file.fopen( TEST_DIR' , 'test.txt' ,'W', max_linesize=> 32767 );
    utl_file.put( l_output_file , l_clob );
    utl_file.fflush( l_output_file);
    utl_file.fclose( l_output_file );
    utl_file.fclose_all;
    END;
    Here you can see where I put a few lines into my clob, I manually append the CRLF using the CHR function, since I cant accurately reproduce a non-printable character in a string value. This is important because the Clob I am attempting to write to disc contains CRLF’s as part of its data, these must be preserved. Also note that I am writing this to the file using utl_file.PUT not PUT_LINE, again, because the disk file must be the clob verbatim, I cant use put_line because it adds a “new line character” at the end of the data it writes.
    Ignore the DMBS_OUTPUT line , I will get back to that in a bit.
    I execute this bit of code and get a file text.txt. What I expected to see was:
    “'Hello my name is George!
    Would you like to play a game?
    'It will be fun, I promise..”
    What I actually got was:
    !http://i594.photobucket.com/albums/tt22/GargleSpam/Temp001.jpg!
    Looking at this in notepad++ we can expose the non-printable chars:
    !http://i594.photobucket.com/albums/tt22/GargleSpam/Temp002.jpg!
    Using notepad ++ we can see that an extra CR ( CHR(13)) has been pre-pended to the CRLF. We can confirm this is not an artifact of viewing this in notepad by looking at the file size of the output file and comparing it to the size of the clob.
    The DBMS_OUTPUT line indicates ( in my test case) clob size of 87 characters. If you take the time to count you will see this is correct. 81 printable characters that we see, and the 6 non-printable chars to accomplish the CRLF’s.
    However if we look at the file size:
    !http://i594.photobucket.com/albums/tt22/GargleSpam/Temp003.jpg!
    So that’s 87 + our 3 “ninja ” CR’s.
    For my purposes this is a deal-breaking problem. The contents of my output file must be exactly the contents of my clob, byte for byte. So this extra CR is a big big problem.
    Where is it coming from? I started thinking about the “new line character” that the PUT_LINE procedure uses and, had a hunch that perhaps since the DB is OS independent, it might be passing one of the non-printable chars to the OS as “new line” and letting the os worry about what that means on disk. With that in mind I did some further testing:
    DECLARE
    l_clob CLOB ;
    l_output_file utl_file.file_type;
    BEGIN
    l_clob := 'Incoming lf->'|| chr(10) ;
    l_clob:= l_clob || 'Incoming cr->' || chr(13);
    clob:= lclob || 'Incoming CRLF->' || chr(13) || chr(10);
    l_output_file := utl_file.fopen( TEST_DIR' , 'test.txt' ,'W', max_linesize=> 32767 );
    utl_file.put( l_output_file , l_clob );
    utl_file.fflush( l_output_file);
    utl_file.fclose( l_output_file );
    utl_file.fclose_all;
    END;
    This code results in:
    !http://i594.photobucket.com/albums/tt22/GargleSpam/Temp004.jpg!
    Looking at this it becomes obvious that the CHR(10) is being written to disc as TWO characters ( CR LF). So my assumption must be correct, that the DB is passing CHR(10) to the OS as “newline” and the OS ( Windows in my case ) is interpreting this as ‘CRLF.’
    This makes sense since it seems to be widely known ( though not to me , I am shaky on this part ) that “newline” in unix is just CHR(10), and in windows its CHR(10)||CHR(13).
    So I seem to have isolated my problem. Now finally my question.. How to I get around this?
    Google searches and searches on this forum yeilded only marginal help, something about passing this file through an FTP server.. ?. The only marginal help was in post # 3298335. Nothing that really answers my question though.
    Is there a setting my DBA can set to change this behavior? Is there a different way ( PLSQL) to write the file that might mitigate this? Don’t say put the DB on unix, that’s not an option.
    Let me know what you think…
    -VAF

    Hi,
    Also you should check that the directory name is enclosed between '. TEST_DIR is an Oracle directory object that maps a real directory path in the filesystem (check privileges).
    Like:
    DECLARE
        l_clob CLOB;
        l_output_file utl_file.file_type;
    BEGIN
        l_clob := 'Hello my name is George!' || CHR(13) || CHR(10);
        l_clob := l_clob || 'Would you like to play a game?' || CHR(13) || CHR(10);
        l_clob := l_clob || 'It will be fun, I promise..' || CHR(13) || CHR(10);
        dbms_output.put_line(dbms_lob.getlength(l_clob));
        l_output_file := utl_file.fopen('TEST_DIR', 'test.txt', ' W', max_linesize => 32767);
        utl_file.put(l_output_file, l_clob);
        utl_file.fflush(l_output_file);
        utl_file.fclose(l_output_file);
    END;Tip: to post formatted code you must enclose it between {noformat}{noformat} tags (start and end tags are the same).
    Regards,                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                               

Maybe you are looking for

  • Database connection not closed in Destroy()  method of servlet

    Hi, I have a problem with my deployed web application. At first, I thought Glassfish was messing up on me, and after checking the log I could see plenty of null pointer exceptions being thrown at lines in my code where I generate prepared statements

  • Linking Multiple regions in a single page

    Hi All, I am a new user to Apex, and i need some help for my current requirement. i will appreciate any help from the members i have a Master table and 5 child tables. i have created an interactive report in region1 for the master and 5 simple report

  • Backspace key: Can it have a shortcut?

    Since making changes to my Custom Set of Keyboard Shortcut commands I seem to have lost the backspace key's function of deleting frames, though the key still deletes in type mode and works like it should in, say, Illustrator. I can't recall how I mig

  • Intermittent Time Machine Error -1

    I have a late 2008 MacBook Pro 2.8 GHz with 4 GB of RAM running Mac OS X 10.7.3. I have Time Machine backups performed through a Mac Mini running Mac OS X 10.7.3 Lion Server (clean install) to an external drive attached to the mini via Firewire 800.

  • Problems during NWDS startup

    I have installed Netweaver developer studio. When i tried to launch it , it gave me an error "Problem during start up". The log file show the following !SESSION Oct 22, 2004 18:26:15.579 - java.version=1.4.2_04 java.vendor=Sun Microsystems Inc. BootL