Question

Parse XML File using PL/SQL

Asked by: hthukral

Hello Everyone,

I have XML File along these lines. I need to parse this file from a location and dont want to keep in the Dbase just get the results and do some calculations and show the results.

My Question is how can I read this file using PL/SQL and from a particular location.


<sch>
  <cr>A</cr>
  <year>2005</year>
  <title />
- <month>
  <name>January</name>
- <week>
  <week>1</week>
- <day>
  <id>1</id>
  <code />
  <day_num />
  </day>
- <day>
  <id>2</id>
  <code />
  <day_num />
  </day>
- <day>
  <id>3</id>
  <code />
  <day_num />
  </day>

Thanks,
Harsimrat

This Question has been solved and asker verified All Experts Exchange premium technology solutions are available to subscription members.

Subscribe now for full access to Experts Exchange and get

Instant Access to this Solution

  • Plus...
  • 30 Day FREE access, no risk, no obligation
  • Collaborate with the world's top tech experts
  • Unlimited access to our exclusive solution database
  • Never be left without tech help again

Subscribe Now

Asked On
2005-10-19 at 13:12:37ID21600835
Tags

xml

,

file

Topic

Oracle Database

Participating Experts
3
Points
250
Comments
23

Trusted by hundreds of thousands everyday for fast, accurate and reliable tech support.

  • "The time we save is the biggest benefit of Experts Exchange to Warner Bros. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange." Mike Kapnisakis, Warner Bros.
  • "Our team likes having a resource that is more secure than just using Google and most experts using this service really know their stuff. It's nice to look here first versus using Google." Dayna Sellner, Lockheed Martin
  • "Anytime that I've been stumped with a problem, 9 out of 10 times Experts Exchange has either the accepted solution or an open discussion of the potential solution to the problem." Kenny Red, eBay Inc.

See what Experts Exchange can do for you.

Got a question?

We've got the answer.

Experts Exchange has been collecting answers to technology questions since 1996…3 million and counting! If you have a question, chances are we already have your answer.

Screenshot of Experts Exchange Knowledgebase

Need individual assistance?

Our experts are ready to help.

If you can't find the exact answer you're looking for, ask our exclusive community of 50,000 experts. You’ll get a personalized answer from a trusted professional.

Screenshot of Experts Exchange Knowledgebase

Want to learn from the best?

Read articles from industry experts.

Thousands of free tech tips, tricks, how-to’s and tutorials are available in our peer reviewed articles section. See for yourself how smart our experts are, no login required.

Screenshot of an Article

Working on a long term project?

Store your work and research.

Save solutions to your questions, answers you’ve discovered through searching plus helpful articles in your personal knowledgebase for easy future access.

Screenshot of Experts Exchange Knowledgebase

Access the answers to your technology questions today.

Subscribe Now

30-day free trial. Register in 60 seconds.

What Makes Experts Exchange Unique?

Members of the expert community talk about why the experience at Experts Exchange is different than what you will find anywhere else.

Trusted by the world's most respected brands.

image of each brand's logo

Faithfully serving IT professionals since 1996.

Experts Exchange Logo

Try it out and discover for yourself.

Subscribe Now

30-day free trial. Register in 60 seconds.

Related Solutions

  1. par file
    Waht is a file with .par used for and what does this extension mean? Can I list the parameters for import in a .par file and use this file in imp, like imp file=filename.par Please suggest.
  2. PAR Protocol
    How has the PAR Protocol been extended for use in the Internet?
  3. Converting from PERL to Executable using PAR
    I have a PERL script that begins with the following: use Win32::OLE qw(in with); use Win32::OLE::Const 'Microsoft Excel'; When I convert my PERL script to an executable using pp -o file.exe file.pl, there is no problem. But, when I run file.exe I receive the following pop-...
  4. xml, deref question
    Here's a SIMPLE xml parse use XML::Simple; my $file = 'x.xml'; my $x = XML::Simple->new(); my $doc = $x->XMLin($file); use Data::Dumper; s$Data::Dumper::Indent = 1; $VAR1 = { 'view-elem' => { 'viewpool' => { 'viewparameters' => { 'view_...
  5. What does the /par in a .bat file mean?
    I am learning to do batch files, and came across this /par in my .bat file. I dont know really how it got there, as I was just manually creating the batch. I did just install easy batch creator, but I didnt use that prog. Anyway here is the code that I have in my batch, but ...

Free Tech Articles

  1. WARNING: 5 Reasons why you should NEVER fix a computer for free.
    It is in our nature to love the puzzle. We are obsessed. The lot of us. We love puzzles. We love the challenge. We thrive on finding the answer. We hate disarray. It bothers us deep in our soul. W...
  2. SCCM OSD Basic troubleshooting
    SCCM 2007 OSD is a fantastic way to deploy operating systems, however, like most things SCCM issues can sometimes be difficult to resolve due to the sheer volume of logs to sift through and the dispe...
  3. Migrate Small Business Server 2003 to Exchange 2010 and Windows 2008 R2
    This guide is intended to provide step by step instructions on how to migrate from Small Business Server 2003 to Windows 2008 R2 with Exchange 2010. For this migration to work you will need the fo...
  4. Create a Win7 Gadget
    This article shows you how to create a simple "Gadget" -- a sort of mini-application supported by Windows 7 and Vista. Gadgets can be dropped anywhere on the desktop to provide instant information, ...
  5. Outlook continually prompting for username and password
    There have been a lot of questions recently regarding Outlook prompting for a username and password whilst using Exchange 2007. There are a few reasons why this would happen and I will try to cover t...
  6. Backup Exchange 2010 Information Store using Windows Backup
    There seems to be quite a lot of confusion around the ability to backup Exchange 2010 using the built in Windows Backup feature. This stems from the omission of this feature prior to Exchange 2007 s...

Cloud Class Webinars

  1. Avoiding Bugs in Microsoft Access
    Alison Balter takes and in-depth look at avoiding bugs in Access. In this webinar you will learn about using the immediate window to debug your applications, invoking the debugger, using breakpoints to troubleshoot, stepping through code, setting the next statement to execute, ...
  2. Top 10 Best New Features in Visio 2010
    Scott Helmers gives live demonstrations of the top 10 new features in Visio 2010. This webinar will teach you how to create compelling diagrams by adding shapes to the page with a single click, linking the shapes in a diagram to data in Excel (or SQL Server, or SharePoint), ...
  3. IT Consultant Business Secrets Revealed
    Michael Munger, Experts Exchange tech pro and IT consultant, pulls back the curtain on his very successful businesses and answers question on every IT consultant and business owner should know about. He shares secrets on what he did to solve the 5 most common problems in IT, ...
  4. Disaster Recovery and Business Continuity
    Quest CTO, Mike Billon, gives an overview of the steps involved in building a dunamic disaster recovery plan. Through case studies and an examination of software/hardware tooles for monitoring and testing, you'll gain a better understandin of where you are, where you want ...
  5. Organize Your Visio Diagrams with Containers and Lists
    Scott Helmers uses cross functional flowcharts, wireframe diagrams, data graphic legends and seating charts to teach you: how to ustilize all three new structured diagram components in Visio 2010, the best practices for organizeing shapes in previous version of Visio, how to organize ...
  6. How to Us Objects, Properties, Events and Methods in Microsoft Access
    Alison Dalter gives an in-depbth look at objects, properties, events and methods in Microsoft Access. In this webinar you will learn about using the object browser, referring to objects, working with properties and methods, working with object variables, understanding the ...

Join the Community

Give a Little. Get a Lot.

Join the community of experts here and help other tech pros by answering question in your area of expertise. You can earn FREE access to all Experts Exchange's premium features and resources.

Join the Community

Answers

 

by: schwertnerPosted on 2005-10-20 at 00:46:14ID: 15122355

For  reading files into buffer use:

procedure YOUR_PROC   is

   sasha SYS.UTL_FILE.FILE_TYPE;

    sanjeev   VARCHAR2(1800);

begin

  sasha := UTL_File.Fopen('D:\staff\cv','56789.txt', 'r');
 

LOOP

UTL_File.get_line(sasha,sanjeev);

-- FORMAT THE DATA in/from buffer sanjeev and insert in Oracle DB using INSERT statement

END LOOP              
               
EXCEPTION
WHEN no_data_found THEN  
UTL_File.Fclose(sasha);                      
WHEN  UTL_File.invalid_filehandle   THEN ... UTL_File.Fclose(sasha);  
      --   invalid_filehandle - not a valid file handle
WHEN  UTL_File.read_error   THEN ... UTL_File.Fclose(sasha);
       -- OS error occurred during read
WHEN  UTL_File.invalid_operation   THEN ... UTL_File.Fclose(sasha);                    

end  YOUR_PROC ;


REMARK
Server security for PL/SQL file I/O consists of a restriction on the directories that can be accessed.
Accessible directories must be specified in the
instance parameter initialization file (INIT.ORA).

Specify the accessible directories for the UTL_FILE
functions in the initialization file
using the UTL_FILE_DIR parameter.
For example:
UTL_FILE_DIR = <directory name>
like in
UTL_FILE_DIR = C:\DATA\ORACLE\DATAFILES
Starting from 9i you can use Oracle directories instead:

create or replace directory XMLDIR as 'E:\ICW_TASKS\XML\SOURCE\';
grant read on directory xmldir to my_user with grant option;

 

by: ivostoykovPosted on 2005-10-20 at 01:16:20ID: 15122474

Hell hthukral

If you are not going to store data into DB I think it is not a good idea to use SQL for this. Use some script languages, Java, .NET or whatever.

If you want to practice you have to use DBMS_XML* packages. Documentation is here - Packages and Types Reference - here's the contents
http://www.oracle.com/pls/db102/show_toc?partno=b14258&remark=drilldown&word=


Good luck

I

 

by: slightwvPosted on 2005-10-20 at 10:12:22ID: 15126284

I agree with ivostoykov.  Depending on the full requirements, there may be easier ways to acheive this.  It may be as simple as applying an XSL Stylesheet.

If you are set on using the DB to perform this, I wanted to throw out using DBMS_LOB.LOADCLOBFROMFILE to get the contents into a CLOB variable then there are several things you could do to it.  For example, use the DOM to process it of simple XML SQL calls.

Note:  Using DBMS_LOB or UTL_FILE, the file would need to be located on the DB server itself.

If possible, please provide a little more detail.

 

by: schwertnerPosted on 2005-10-21 at 03:11:47ID: 15131071

You asked a PL/SQL solution and I gave it as by my knowledge.
To use another tools is easy but there is a big prerequisite - one have to know and to posses experience in that tool.
Speaking retorically one can use Java, VB, VC++, C, Basic, Assembler, Fortran, Cobol, Lisp, Prolog, PL/I, ADA or even machine code directly.

 

by: hthukralPosted on 2005-10-21 at 06:14:56ID: 15131915

Hello Everyone,

I agree to you all, but the thing is I dont have any other choice. If you see the file I'm basically interested where the code is empty, and down the file there are places where code has a value.

I just need some information out of it. If say I will store the info in the tables will it be easier....Can someone let me know how I parse....Rite now I'm doing the dirty way.....

Procedure          XML_TEST

IS
      v_XML     VARCHAR2(32767) := ' ';
        v_line      VARCHAR2(1000);
      newsXML     xmldom.DOMDocument;
     
      response      xmldom.DOMNodeList;
      year      xmldom.DOMNodeList;
      month      xmldom.DOMNodeList;
      week      xmldom.DOMNodeList;
      day      xmldom.DOMNodeList;
      code      xmldom.DOMNodeList;

      curNode     xmldom.DOMNode;
      yearNode    xmldom.DOMNode;
      monthNode   xmldom.DOMNode;
      weekNode    xmldom.DOMNode;
      dayNode     xmldom.DOMNode;
      codeNode    xmldom.DOMNode;

      chNodetext      VARCHAR(100);
      chNodeName      VARCHAR(100);
     
      yeartext      VARCHAR(100);
      yearName      VARCHAR(100);
     
      monthtext      VARCHAR(100);
      monthName      VARCHAR(100);
     
      weektext      VARCHAR(100);
      weekName      VARCHAR(100);
     
      daytext      VARCHAR(100);
      dayName      VARCHAR(100);
     
      codetext      VARCHAR(100);
      codeName      VARCHAR(100);

      nodeCount     integer;
      yearCount     integer;
      monthCount    integer;
      weekCount     integer;
      dayCount      integer;
      codeCount     integer;
     
     parser       xmlparser.Parser;
      
       pt_inputFile                            UTL_FILE.file_type;
       pt_outputFile                           UTL_FILE.file_type;
      
BEGIN
     
        pt_inputFile := utl_file.fopen('/opt/bin', 'RPC_A_2005.XML', 'r');
--        pt_inputFile := utl_file.fopen('/opt/bin', 'test.xml', 'r');
        
        BEGIN
        
            LOOP
                      utl_file.get_line(pt_inputFile, v_line);
                    v_XML := v_XML||TRIM(BOTH FROM v_line);              
              END LOOP;

            
          EXCEPTION WHEN NO_DATA_FOUND THEN
            
            utl_file.fclose(pt_inputFile);
            
            
        END;


      parser  := xmlparser.newParser;
      xmlparser.parseBuffer(parser, v_XML);
      newsXML := xmlparser.getDocument(parser);
     xmlparser.freeParser(parser);


     curNode := xmldom.makeNode(newsXML);
     curNode := xslprocessor.selectSingleNode(curNode,'//schedule');
     response := xslprocessor.selectNodes(curNode,'//crew');
     nodeCount := xmldom.getLength(response);
     
     yearNode := xmldom.makeNode(newsXML);
     yearNode := xslprocessor.selectSingleNode(yearNode,'//schedule');
     year := xslprocessor.selectNodes(yearNode,'//year');
     yearCount := xmldom.getLength(year);

      FOR j IN 0..nodeCount-1 LOOP
        FOR y IN 0..yearCount-1 LOOP

          curNode := xmldom.item(response, j);

          yearNode := xmldom.item(year, y);

          chNodeName := xmldom.getnodename(curNode);
          curNode := xmldom.getFirstChild(curNode);
          chNodetext := xmldom.getNodeValue(curNode);
           
          yearName := xmldom.getnodename(yearNode);
          yearNode := xmldom.getFirstChild(yearNode);
          yeartext := xmldom.getNodeValue(yearNode);
               
          dbms_output.put_line('Name: ' || chNodeName);
          dbms_output.put_line('Value: ' || chNodetext);
         
          dbms_output.put_line('Name: ' || yearName);
          dbms_output.put_line('Value: ' || yeartext);
         
         
         END LOOP;
      END LOOP;

      xmldom.freeDocument(newsXML);

END;

Thanks,
Harsimrat

 

by: hthukralPosted on 2005-10-21 at 11:51:26ID: 15134682

Hello Everyone,

Even if it finds the NULL attribute Oracle craps out....is there any solution to get around it........

Please let me know...

Thanks,
Harsimrat

 

by: ivostoykovPosted on 2005-10-23 at 23:59:14ID: 15144517

Well here is a samplese that I hope will help you

Good luck

I

Example : Parsing XML from a String and Using DOM

CREATE OR REPLACE FUNCTION idAttributeOfDocElement(xmldoc VARCHAR2 )
RETURN VARCHAR2 IS

  theXmlDoc xmldom.DOMDocument;
  theDocElt xmldom.DOMElement;
  retval    VARCHAR2(400);
  XMLParseError EXCEPTION;
  PRAGMA EXCEPTION_INIT( XMLParseError, -20100 );

  -- Local parse function keeps code cleaner. Return NULL if parse fails
  FUNCTION parse(xml VARCHAR2) RETURN xmldom.DOMDocument IS
    retDoc xmldom.DOMDocument;
    parser xmlparser.Parser;
  BEGIN
    parser := xmlparser.newParser;
    xmlparser.parseBuffer(parser,xml);
    retDoc := xmlparser.getDocument(parser);
    xmlparser.freeParser(parser);
    RETURN retdoc;
  EXCEPTION
    -- If the parse fails, we'll jump here.
    WHEN XMLParseError THEN
      xmlparser.freeParser(parser);
      RETURN retdoc;
  END;

BEGIN
  -- Parse the xml document passed in the VARCHAR2 argument
  theXmlDoc := parse(xmldoc);
  -- If the XML document returned is not NULL...
  IF NOT xmldom.IsNull(theXmlDoc) THEN
    -- Get the outermost enclosing element (aka "Document Element")
    theDocElt := xmldom.getDocumentElement(theXmlDoc);
    -- Get the value of the document element's "id" attribute
    retval    := xmldom.getAttribute(theDocElt,'id');
    -- Free the memory used by the parsed XML document
    xmldom.freeDocument(theXmlDoc);
    RETURN retval;
  ELSE
    RETURN NULL;
  END IF;
END;

 

by: slightwvPosted on 2005-10-24 at 05:36:08ID: 15145918

If the above post doesn't help, can you post a little more information?

Like a valid XML file (1 to 3 nodes should work), expected results and brief descrpition of how you got the results.

 

by: hthukralPosted on 2005-10-24 at 08:42:10ID: 15147437

I can't get the example to work as I cant read from the file........or I'm doing something terribly wrong which I think I'm doing as I'm new with XML in PL/SQL

THE actual XML looks like this :

- <sch>
  <cr> Fun</cr>
  <year>2005</year>
  <title />
- <month>
  <name>January</name>
- <week>
  <week_num>1</week_num>
- <day>
  <id>1</id>
  <code />
  <day_num />
  </day>
- <day>
  <id>2</id>
  <code />
  <day_num />
  </day>
- <day>
  <id>3</id>
  <code />
  <day_num />
  </day>
- <day>
  <id>4</id>
  <code />
  <day_num />
  </day>
- <day>
  <id>5</id>
  <code />
  <day_num />
  </day>
- <day>
  <id>6</id>
  <code />
  <day_num />
  </day>
- <day>
  <id>7</id>
  <code>H</code>
  <day_num>1</day_num>
  </day>
  </week>
- <week>
  <week_num>2</week_num>
- <day>
  <id>1</id>
  <code>M</code>
  <day_num>2</day_num>
  </day>
- <day>
  <id>2</id>
  <code>N</code>
  <day_num>3</day_num>
  </day>
- <day>
  <id>3</id>
  <code>N</code>
  <day_num>4</day_num>
  </day>
- <day>
  <id>4</id>
  <code>N</code>
  <day_num>5</day_num>

If you see in the above XML it was generated from an Excel where there was a calendar ....and for symmetry every month had 6 weeks and 7 days and when XML got generated some days_num fields are empty......so when the parser goes through that its just not happy.........

I'm trying to find the code ....where there is empty and related to the day_num from that I have to form the day and store in the Dbase.....

Thanks,
Harsimrat

 

by: slightwvPosted on 2005-10-24 at 08:56:20ID: 15147563

What version or Oracle are you using?  Please include full version (i.e./ 9.2.0.4).

Now to help me clairify:  You are wanting all the populated days in the week (day_num not null) for each week in the month for each month of the year.  You then want to populate a database table with a structure similar to:

crew
year
week_num
day_num
id
code

 

by: hthukralPosted on 2005-10-24 at 09:18:13ID: 15147763

The Version is : 9.2.0.1


Yes Correct....The thing is basically I'm looking for the days they are not working......and maybe ...As the day not working the code will be empty..I need to capture that and replace with (o) and store in Dbase.....

Crew :
Date: when they are not working
and code will be (o)

And this is all read from a file and this is only year by year...........its pretty complicated for me...

Thanks a ton...

Harsimrat

 

by: slightwvPosted on 2005-10-24 at 10:29:07ID: 15148272

First:  Get on at least 9.2.0.4 or 9.2.0.6 ASAP!!!!!

9.2.0.1 is pretty unstable/slow espically with XML.  9.2.0.4 was a pretty major XML re-write from what Oracle tells me.

Now back to the question.  There are a couple of ways to do this.  You can use the DOM as you've already played with.  Until you get used to using the DOM it can be pretty confusing.  The other way is to use some of the XML SQL calls new in 9i.

I've created a test case that shoud be pretty close to what you need.  If it's missing anything that you can't figure out, just post back and I'll see what I can do.  This sample uses the SQL calls instead of the DOM.

Note #1:  The XML file must be located on the DB server itself for BFILE or UTL_FILE to work.
Note #2:  I developed this example on 10.2 (I don't have any 9i left).  It should work on 9i but I can't prove it.
--------------------------------------------------------------------

drop table tab1;
create table tab1(
      crew      varchar2(20),
      emp_date date,
      code      char(1)
)
/

drop directory xml_dir;
create directory xml_dir as 'c:\';


DECLARE

      v_bfile                   bfile := BFILENAME( 'XML_DIR' , 'cal_test.xml');
      v_lob                   clob;
      v_xml                   xmltype;

      src_offset  number := 1;
      dst_offset  number := 1;
      cs_id       number := NLS_CHARSET_ID('UTF8'); /* 998 */
      lang_ctx    number := dbms_lob.default_lang_ctx;
      warning     number;


      year            char(4);
      crew      varchar2(20);

BEGIN


            --create a place to load the file
            dbms_lob.createtemporary(v_lob,TRUE);
            dbms_lob.open(v_lob,DBMS_LOB.LOB_READWRITE);

            -- read the file off disk
            dbms_lob.fileopen(v_bfile, DBMS_LOB.FILE_READONLY);
            dbms_lob.loadclobfromfile(v_lob, v_bfile, DBMS_LOB.GETLENGTH(v_bfile), dst_offset, src_offset, cs_id, lang_ctx,warning);
            dbms_lob.close(v_bfile);

            --convert the clob to xmltype
            v_xml := xmltype(v_lob);

            --get rid of clob since we don't need it any more
            dbms_lob.freetemporary(v_lob);


            -- extractvalue needs to be used in select statement.  Oracle hasn't ported it to PL/SQL yet...
            select extractvalue(v_xml,'//sch/year') into year from dual;
            select extractvalue(v_xml,'//sch/cr') into crew from dual;


            -- get each month and XML fragment of days in month
            for i in ( select extract(column_value,'//name/text()').getstringval() month_name, extract(column_value,'//week/day') day_nodes from table( xmlsequence( extract( v_xml, '//sch/month' ))) ) loop
                  dbms_output.put_line('Month: ' || i.month_name);

                  -- get each days values
                  for j in ( select
                        extract(column_value,'//id/text()').getstringval() id,
                        extract(column_value,'//code/text()').getstringval() code,
                        extract(column_value,'//day_num/text()').getstringval() day_num
                  from table( xmlsequence( extract( i.day_nodes, '*' ))) ) loop

                        -- populate table
                        -- You could do this based on code just as easy
                        if j.day_num is not null then
                              insert into tab1 values( crew, to_date(i.month_name || ' ' || j.day_num || ' ' || year, 'Month DD YYYY'), j.code);
                        end if;

                  end loop;
                  commit;

            end loop;



END;
/

show errors


select * from tab1;

 

by: hthukralPosted on 2005-10-24 at 12:39:50ID: 15149227

This isnt happy here

ORA-22285: non-existent directory or file for FILEOPEN operation
ORA-06512: at "SYS.DBMS_LOB", line 504
ORA-06512: at "TRAINING.XML_TEST1", line 27
ORA-06512: at line 7

I put the file in the proper location If I use this funtion it works.....

pt_inputFile                        UTL_FILE.file_type;
      pt_outputFile                       UTL_FILE.file_type;
     
BEGIN
     
       pt_inputFile := utl_file.fopen('/opt/bin', 'RPC_A_2005.XML', 'r');

But unfortunately I dont know the way to change your example and make it work with this......

Sorry for asking such questions....

Thanks,
Harsimrat

 

by: slightwvPosted on 2005-10-24 at 12:42:57ID: 15149250

Give this a try.  replace the following lines in my previous example with:

create directory xml_dir as '/opt/bin';

     v_bfile                bfile := BFILENAME( 'XML_DIR' , 'RPC_A_2005.XML');



>>Sorry for asking such questions....

no need to apologize.  We all had to start somewhere.

 

by: hthukralPosted on 2005-10-24 at 12:45:21ID: 15149264

I put some watches on the Cariables :

v_bfile: /opt/bin/RPC_A_2005.XML, esists=F, length=o, open=F
v_lob: open=T, temp=T, length=o, chunksize=8132, data=<>

Hopefully some of this info helps.....

 

by: slightwvPosted on 2005-10-24 at 12:52:01ID: 15149312

>>Hopefully some of this info helps.....

sorry but not really.  I don't think I've ever done anything that produces that output.

Is it still failing after you made the changes from my last post?

 

by: hthukralPosted on 2005-10-24 at 13:00:17ID: 15149380

Your last post gives me there errors

ORA-22285: non-existent directory or file for FILEOPEN operation
ORA-06512: at "SYS.DBMS_LOB", line 504
ORA-06512: at "TRAINING.XML_TEST1", line 27
ORA-06512: at line 7

I dont know how to make it work......
 
 

 

by: slightwvPosted on 2005-10-24 at 13:22:09ID: 15149560

By chance, are you making this code a stored procedure?

I had all the code I posted in a single sql script file and executed the stand alone file.  Give that a try.

 

by: hthukralPosted on 2005-10-24 at 13:32:37ID: 15149656

Same thing when I do that in a single sql script...

 ORA-22285: non-existent directory or file for FILEOPEN operation ORA-06512: at "SYS.DBMS_LOB", line 504 ORA-06512: at line 25

Do you know how can I open the file with (UTL_FILE) I have no clue how to change ur code to work with UTL......

Let me know...

Thanks,
Harsimrat

 

by: slightwvPosted on 2005-10-25 at 05:54:07ID: 15153747

I've really never used UTL_FILE because of its limitations and don't have a DB available that I can set up to create a working test case.

You should be able to take the code from your original post that loops through GET_LINE and replace the 3 lines from my post below the comment  "-- read the file off disk".  You will probably also need to replace the CLOB variable with your varchar2(32767).

As long as you don't have an XML file greater than 32K you'll be fine.

For maximum flexibility I would probably keep using CLOB.  Using UTL_FILE you will need to read a line and use DBMS_LOD.WRITEAPPEND to keep appending to the lob.

If you're willing, I'd suggest working through the issues we're having with LOADCLOBFROMFILE.  I feel it is the cleanest method.

If you want to continue working with my script, read on:
I'm not on UNIX any longer so we'll have to do some troubleshooting.  Copy the file to /tmp and open the permissions up on it (777).  Then change the create directory statement to point to /tmp.  Also make sure the case of the file name matches exactly.  

If that fails, change the owner and group of the file to oracle and dba and try again.

Let me know.

 

by: hthukralPosted on 2005-10-25 at 08:27:01ID: 15155106

Hello,

I got the FILEOPEN working using your method, I was not creating Directory.....now its going into the loop and just exiting.........

 for i in ( select extract(column_value,'//name/text()'

after this directly to end.......

Trying to figure out....Let me know if you have any suggestions.....

I really appreciate your help.....will give you points by the end of the day....hopefully this works.....

Thanks,
Harsimrat

 

by: hthukralPosted on 2005-10-25 at 08:42:39ID: 15155265

Sorry, my mistake it works awesome....

Really appreciate for the help......

Thanks,
Harsimrat

 

by: slightwvPosted on 2005-10-25 at 09:24:07ID: 15155729

Glad to help.  More glad it works!!!

20120131-EE-VQP-002

3 Ways to Join

30-Day Free Trial

The Experts

98% positive feedback on 31,087 answers since March 2000. angeliii is a Microsoft Most Valuable Professional for his work with MS SQL Server & Develoment.

He has also proven his knowledge of Visual Basic Programming, PHP Scripting and Oracle Databases.

The Experts

97% positive feedback on 10,752 answers since July 2000. lrmoore has more than 18 years experience in the networking industry.

The six-time Mircosoft MVPs specialties include firewalls, virtual private networking, and network management.

Testimonials

"...and excellent source for support... Kind of like having your very own IT dept." Electriciansnet

Testimonials

"I was apprehensive at signing up at first. However... it has already made my life as an IT administrator much easier." JaCrews

Testimonials

"WOW! You guys have great, active, and knowledgeable people on here." moore50

Business Clients

Business Clients

In the Press

"If you’ve got a question... Experts Exchange can supply an answer.”

In the Press

"...an invaluable aid for both IT professionals and those who require tech support."

In the Press

"where IT professionals provide quick answers on just about any topic"

Business Account Plans

Loading Advertisement...