Need help on Db2 Stored procedures

Hi ,

Iam new to Db2 , I need help in writing an stored procedure that accepts an xml file and read the xml file and insert into DB table called Account

<?xml version="1.0" encoding="UTF-8"?>

DB table : Account

Name varchar
Age Integer
Gender char

Any help is really appreciated as Iam not aware of DB2 .
Who is Participating?
Kent OlsenData Warehouse Architect / DBACommented:
If it was my application, I'd write one something like this:

CREATE PROCEDURE load_xml_file (IN in_filename VARCHAR(255))
SET cmd = 'LOAD FROM {testfile} of del XMS from ' || in_filename ||
  ' INSERT INTO {xml_table}';

Open in new window

Substitute your values for {testfile} and {xml_table}.

Also note that stored procedures run on the server, NOT the client machine.  The file must be accessible by the server.

Kent OlsenData Warehouse Architect / DBACommented:
Hi Sam,

You can parse the XML and manage the logic yourself or you can use the DB2 utilities to load the data into an appropriate table for you.  The easiest way to get an XML document (file) into DB2 is with the LOAD or IMPORT function.  (They are both part of the db2 command line processor.)

You should be able to execute the LOAD or IMPORT by calling SYSPROC.ADMIN_CMD.

Good Luck,
sam_2012Author Commented:
Hi kent,

I have been asked to do it using the xml functions available in Db2  and also they want me to write an procedure  instead of load or import utility as this will be called from an application.
Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Kent OlsenData Warehouse Architect / DBACommented:
Hi Sam,

The IBM documentation on handling XML in DB2 is quite lengthy.  Probably more than you care to read in a week.  So I suggest you start smaller and review this page:

It briefly explains a lot of what you can do in XML and is much more concise than anything that I can write up in just a few minutes.  Please review that page and get back to me.  We'll see where to go next.

sam_2012Author Commented:
that link was good example on XML. But iam too sure how to code using Db2 stored procedure , any example of an stored procedure to read the xml file and insert into table will be really useful.
sam_2012Author Commented:
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.