Extract XML output to file using PL/SQL

Hi.
Since Oracle 8.1.4.7.1 I am using XML output in my applications.
With that version of Oracle, my method was:
1. Make the select;
2. Create a file somewhere in my C drive;
3. Create the XML file header;
3. For each row, insert into the file, with the correct format;
4. Close the file;
... and, voilá ... the XML file was made.
Now, with the Oracle 10g, I know that I have much more ways to do it:
1. Package DBMS_XMLQUERY
2. Statements like
"SELECT XMLELEMENT("USERS", XMLELEMENT("nome_pessoa", e.nome_pessoa ||' - '|| e.login), XMLELEMENT ( "password", e.password)) AS "result"
FROM pessoa e"
3. Or finally using XML SQL Utility.
My question, is that if there is any way that i can make it all of this automatically. If there is any procedure or method that allow me to do all this stuff in just one step:
1. Select in XML output;
2. Creation of file;
3. Insertion of Select output in file and Close of File;
Thankx,

I'm assuming that you want to write to the file system of the server that the database is running on...
you'll have to use utl_file
See
http://otn.oracle.com/docs/products/oracle9i/doc_library/release2/appdev.920/a96612/u_file.htm

Similar Messages

  • Read XML File Using PL/SQL

    Hi,
    I have to read a XML file using PL/SQL. I am new to this so please explain in easy steps.
    Regards,
    SF

    STEP - 2
    SQL>
    SQL> DECLARE
      2    l_ctx dbms_xmlsave.ctxType ;
      3    l_xml CLOB :=
      4  '<?xml version="1.0" encoding="UTF-8" ?>
      5  <NewDataSet>
      6      <ROW>
      7          <DEPARTMENT>BA52</DEPARTMENT>
      8          <PCS_CONTRACT_TAG>MD-3GSM</PCS_CONTRACT_TAG>
      9          <LOCATION>Australia</LOCATION>
    10          <MAY_2006>21668</MAY_2006>
    11      </ROW>
    12      <ROW>
    13          <DEPARTMENT>BA501</DEPARTMENT>
    14          <PCS_CONTRACT_TAG>MD-3GSM</PCS_CONTRACT_TAG>
    15          <LOCATION>China</LOCATION>
    16          <MAY_2006>8166</MAY_2006>
    17      </ROW>
    18      <ROW>
    19          <DEPARTMENT>BA522</DEPARTMENT>
    20          <PCS_CONTRACT_TAG>MD-3GSM</PCS_CONTRACT_TAG>
    21          <LOCATION>Australia</LOCATION>
    22          <MAY_2006>21668</MAY_2006>
    23      </ROW>
    24  </NewDataSet>' ;
    25  BEGIN
    26      l_ctx := dbms_xmlsave.newContext(targetTable => 'XML_INSERT');
    27      dbms_output.put_line(dbms_xmlsave.insertXML(ctxHdl => l_ctx,
    28                                                  xDoc   => l_xml) ||
    29                           ' rows inserted.');
    30      dbms_xmlsave.closeContext(l_ctx);
    31  END;
    32  /
    3 rows inserted.
    PL/SQL procedure successfully completed.Regards.
    Satyaki De.

  • How can I create an csv/excel file using pl/sql and then sending that file

    How can I create an csv/excel file using pl/sql and then sending that file to a clients site using pl/sql?
    I know how to create the csv/excel file but I can't figure out how I would get it to the clients site.

    968776 wrote:
    How can I create an csv/excel file using pl/sql and then sending that file to a clients site using pl/sql?
    I know how to create the csv/excel file but I can't figure out how I would get it to the clients site.You are trying to do it at a wrong place..
    Whay do you want database (pl/sql) code to do these things?
    Anyhow, you may be interested in :
    {message:id=9360007}
    {message:id=9984244}

  • Loading the data from a packed decimal format file using a sql*loader.

    Hi ,
    In one of the project i'm working here i have to load the data into oracle table from a file using a Sql*loader but the problem is the data file is in the packed decimal format so please let me know if there is any way to do this....I search a lot regarding this ..If anybody faced such type of problem ,then let me the steps to solve this.
    Thanks in advance ,
    Narasingarao.

    declare
    f utl_file.file_type;
    s1 varchar2(200);
    s2 varchar2(200);
    s3 varchar2(200);
    c number := 0;
    begin
    f := utl_file.fopen('TRY','sample1.txt','R');
    utl_file.get_line(f,s1);
    utl_file.get_line(f,s2);
    utl_file.get_line(f,s3);
    insert into sampletable (a,b,c) values (s1,s2,s3);
    c := c + 1;
    utl_file.fclose(f);
    exception
    when NO_DATA_FOUND then
    if utl_file.is_open(f) then utl_file.fclose(f); ens if;
    dbms_output.put_line('No. of rows inserted : ' || c);
    end;SY.

  • Writing into Excel file using PL/SQL and formatting the excel file

    Hi,
    I am writing into a excel file using PL/SQL and I want to make the first line bold on the excel. Also let me know if there are any other formatting options when writing into excel.
    Regards,
    -Anand

    I am writing into a excel file using PL/SQL
    Re: CSV into Oracle and Oracle into CSV
    check that thread or search in this forum...

  • Display data in log file using PL/SQL procedure

    Just as srw.message is used in Oracle RDF Reports to display data in log file in Oracle Apps, similarly how it is possible to display data in log file using PL/SQL procedure?
    Please also mention the syntax too.

    Pl post details of OS, database and EBS versions.
    You will need to invoke the seeded FND_LOG procedure - see previous discussions on this topic
    Enable debug for pl/sql
    https://forums.oracle.com/forums/search.jspa?threadID=&q=FND_LOG&objID=c3&dateRange=all&userID=&numResults=15&rankBy=10001
    HTH
    Srini

  • Downloading BLOB to a file using pl/sql toolkit

    Created an Oracle Reports RDF file using the reports builder (9.0.2.x).
    Uploaded the file into the database in a BLOB column using the following code:
    >>>>
    SET VERIFY OFF
    DECLARE
    p_bfile BFILE ;
    p_blob BLOB ;
    BEGIN
    p_bfile := BFILENAME('CDR_REPORTS', '&1') ;
    INSERT INTO RPTIDE (RPTID, RPTMODULE) VALUES ('&1', EMPTY_BLOB()) RETURNING
    RPTMODULE INTO p_blob ;
    DBMS_LOB.FILEOPEN(p_bfile, DBMS_LOB.FILE_READONLY);
    DBMS_LOB.LOADFROMFILE(p_blob, p_bfile, DBMS_LOB.GETLENGTH(p_bfile));
    DBMS_LOB.FILECLOSE(p_bfile);
    COMMIT ;
    END ;
    <<<<<
    Now when we try to download the same file using pl/sql web toolkit (code pasted
    below), the file downloads fine (with exact same file size as before), but no
    longer can open the file in Reports Builder anymore. Get "Cannot open file"
    error in reports builder. Is it getting corrupt or am I doing something wrong?
    >>>>
    CREATE OR REPLACE PROCEDURE filedownload(p_rpt IN VARCHAR2) AS
    p_file blob;
    p_mime_type varchar2(50);
    p_offset integer := 1;
    p_len number;
    p_buf RAW(32000);
    p_buf_size integer:= 32000;
    BEGIN
    SELECT rptmodule, 'application/x-zip'
    INTO p_file, p_mime_type
    FROM rptide
    WHERE rptid = p_rpt ;
    OWA_UTIL.MIME_HEADER(p_mime_type);
    p_len := DBMS_LOB.GETLENGTH(p_file);
    WHILE p_offset < p_len LOOP
    DBMS_LOB.READ(p_file, p_buf_size, p_offset, p_buf);
    HTP.PRN(UTL_RAW.CAST_TO_VARCHAR2(p_buf));
    p_offset := p_offset + p_buf_size;
    END LOOP;
    EXCEPTION
    WHEN NO_DATA_FOUND THEN HTP.PRN('No document specified') ;
    WHEN OTHERS THEN HTP.P('filedownload: '||SQLERRM);
    END filedownload ;
    <<<<<

    The answer to this problem was to set the NLS_LANGUAGE for the DAD to an 8-bit character set since the database charset was 8-bit. It seems, by default, the web toolkit assumes a 7-bit character set.

  • Creating Files Using PL/SQL?

    Hi,
    Is there a way to create a file using PL/Sql? It seems that the
    utl_file package doesn't allow you to create a file. It only
    allows you to read, write to a file that already exists there.
    Thanks
    Vic

    Make sure the following is set in the init.ora:
    UTL_FILE_DIR = /path/to/your/file/directory (for unix)
    or
    UTL_FILE_DIR = <drive>:\path\to\your\file\directory (for windows)

  • Generating text file using PL/SQL

    can any body send sample program how to generate text file using PL/SQL program.I want to store table data into that text file.

    Hi,
    try this.
    Thanks
    CREATE OR REPLACE procedure write_index (TABLE_NAME_ACCEPT VARCHAR2) IS
    id UTL_FILE.FILE_TYPE;
    name VARCHAR2(20) := 'e:\db_coca\input';      
    err VARCHAR2(100);      
    ColNameLength Integer;
    NumberoFColumns Integer;
    num NUMBER;           
    i integer;
    loc_query VARCHAR2(2000);
    cursor_name INTEGER;
    ret INTEGER;
    l_const_name VARCHAR2(30);
    CURSOR c_columns(i_Constraint_name VARCHAR2) IS
         SELECT *
         FROM     all_cons_columns
         WHERE     CONSTRAINT_NAME = i_Constraint_name
         order by table_name;
    BEGIN
    DBMS_OUTPUT.PUT_LINE('BEFORe OPEN');
    --id := UTL_FILE.FOPEN('e:\db_coca\input',name,'w');          
         --IF UTL_FILE.IS_OPEN(id) THEN
         --     DBMS_OUTPUT.PUT_LINE('Opened');
         --ELSE
         --     DBMS_OUTPUT.PUT_LINE('Still Closed');           
         --END IF;          
    DBMS_OUTPUT.PUT_LINE('AFTER OPEN');
    --The table generation script
         loc_query := 'Select CONSTRAINT_NAME from user_constraints ';
         loc_query := loc_query || ' where owner = ' || '''CPS''';
         loc_query := loc_query || ' AND CONSTRAINT_TYPE = ' || '''P''';
         dbms_output.put_line('TABLE_NAME_ACCEPT = ' || TABLE_NAME_ACCEPT);
         IF NOT (TABLE_NAME_ACCEPT IS NULL ) THEN
              loc_query := loc_query || ' AND TABLE_NAME like ''';
              loc_query := loc_query || TABLE_NAME_ACCEPT ;
              loc_query := loc_query || '''';
         END IF;
         cursor_name := DBMS_SQL.OPEN_CURSOR;
    dbms_output.put_line('Query = ' || loc_query);
         DBMS_SQL.PARSE(cursor_name, loc_query, DBMS_SQL.v7);
    dbms_output.put_line('After parse');
         dbms_sql.DEFINE_COLUMN(cursor_name, 1,l_const_name, 30);
         ret := DBMS_SQL.EXECUTE(cursor_name);
    --     IF ret > 0 THEN
         LOOP
         dbms_output.put_line('return = ' || ret);
              IF DBMS_SQL.FETCH_ROWS(cursor_name) > 0 THEN
                   dbms_sql.COLUMN_VALUE(cursor_name, 1,l_const_name);
              --     dbms_sql.BIND_VARIABLE(cursor_name,
    l_const_name,CONSTRAINT_NAME);
              --     FOR C10 in Table_Loop Loop          --The cursor
    for the table name
                   Select COunt(*) INTO NumberoFColumns from
                   all_cons_columns
                   Where CONSTRAINT_NAME = l_const_name;
         --          FOR C11 IN c_columns(l_const_name) LOOP
         --          End loop;
         --          UTL_FILE.PUT(id, ');');
              ELSE EXIT;
              END if;     --THe 1 st cursor if is closed
         End Loop;     --The table loop ends here
              DBMS_SQL.CLOSE_CURSOR(cursor_name);
    --     END IF;     
    --     UTL_FILE.PUT_LINE(id,name);
    --     UTL_FILE.PUT(id,'It worked and wrote to this file');
         UTL_FILE.FCLOSE(id);
         DBMS_OUTPUT.PUT_LINE('Successful write to file');          
    EXCEPTION     
    WHEN OTHERS THEN               
         err := SQLERRM;          
         num := SQLCODE;
         DBMS_OUTPUT.PUT_LINE(err);          
         DBMS_OUTPUT.PUT_LINE(num);
         DBMS_OUTPUT.PUT_LINE('Error in writing to file');     
    END write_index;

  • Creating a text file using pl/sql

    how can one create a text file using pl/sql?
    Say for example abcd.txt in the d: drive
    (d:\abcd.txt)
    on a windows nt server

    <BLOCKQUOTE><font size="1" face="Verdana, Arial">quote:</font><HR>Originally posted by bhrigu nagal ([email protected]):
    thanks for your replies
    I had already set the utl_file_dir parameter
    I tried the utl package and wrote the following code but got some errors
    declare
    filehandler UTL_FILE.FILE_TYPE;
    begin
    filehandler:=UTL_FILE.fopen('d:/intel/','myfile.txt','w');
    utl_file.put_line(filehandler,'look masjdfgsd\n');
    utl_file.fclose(filehandler);
    exception when utl_file.invalid_path then
    raise_application_error(-20023,'bhrigu ,chk the path');
    end;
    the errors
    ERROR at line 1:
    ORA-06510: PL/SQL: unhandled user-defined exception
    ORA-06512: at "SYS.UTL_FILE", line 101
    ORA-06512: at "SYS.UTL_FILE", line 157
    ORA-06512: at line 4
    if u know what this is please tell me
    thanks bhrigu
    <HR></BLOCKQUOTE>
    U need :
    1) To have UTL_FILE_DIR param in the init file of the instance with the same directory (don't forget to stop and restart the base)
    2) Handled the exceptions listed in the utl_file package (Oracle_home\rdbms\admin\utlfile.sql) in your source.
    3) Turn set serveroutput on in SQL*Plus.
    Run your procedure and see the error message to debug.
    Good luck
    null

  • How to send the output of a script to a txt or rpt file using T-sql?

    Hi!
    I have some code which we use to record info about a database when we decommission it. I normally click Query > Results to File and then run it to produce a file.  I need to do this via t-sql so I can automate it. Any idea what code I need to make
    this script output to file?
    Thanks,
    Zoe
    SET NOCOUNT ON
    DECLARE @Databasename varchar(50)
    DECLARE @date as char(10)
    DECLARE @session_usr nchar(30);
    SET @Databasename = db_name()
    SET @date = convert(char(10), getdate(), 121)
    SET @session_usr = SYSTEM_USER;
    DECLARE @sqlCommand varchar(1000)
    select current_user
    Print '================================================================================'
    Print '========== SQL Decommission Report for '+ @@SERVERNAME +' ========='
    Print '========== Executed on ' + @date +' by '+ rtrim(@session_usr) +' ========='
    Print '================================================================================'
    Print ' '
    Print 'Database properties'
    Print '----------------------------------'
    select substring(name,1,25) as Name,substring(filename,1,40) as File_Name,cmptlevel as Compatibility_level from master.dbo.sysdatabases
    where name = @databasename
    Print 'Full Text Catalogs'
    Print '----------------------------------'
    select substring(name,1,20)as Name,status,substring(path,1,52) as Path FROM [master].[dbo].[sysfulltextcatalogs]
    Print 'SSIS Packages'
    Print '----------------------------------'
    IF (select cast(@@version as varchar)) like '%2012%' begin
    print 'sql 2012 instance'
    select substring(name,1,20) as Name,substring(description,1,40) as Description,ownersid as Owner from msdb.dbo.sysssispackages
    end else if (select cast(@@version as varchar)) like '%2008%' begin
    print 'sql 2008 instance'
    select substring(name,1,20) as Name,substring(description,1,40) as Description,ownersid as Owner from msdb.dbo.sysssispackages
    select substring(name,1,20) as Name,substring(description,1,40) as Description,substring(owner,1, 18) as Owner from msdb.dbo.sysdtspackages
    end else if (select cast(@@version as varchar)) like '%2005%' begin
    print 'sql 2005 instance'
    select substring(name,1,20) as Name,substring(description,1,40) as Description,suser_sname(ownersid) as Owner from msdb.dbo.sysdtspackages90
    select substring(name,1,20) as Name,substring(description,1,40) as Description,substring(owner,1, 18) as Owner from msdb.dbo.sysdtspackages
    end
    Print 'Linked Servers'
    Print '----------------------------------'
    SELECT substring(srvname,1,35) as LinkedServer_Name,substring(datasource,1,35) as Data_Source FROM master.dbo.sysservers WHERE isremote = 0
    Print 'Replication'
    Print '----------------------------------'
    IF (select count(*) from master.dbo.sysdatabases where name = 'Distribution') > 0
    select substring(publisher_db,1,20) as Published_DB,substring(Description,1,40) as Description from distribution.dbo.MSpublications
    ELSE print 'No replication'
    Print ' '
    Print 'Database Mail'
    Print '----------------------------------'
    SELECT substring(name,1,20) as Name,enabled,substring(email_address,1,35) as Email_address,last_email_date FROM msdb.dbo.sysoperators
    where last_email_date > dateadd(day,-30,getdate())-- detect whether any of the systems have sent an email in the last 30 days
    Print 'CLR Assemblies'
    Print '----------------------------------'
    select substring(Name,1,20) as Name,substring(Type_desc,1,35) as Description,Create_date from sys.objects where object_id in (select object_id from sys.assembly_modules)
    Print 'Logins'
    Print '----------------------------------'
    SET @sqlCommand = 'select substring(name,1,40) as Name,substring(dbname,1,30) as Default_Database from master.dbo.syslogins where sid in (select sid from '+ @databasename +'.dbo.sysusers where issqlrole <> 1 and hasdbaccess <> 0 and name <> ''dbo'')'
    EXEC (@sqlCommand)

    You can use bcp to export from database to flat file.
    It requires xp_cmdshell to work from a stored procedure.
    Kalman Toth Database & OLAP Architect
    SQL Server 2014 Design & Programming
    New Book / Kindle: Exam 70-461 Bootcamp: Querying Microsoft SQL Server 2012

  • Import xml file using pl/sql

    Hi,
    i have an oracle 8i database.
    in a few weeks i will be receiving a number of xml files on a daily basis.
    i want to import these files into my oracle database using pl/sql. However, although i know i can do this, i have been unable to find any sample code for this type of operation.
    Can someone please help.
    Thanks
    Joe

    Hi Joe,
    I have a ready solution for this problem.
    Let suppose You have an XML doc in canonical form:
    <?xml version = '1.0'?>
    <ROWSET>
    <ROW num="1">
    <DEPARTMENT_ID>99</DEPARTMENT_ID>
    <DEPARTMENT_NAME>OKATAS</DEPARTMENT_NAME>
    <MANAGER_ID>100</MANAGER_ID>
    <LOCATION_ID>1700</LOCATION_ID>
    </ROW>
    <ROW num="2">
    <DEPARTMENT_ID>77</DEPARTMENT_ID>
    <DEPARTMENT_NAME>PERSONNEL</DEPARTMENT_NAME>
    <LOCATION_ID>1800</LOCATION_ID>
    </ROW>
    </ROWSET>
    These tag names are mandatory (ROW and ROWSET).
    1. First create an Oracle directory, for example in UNIX:
    CREATE DIRECTORY TANF_DIR AS '/home1/teach1/DEMO';
    2. Create a procedure which reads the XML file (such as DEPT.XML)
    CREATE OR REPLACE PROCEDURE XML_TO_SQL
    (dir_name VARCHAR2,file_name VARCHAR2,TNAME VARCHAR2)
    AUTHID CURRENT_USER IS
    FH UTL_FILE.FILE_TYPE;
    C CLOB;
    PUF VARCHAR2(1000);
    READ_COUNT NUMBER:=0; ERROR_COUNT NUMBER:=0;
    procedure INSERTProc(xmlDoc IN CLOB, tableName IN VARCHAR2)
    IS
    insCtx DBMS_XMLSave.ctxType;
    rows number;
    begin
    insCtx := DBMS_XMLSave.newContext(tableName); -- get the context handle
    rows := DBMS_XMLSave.insertXML(insCtx,xmlDoc); -- this inserts the document
    DBMS_XMLSave.closeContext(insCtx);
    You can save the XML document as data of XMLtype,which was introduced in Oracle 9i
    INSERT INTO xml_table(key,xml_doc)
    VALUES(xml_seq.NEXTVAL,sys.xmltype.createxml(xmldoc));
    */ -- this closes the handle
    END INSERTPROC;
    BEGIN
    DBMS_OUTPUT.ENABLE(1000000);
    FH:=UTL_FILE.FOPEN(DIR_NAME,FILE_NAME,'R');
    LOOP
    UTL_FILE.GET_LINE(FH,puf);
    READ_COUNT:=READ_COUNT+1;
    c:=c||puf;
    -- DBMS_OUTPUT.PUT_LINE(PUF);
    END LOOP;
    EXCEPTION
    WHEN NO_DATA_FOUND THEN
    DBMS_OUTPUT.PUT_LINE('FINISH '||READ_COUNT||' ROWS. ERRORS: ' ||ERROR_COUNT);
    UTL_FILE.FCLOSE(FH);
    INSERTProc(C,TNAME);
    COMMIT;
    END XML_TO_SQL;
    3. Create table NEWDEPT .. containing the column names which are in the XML ROW tag(DEPARTMENT_ID, ...)
    4. Execute the procedure:
    exec xml_to_sql('TANF_DIR','DEPT.XML','NEWDEPT')

  • Generating Excel file using PL/SQL

    Hi,
    I wanted to generate the excel file using the below pasted PL/SQL which I have downloaded from one of the tech sites. And as I have very limited knowledge about PL/SQL I really dont know how & where I should compile this below mentioned code and get the desired O/P?
    Please reply me ASAP if anybody can help me with this?
    Please see the below code and please help me to interpret the same.
    CREATE OR REPLACE PACKAGE gen_xl_xml IS
    -- Version 0.5
    -- Objective : The main objective OF this PACKAGE IS TO CREATE excel files from PL/SQL code
    -- Requirement : Excel version 2003 onwards support XML format.
    -- The procedures does have TO be called IN specific order at this moment.
    -- expected SEQUENCE AS OF now IS
    -- At first call create_file -> It creates a FILE WITH NAME that you pass AS parameter. This PROCEDURE writes the
    -- excel file header AND some basic requirments like default style.
    -- procedures 1. create_style , create_worksheet AND write_cell can be used IN ANY SEQUENCE AS many
    -- times AS you need.
    -- When done WITH writing TO FILE call the PROCEDURE close_file
    -- CLOSE FILE --> This will actually flush the data INTO the worksheet(s) one BY one and then close the file.
    -- What colors I can use ?
    -- red , blue , green, gray , YELLOW, BROWN , PINK . lightgray ,
    debug_flag BOOLEAN := TRUE ;
    PROCEDURE create_excel( p_directory IN VARCHAR2 DEFAULT NULL , p_file_name IN VARCHAR2 DEFAULT NULL ) ;
    PROCEDURE create_excel_apps ;
    PROCEDURE create_style( p_style_name IN VARCHAR2
    , p_fontname IN VARCHAR2 DEFAULT NULL
    , p_fontcolor IN VARCHAR2 DEFAULT 'Black'
    , p_fontsize IN NUMBER DEFAULT null
    , p_bold IN BOOLEAN DEFAULT FALSE
    , p_italic IN BOOLEAN DEFAULT FALSE
    , p_underline IN VARCHAR2 DEFAULT NULL
    , p_backcolor IN VARCHAR2 DEFAULT NULL );
    PROCEDURE close_file ;
    PROCEDURE create_worksheet( p_worksheet_name IN VARCHAR2 ) ;
    PROCEDURE write_cell_num(p_row NUMBER , p_column NUMBER, p_worksheet_name IN VARCHAR2, p_value IN NUMBER , p_style IN VARCHAR2 DEFAULT NULL );
    PROCEDURE write_cell_char(p_row NUMBER, p_column NUMBER, p_worksheet_name IN VARCHAR2, p_value IN VARCHAR2, p_style IN VARCHAR2 DEFAULT NULL );
    PROCEDURE write_cell_null(p_row NUMBER , p_column NUMBER , p_worksheet_name IN VARCHAR2, p_style IN VARCHAR2 );
    PROCEDURE set_row_height( p_row IN NUMBER , p_height IN NUMBER, p_worksheet IN VARCHAR2 ) ;
    PROCEDURE set_column_width( p_column IN NUMBER , p_width IN NUMBER , p_worksheet IN VARCHAR2 ) ;
    END ;
    -- Package : gen_xl_sml
    -- Version : 0.62
    CREATE OR REPLACE PACKAGE Body gen_xl_xml IS
    -- worksheets must be created before it could be passed AS parameter TO the write cell procedures
    l_file utl_FILE.file_type ;
    g_apps_env VARCHAR2(1) := 'U' ; -- unset at the start
    TYPE tbl_excel_data IS TABLE OF VARCHAR2(2000) INDEX BY BINARY_INTEGER ;
    g_excel_data tbl_excel_data ;
    g_null_data tbl_excel_data ;
    g_data_count NUMBER ;
    TYPE rec_styles IS record ( s VARCHAR2(30) , def VARCHAR2(2000) );
    TYPE tbl_style IS TABLE OF rec_styles INDEX BY BINARY_INTEGER ;
    g_styles tbl_style ;
    g_null_styles tbl_style ;
    g_style_count NUMBER := 0;
    TYPE rec_worksheets IS record ( w VARCHAR2(30) , whdr VARCHAR2(300), wftr VARCHAR2(2000) );
    TYPE tbl_worksheets IS TABLE OF rec_worksheets INDEX BY BINARY_INTEGER ;
    g_worksheets tbl_worksheets ;
    g_null_worksheets tbl_worksheets ;
    g_worksheets_count NUMBER := 0;
    TYPE rec_cell_data IS record ( r NUMBER , c NUMBER , v VARCHAR2(2000) ,s VARCHAR2(30) , w VARCHAR2(100), dt VARCHAR2(8) );
    TYPE tbl_cell_data IS TABLE OF rec_cell_data INDEX BY binary_INTEGER ;
    g_cells tbl_cell_data ;
    g_null_cells tbl_cell_data ;
    g_cell_count NUMBER := 0 ;
    TYPE rec_columns_data IS record( c NUMBER, wd NUMBER, w VARCHAR2(30) ) ;
    TYPE tbl_columns_data IS TABLE OF rec_columns_data Index BY BINARY_INTEGER ;
    g_columns tbl_columns_data ;
    g_null_columns tbl_columns_data ;
    g_column_count NUMBER ;
    TYPE rec_rows_data IS record( r NUMBER, ht NUMBER , w VARCHAR2(30) ) ;
    TYPE tbl_rows_data IS TABLE OF rec_rows_data Index BY BINARY_INTEGER ;
    g_rows tbl_ROWS_data ;
    g_null_rows tbl_rows_data ;
    g_ROW_count NUMBER ;
    PROCEDURE p ( p_string IN VARCHAR2) is
    begin
    IF debug_flag = TRUE THEN
    DBMS_OUTPUT.put_line( p_string) ;
    END IF;
    END ;
    FUNCTION style_defined ( p_style IN VARCHAR2 ) RETURN BOOLEAN IS
    BEGIN
    FOR i IN 1..g_style_count LOOP
    IF g_styles(i).s = p_style THEN
    RETURN TRUE ;
    END IF;
    END LOOP ;
    RETURN FALSE ;
    END ;
    -- Function : cell_used returns : BOOLEAN
    -- Description : Cell_used FUNCTION returns TRUE IF that cell IS already used
    -- Called BY : write_Cell_char, write_cell_num
    -- ??? right now it IS NOT called BY write_Cell_null , this needs TO be evaluated
    FUNCTION cell_used ( p_r IN NUMBER , p_c IN number , p_w IN VARCHAR2 ) RETURN BOOLEAN IS
    BEGIN
    FOR i IN 1..g_cell_count LOOP
    IF ( g_cells(i).r = p_r AND g_cells(i).c = p_c AND g_cells(i).w = p_w ) THEN
    RETURN TRUE ;
    END IF;
    END LOOP ;
    RETURN FALSE ;
    END ;
    PROCEDURE initialize_collections IS
    --- following lines resets the cell data and the cell count as it was
    -- observed that the data is retained across the two runs within same seseion.
    BEGIN
    g_cells := g_null_cells ;
    g_Cell_count := 0 ;
    g_styles := g_null_styles ;
    g_style_count := 0 ;
    g_rows := g_null_rows ;
    g_ROW_count := 0 ;
    g_columns := g_null_columns ;
    g_column_count := 0 ;
    g_excel_data := g_null_data ;
    g_data_count := 0 ;
    g_apps_env := 'U';
    g_worksheets := g_null_worksheets ;
    g_worksheets_count := 0;
    END ;
    PROCEDURE create_excel_apps is
    BEGIN
    -- CHECK the env value
    IF g_apps_env = 'N' THEN
    raise_application_error( -20001 , 'You have already called create_excel ( Non Apps ) procedure, Can not set env to create_excel_apps.');
    END IF ;
    initialize_collections ;
    g_apps_env := 'Y' ;
    END ;
    PROCEDURE create_excel( p_directory IN VARCHAR2 DEFAULT NULL , p_file_name IN VARCHAR2 DEFAULT NULL )
    IS
    BEGIN
    -- CHECK the env value
    IF g_apps_env = 'Y' THEN
    raise_application_error( -20001 , 'You have already called procedure create_excel_apps , Can not set env to Non-Apps create_excel.');
    END IF ;
    initialize_collections ;
    g_apps_env := 'N' ;
    IF ( p_directory IS NULL OR p_file_name IS NULL ) THEN
    raise_application_error( -20001 , 'p_directory and p_file_name must be not null');
    END IF ;
    BEGIN
    -- Open the FILE IN the specified directory
    l_file := utl_file.fopen( p_directory, p_file_name , 'w') ;
    EXCEPTION
    WHEN utl_file.write_error THEN
    raise_application_error( -20101 , 'UTL_FILE raised write error, check if file is already open or directory access');
    WHEN utl_file.INVALID_OPERATION THEN
    raise_application_error( -20101 , 'UTL_FILE could not open file or operate on it, check if file is already open.');
    WHEN utl_file.invalid_path THEN
    raise_application_error( -20101 , 'UTL_FILE raised invalid path, check the directory passed is correct and you have access to it.');
    WHEN others THEN
    raise_application_error( -20101 , 'UTL_FILE raised others exception ');
    END ;
    p( 'File '||p_file_name ||' created successfully');
    END ;
    PROCEDURE create_style( p_style_name IN VARCHAR2
    , p_fontname IN VARCHAR2 DEFAULT NULL
    , p_fontcolor IN VARCHAR2 DEFAULT 'Black'
    , p_fontsize IN NUMBER DEFAULT null
    , p_bold IN BOOLEAN DEFAULT FALSE
    , p_italic IN BOOLEAN DEFAULT FALSE
    , p_underline IN VARCHAR2 DEFAULT NULL
    , p_backcolor IN VARCHAR2 DEFAULT NULL ) is
    l_style VARCHAR2(2000) ;
    l_font VARCHAR2(1200);
    BEGIN
    --- CHECK IF this style IS already defined AND RAISE ERROR IF yes
    IF style_defined( p_style_name ) THEN
    RAISE_application_error( -20001 , 'Style "'||p_style_name ||'" is already defined.');
    END IF;
    g_style_count := g_style_count + 1;
    ---- ??? pass ANY value OF underline AND it will only use single underlines
    -- ??? pattern IS NOT handleed
    IF upper(p_style_name) = 'DEFAULT' THEN
    RAISE_application_error( -20001 , 'Style name DEFAULT is not allowed ');
    END IF ;
    IF upper(p_style_name) IS NULL THEN
    RAISE_application_error( -20001 , 'Style name can not be null ');
    END IF ;
    g_styles(g_style_count).s := p_style_name ;
    g_styles(g_style_count).def := ' <Style ss:ID="'|| p_style_name ||'"> ' ;
    l_font := ' <Font ' ;
    IF p_fontname IS NOT NULL THEN
    l_font :=l_font || 'ss:FontName="'|| p_fontname ||'" ';
    end if ;
    IF p_fontsize is not null then
    l_font := l_font ||' ss:Size="'|| p_fontsize ||'" ';
    end if ;
    IF p_fontcolor is not null then
    l_font := l_font ||' ss:Color="'|| p_fontcolor ||'" ';
    ELSE
    l_font := l_font ||' ss:Color="Black" ';
    end if ;
    IF p_bold = TRUE THEN
    l_font := l_font ||' ss:Bold="1" ' ;
    END IF;
    IF p_italic = TRUE THEN
    l_font := l_font ||' ss:Italic="1" ' ;
    END IF;
    IF p_underline IS NOT NULL THEN
    l_font := l_font ||' ss:Underline="Single" ' ;
    END IF ;
    -- p( l_font );
    g_styles(g_style_count).def := g_styles(g_style_count).def || l_font || '/>' ;
    IF p_backcolor IS NOT NULL THEN
    g_styles(g_style_count).def := g_styles(g_style_count).def || ' <Interior ss:Color="'||p_backcolor ||'" ss:Pattern="Solid"/>' ;
    ELSE
    g_styles(g_style_count).def := g_styles(g_style_count).def || ' <Interior/>';
    END IF ;
    g_styles(g_style_count).def := g_styles(g_style_count).def || ' </Style>' ;
    --- ??? IN font there IS SOME family which IS NOT considered
    END ;
    PROCEDURE close_file IS
    l_last_row NUMBER := 0 ;
    l_dt CHAR ; -- ??? Variable TO store the datatype ; this IS NOT used at this time but may be needed IF the memory
    -- issue IS there FOR example IF there IS big array
    l_style VARCHAR2(140) ;
    l_row_change VARCHAR2(100) ;
    l_file_header VARCHAR2(2000) := '<?xml version="1.0"?>
    <?mso-application progid="Excel.Sheet"?>
    <Workbook xmlns="urn:schemas-microsoft-com:office:spreadsheet"
    xmlns:o="urn:schemas-microsoft-com:office:office"
    xmlns:x="urn:schemas-microsoft-com:office:excel"
    xmlns:ss="urn:schemas-microsoft-com:office:spreadsheet"
    xmlns:html="http://www.w3.org/TR/REC-html40">
    <DocumentProperties xmlns="urn:schemas-microsoft-com:office:office">
    <LastAuthor>a</LastAuthor>
    <Created>1996-10-14T23:33:28Z</Created>
    <LastSaved>2007-05-10T04:00:57Z</LastSaved>
    <Version>11.5606</Version>
    </DocumentProperties>
    <ExcelWorkbook xmlns="urn:schemas-microsoft-com:office:excel">
    <WindowHeight>9300</WindowHeight>
    <WindowWidth>15135</WindowWidth>
    <WindowTopX>120</WindowTopX>
    <WindowTopY>120</WindowTopY>
    <AcceptLabelsInFormulas/>
    <ProtectStructure>False</ProtectStructure>
    <ProtectWindows>False</ProtectWindows>
    </ExcelWorkbook>
    <Styles>
    <Style ss:ID="Default" ss:Name="Normal">
    <Alignment ss:Vertical="Bottom"/>
    <Borders/>
    <Font/>
    <Interior/>
    <NumberFormat/>
    <Protection/>
    </Style>'
    BEGIN
    IF gen_xl_xml.g_Cell_count = 0 THEN
    raise_application_error( -20007 , 'No cells have been written, this version of gen_xl_xml needs at least one cell to be written');
    END IF;
    IF gen_xl_xml.g_worksheets_count = 0 THEN
    raise_application_error( -20008 , 'No worksheets have been created, this version does not support automatic worksheet creation');
    END IF;
    p( gen_xl_xml.g_Cell_count) ;
    -- Write the header xml part IN the FILE.
    g_data_count := g_data_count + 1 ;
    g_excel_data( g_data_count ) := l_file_header ;
    p( 'Headers written');
    FOR i IN 1..g_style_count LOOP
    p( ' writing style number : '||i);
    g_data_count := g_data_count + 1 ;
    g_excel_data( g_data_count ) := g_styles(i).def ;
    END LOOP ;
    -- CLOSE the styles tag
    g_data_count := g_data_count + 1 ;
    g_excel_data( g_data_count ) := ' </Styles>' ;
    p( 'worksheet count '|| g_worksheets_count );
    FOR j IN 1..g_worksheets_count LOOP
    l_last_row := 0 ; --- FOR every worksheet we need TO CREATE START OF the row
    p( '()()------------------------------------------------------------ last row '||l_last_row );
    --- write the header first
    -- write the COLUMN widhts first
    -- write the cells
    -- write the worksheet footer
    l_row_change := NULL ;
    g_data_count := g_data_count + 1 ;
    g_excel_data( g_data_count ) := ' <Worksheet ss:Name="'|| g_worksheets( j).w ||'"> ' ;
    p( '-------------------------------------------------------------');
    p( '****************.Generated sheet '|| g_worksheets( j).w);
    p( '-------------------------------------------------------------');
    -- write the TABLE structure ??? change the LINE here TO include tha maxrow AND cell
    g_data_count := g_data_count + 1 ;
    g_excel_data( g_data_count ) := '<Table ss:ExpandedColumnCount="16" ss:ExpandedRowCount="44315" x:FullColumns="1" x:FullRows="1">' ;
    FOR i IN 1..g_column_count LOOP
    IF g_columns(i).w = g_worksheets( j).w THEN
    g_data_count := g_data_count + 1 ;
    g_excel_data( g_data_count ) := ' <Column ss:Index="'||g_columns(i).c||'" ss:AutoFitWidth="0" ss:Width="'||g_columns(i).wd ||'"/> ' ;
    END IF;
    END LOOP ;
    -- write the cells data
    FOR i IN 1..g_cell_count LOOP ------ LOOP OF g_cell_count
    p( '()()()()()()()()()()()() '|| i);
    --- we will write only IF the cells belongs TO the worksheet that we are writing.
    IF g_cells(i).w <> g_worksheets(j).w THEN
    p( '........................Cell : W :'|| g_worksheets( j).w ||'=> r='|| g_cells(i).r ||',c ='|| g_cells(i).c||',w='|| g_cells(i).w );
    p( '...Not in this worksheet ');
    -- l_last_row := l_last_row -1 ;
    ELSE
    p( '........................Cell : W :'|| g_worksheets( j).w ||'=> r='|| g_cells(i).r ||',c ='|| g_cells(i).c||',w='|| g_cells(i).w );
    IF g_cells(i).s IS NOT NULL AND NOT style_defined( g_cells(i).s ) THEN
    -- p(g_cells(i).s) ;
    raise_application_error( -20001 , 'Style "'||g_cells(i).s ||'" is not defined, Note : Styles are case sensative and check spaces used while passing style');
    END IF;
    p( '()()------------------------------------------------------------ last row '||l_last_row );
    IF l_last_row = 0 THEN
    FOR t IN 1..g_row_count LOOP
    p( '...Height check => Row =' ||g_rows(t).r ||', w='||g_rows(t).w);
    IF g_rows(t).r = g_cells(i).r AND g_rows(t).w = g_worksheets(j).w THEN
    p( '...Changing height') ;
    l_row_change := ' ss:AutoFitHeight="0" ss:Height="'|| g_rows(t).ht||'" ' ;
    g_data_count := g_data_count + 1 ;
    g_excel_data( g_data_count ) := ' <Row ss:Index="'||g_cells(i).r||'"'|| l_row_change ||'>' ;
    l_last_row := g_cells(i).r ;
    EXIT ;
    ELSE
    p( '...NO change height') ;
    l_row_change := NULL ;
    END IF ;
    END loop ;
    IF l_ROW_CHANGE IS NULL THEN
    g_data_count := g_data_count + 1 ;
    p( '...Creating new row ');
    g_excel_data( g_data_count ) := ' <Row ss:Index="'||g_cells(i).r||'"'|| l_row_change ||'>' ;
    l_last_row := g_cells(i).r ;
    END IF;
    END IF;
    IF g_cells(i).s IS NOT NULL THEN
    p( '...Adding style ');
    l_style := ' ss:StyleID="'||g_cells(i).s||'"' ;
    ELSE
    p( '...No style for this cell ');
    l_style := NULL ;
    END IF;
    p( '()()------------------------------------------------------------ last row '||l_last_row );
    IF g_cells(i).r <> l_last_row THEN
    p('...closing the row.'||g_cells(i).r);
    g_data_count := g_data_count + 1 ;
    g_excel_data( g_data_count ) := ' </Row>' ;
    p( 'ROWCOUNT : '||g_row_count );
    FOR t IN 1..g_ROW_count LOOP
    p( '.....Height check => Row =' ||g_rows(t).r ||', w='||g_rows(t).w);
    IF g_rows(t).r = g_cells(i).r AND g_rows(t).w = g_worksheets(j).w THEN
    p( '.....Changing height') ;
    l_row_change := ' ss:AutoFitHeight="0" ss:Height="'|| g_rows(t).ht||'" ' ;
    g_data_count := g_data_count + 1 ;
    g_excel_data( g_data_count ) := ' <Row ss:Index="'||g_cells(i).r||'"'|| l_row_change ||'>' ;
    EXIT ;
    ELSE
    p( '.....NO change height') ;
    l_row_change := NULL ;
    END IF ;
    END loop ;
    -- P( 'Row :'||g_cells(i).r ||'->'|| l_ROW_CHANGE);
    IF l_row_change IS NULL THEN
    g_data_count := g_data_count + 1 ;
    g_excel_data( g_data_count ) := ' <Row ss:Index="'||g_cells(i).r||'"'|| l_row_change ||'>' ;
    END IF;
    IF g_cells(i).v IS NULL THEN
    g_data_count := g_data_count + 1 ;
    g_excel_data( g_data_count ) := '<Cell ss:Index="'||g_cells(i).c||'"' || l_style ||' ></Cell>';
    ELSE
    g_data_count := g_data_count + 1 ;
    g_excel_data( g_data_count ) := '<Cell ss:Index="'||g_cells(i).c||'"' || l_style ||' ><Data ss:Type="'||g_cells(i).dt ||'">'||g_cells(i).v||'</Data></Cell>';
    END IF ;
    l_last_row :=g_cells(i).r ;
    ELSE
    IF g_cells(i).v IS NULL THEN
    g_data_count := g_data_count + 1 ;
    g_excel_data( g_data_count ) := '<Cell ss:Index="'||g_cells(i).c||'"' || l_style ||' > </Cell>';
    ELSE
    g_data_count := g_data_count + 1 ;
    g_excel_data( g_data_count ) := '<Cell ss:Index="'||g_cells(i).c||'"' || l_style ||' ><Data ss:Type="'||g_cells(i).dt ||'">'||g_cells(i).v||'</Data></Cell>';
    END IF ;
    END IF ;
    END IF ;
    NULL ;
    END LOOP ; -- LOOP OF g_cells_count
    p('...closing the row.');
    g_data_count := g_data_count + 1 ;
    g_excel_data( g_data_count ) := ' </Row>' ;
    -- ??? does following COMMENT will have sheet NAME FOR debugging
    p( '-------------------------------------------------------------');
    p( '....End of writing cell data, closing table tag');
    g_data_count := g_data_count + 1 ;
    g_excel_data( g_data_count ) := ' </Table>' ;
    g_data_count := g_data_count + 1 ;
    g_excel_data( g_data_count ) := g_worksheets(j).wftr ;
    p( '..Closed the worksheet '|| g_worksheets( j).w );
    END LOOP ;
    g_data_count := g_data_count + 1 ;
    g_excel_data( g_data_count ) := '</Workbook>' ;
    p( 'Closed the workbook tag');
    IF g_apps_env = 'N' THEN
    FOR i IN 1..g_data_count LOOP
    utl_FILE.put_line( l_file, g_excel_data(i ));
    END LOOP ;
    utl_file.fclose( l_file );
    p( 'File closed ');
    ELSIF g_apps_env = 'Y' THEN
    FOR i IN 1..g_data_count LOOP
    fnd_file.put_line( fnd_file.output , g_excel_data(i));
    fnd_file.put_line( fnd_file.log , g_excel_data(i));
    END LOOP ;
    ELSE
    raise_application_error( -20001 , 'Env not set, ( Apps or not Apps ) Contact Support.' );
    END IF;
    END ;
    PROCEDURE create_worksheet ( p_worksheet_name IN VARCHAR2 ) IS
    BEGIN
    g_worksheets_count := g_worksheets_count + 1 ;
    g_worksheets(g_worksheets_count).w := p_worksheet_name ;
    g_worksheets(g_worksheets_count).whdr := '<Worksheet ss:Name=" ' || p_worksheet_name ||' ">' ;
    g_worksheets(g_worksheets_count).wftr := '<WorksheetOptions xmlns="urn:schemas-microsoft-com:office:excel">
    <ProtectObjects>False</ProtectObjects>
    <ProtectScenarios>False</ProtectScenarios>
    </WorksheetOptions>
    </Worksheet>' ;
    END ;
    PROCEDURE write_cell_char(p_row NUMBER, p_column NUMBER, p_worksheet_name IN VARCHAR2, p_value IN VARCHAR2, p_style IN VARCHAR2 DEFAULT NULL ) IS
    l_ws_exist BOOLEAN ;
    l_worksheet VARCHAR2(2000) ;
    BEGIN
    -- CHECK IF this cell has been used previously.
    IF cell_used( p_row , p_column , p_worksheet_name ) THEN
    RAISE_application_error( -20001 , 'The cell ( Row: '||p_row ||' Column:'||p_column ||' Worksheet:'||p_worksheet_name ||') is already used.Check if you have missed to increment row number in your code. ');
    END IF;
    -- IF worksheet NAME IS NOT passed THEN use first USER created sheet ELSE use DEFAULT sheet
    -- this PROCEDURE just adds the data INTO the g_cells TABLE
    g_cell_count := g_cell_count + 1 ;
    g_cells( g_cell_count ).r := p_row ;
    g_cells( g_cell_count ).c := p_column ;
    g_cells( g_cell_count ).v := p_value ;
    g_cells( g_cell_count ).w := p_worksheet_name ;
    g_cells( g_cell_count ).s := p_style ;
    g_cells( g_cell_count ).dt := 'String' ;
    END ;
    PROCEDURE write_cell_num(p_row NUMBER , p_column NUMBER, p_worksheet_name IN VARCHAR2, p_value IN NUMBER , p_style IN VARCHAR2 DEFAULT NULL ) IS
    l_ws_exist BOOLEAN ;
    l_worksheet VARCHAR2(2000) ;
    BEGIN
    -- ??? IF worksheet NAME IS NOT passed THEN use first USER created sheet ELSE use DEFAULT sheet
    -- this PROCEDURE just adds the data INTO the g_cells TABLE
    -- CHECK IF this cell has been used previously.
    IF cell_used( p_row , p_column , p_worksheet_name ) THEN
    RAISE_application_error( -20001 , 'The cell ( Row: '||p_row ||' Column:'||p_column ||' Worksheet:'||p_worksheet_name ||') is already used. Check if you have missed to increment row number in your code.');
    END IF;
    g_cell_count := g_cell_count + 1 ;
    g_cells( g_cell_count ).r := p_row ;
    g_cells( g_cell_count ).c := p_column ;
    g_cells( g_cell_count ).v := p_value ;
    g_cells( g_cell_count ).w := p_worksheet_name ;
    g_cells( g_cell_count ).s := p_style ;
    g_cells( g_cell_count ).dt := 'Number' ;
    END ;
    PROCEDURE write_cell_null(p_row NUMBER , p_column NUMBER , p_worksheet_name IN VARCHAR2, p_style IN VARCHAR2 ) IS
    BEGIN
    -- ???? NULL IS allowed here FOR time being. one OPTION IS TO warn USER that NULL IS passed but otherwise
    -- the excel generates without error
    g_cell_count := g_cell_count + 1 ;
    g_cells( g_cell_count ).r := p_row ;
    g_cells( g_cell_count ).c := p_column ;
    g_cells( g_cell_count ).v := null ;
    g_cells( g_cell_count ).w := p_worksheet_name ;
    g_cells( g_cell_count ).s := p_style ;
    g_cells( g_cell_count ).dt := NULL ;
    END ;
    PROCEDURE set_row_height( p_row IN NUMBER , p_height IN NUMBER, p_worksheet IN VARCHAR2 ) IS
    BEGIN
    g_ROW_count := g_ROW_count + 1 ;
    g_rows( g_row_count ).r := p_row ;
    g_rows( g_row_count ).ht := p_height ;
    g_rows( g_row_count ).w := p_worksheet ;
    END ;
    PROCEDURE set_column_width( p_column IN NUMBER , p_width IN NUMBER, p_worksheet IN VARCHAR2 ) IS
    BEGIN
    g_column_count := g_column_count + 1 ;
    g_columns( g_column_count ).c := p_column ;
    g_columns( g_column_count ).wd := p_width ;
    g_columns( g_column_count ).w := p_worksheet ;
    END ;
    END ;
    SHOW errors ;
    Thanks,
    Maddy B

    Hi,
    Peter Gjelstrup wrote:
    Next thing is how to use it:
    declare
    k_file constant varchar2(30) := 'YourFile.xls'
    begin
    create_file(k_file);
    -- Call other procedures
    close_file;
    end;
    Don't forget: these procedures are all part of the gen_xl_xml package.
    To call them from outside the package, you have to prefix each procedure name with the package name, like this:
    declare
    k_file constant varchar2(30) := 'YourFile.xls'
    begin
    gen_xl_xml.create_file(k_file);
    -- Call other procedures
    gen_xl_xml.close_file;
    end;

  • JSP XML output to file system

    I hava a JSP application that uses the XDK to query the database and display XML rowset data to a JSP. This rowset data can be a few hundred rows or up to 50,000 rows,
    as we publish technical manuals, parts manuals and wiring manuals for aircraft.
    Getting the data to display within the JSP is not a problem. The problem is
    that the XML rowset data shares two purposes:
    1. Query by Example, returning
    XML formatted data for display within a browser.
    2. Use of the XML formatted
    data as an external entity file for our SGML authoring software to print the
    paper publication.
    The JSP I developed (I'm not sure I should take credit for it) uses the XMLData bean and it will open the browser File/SaveAs dialog in both Netscape (Unix) and IE5.5 (Windows). HOWEVER, when I create a second JSP to perform the same task on a different table the JSP errorpage shows with no error and no errors within the JDeveloper console. This has been kicking my butt for some time, and would very much appreciate a workable solution. I will share whatever I can share with the provider. Here is the JSP code.
    =============================================
    <?xml version="1.0"?>
    <%@ page language = "java" errorPage="errorpage.jsp" import = "java.io.*, java.util.*, oracle.jbo.*, javax.naming.*, oracle.jdeveloper.html.*, oracle.jbo.html.databeans.*" contentType="text/html;charset=ISO-8859-1" %>
    <jsp:useBean class="oracle.jbo.html.databeans.XmlData" id="h25EqXml" scope="request" >
    <%
    h25EqXml.setResultElement("equiptbl");
    h25EqXml.setReleaseApplicationResources(true);
    h25EqXml.setDisplayAttributes("Ein,Pnr,Nomen,Cage,Diagnbr,Sht,Effect");
    h25EqXml.initialize(pageContext,"h25Wires_JspApp_h25Wires_be_H25Wires_beModule.HU25A_Equipment");
    response.setContentType("text/sgml");
    response.setHeader("Content-location","attachment;filename="+"equiptbl.sgm");
    ServletOutputStream sos = response.getOutputStream();
    BufferedInputStream bis = new BufferedInputStream (new FileInputStream("equiptbl.sgm"));
    int data;
    while((data = bis.read()) != -1)
    sos.write(data);
    bis.close();
    sos.flush();
    sos.close();
    %>
    <jsp:forward page= "HU5A_Equipment_Browse.jsp" />
    </jsp:useBean>
    ============================================
    The code for the other pages is the same with the exception of the filename xxx.sgm and the bean id.
    I very much appreciate your help. Thanks!
    null

    Hello Paulo,
    thank you for your answer, but i'm using type 04 XML for SEPA.
    when i select Type XML, the fields "output to file system" and "filename" are hidden.
    i dont understand why ...

  • Spool SQl data into text file using dynamic sql

    Hi,
    I am spooling output data into text file using command
    select 'select t.mxname,bo.lxtype,t.mxrev'||chr(10)||'from mx_1234567'||chr(10)||
    'where <condition>';
    here mxname varchar(128),lxtype(128),mxrev(128) all are of varchar type.I want the output in format
    e.g Part|1211121313|A
    but due to column width the output,I am getting is with spaces.
    "Part then blank spaces |1211121313 then blank spaces |A"
    how can I remove these spaces between columns.I used set space 0 but not working.
    Thanks in advance.
    Your help will be appreciated.

    Hi Frank,
    I have seen your reply for SET LINE SIZE function. But, I could not be able to understand it.
    I am facing similar kind of issue in my present project.
    I am trying spool more than 50 columns from a table into flat file. Because of more column lengths in few columns, i am getting space. There are so many columns with the same issue. I want to remove that space.so that, data can fit perfectly in one line in .txt file without any wrap text.
    Below is my sample query.sql. Please let me know the syntax. My mail id : [email protected]
    --Created : Sep 22,2008, Created By : Srinivasa Bojja
    --Export all Fulfillments
    --Scheduled daily after 1:00am and should complete before 3:30am
    WHENEVER SQLERROR EXIT SQL.SQLCODE
    SET LINESIZE 800
    SET WRAP OFF
    SET PAGESIZE 800
    SET FEEDBACK OFF
    SET HEADING ON
    SET ECHO OFF
    SET CONCAT OFF
    SET COLSEP '|'
    SET UNDERLINE OFF
    SPOOL C:\Fulfillment.txt;
    SELECT SRV.COMM_METHOD_CD AS Method,
    SRV.SR_NUM AS "Fulfillment Row_Id",
    CON.LAST_NAME AS "Filled By"
    SRV.SR_TITLE AS Notes,
    SRVXM.ATTRIB_04 AS "Form Description"
    FROM SIEBEL.S_SRV_REQ SRV,
    SIEBEL.S_SRV_REQ_XM SRVXM,
    SIEBEL.S_USER USR,
    SIEBEL.S_CONTACT CON
    WHERE SRV.ROW_ID = SRVXM.PAR_ROW_ID AND
    SRV.OWNER_EMP_ID = USR.ROW_ID AND
    CON.ROW_ID= SRV.CST_CON_ID;
    SPOOL OFF;
    EXIT;

Maybe you are looking for