Home » SQL & PL/SQL » SQL & PL/SQL » XMLTYPE procedure (oracle 11g)
XMLTYPE procedure [message #626611] Thu, 30 October 2014 00:29 Go to next message
alagpereira
Messages: 5
Registered: October 2014
Location: Vasai
Junior Member
I want to extract data from xml and transfer that data to the database table. For that i wrote a procedure (below) but it got compiled with errors. please help.
CREATE OR REPLACE PROCEDURE PerXML
IS
INSERT INTO Personal VALUES (XMLTYPE('<?xml version="1.0" encoding="UTF-8"?>
<Personal>
 <contacts>
<contact>
<name>alag</name>
 <phone>12345</phone>
 <address>Vasai</address>
 </contact>
 <contact>
<name>JINESH</name>
 <phone>42346</phone>
 <address>Andheri</address>
 </contact>
</contacts>
</Personal>
'));
CURSOR  XML_cur IS SELECT * FROM Personal;
XML_rec XML_cur%ROWTYPE;
BEGIN
FOR XML_cur IN XML_rec
LOOP 
INSERT INTO PersonalOut (name,phone,address)
 SELECT xt.*from Personal Pers,
XMLTable('/Personal/contacts/contact'
                  PASSING Pers.per
                  COLUMNS
                  name varchar2(10)        path 'name',
                  phone        number(10)        path 'phone',
                  address varchar2(500) path 'address') xt; 
END LOOP;
END;

TABLES: PERSONAL (per XMLTYPE)
PERSONALOUT (NAME VARCHAR2, PHONE NUMBER, ADDRESS VARCHAR2)

what should be the changes?



[Edit MC: add code tags]

[Updated on: Thu, 30 October 2014 01:50] by Moderator

Report message to a moderator

Re: XMLTYPE procedure [message #626613 is a reply to message #626611] Thu, 30 October 2014 00:58 Go to previous messageGo to next message
Michel Cadot
Messages: 68645
Registered: March 2007
Location: Nanterre, France, http://...
Senior Member
Account Moderator

Welcome to the forum.
Please read OraFAQ Forum Guide and How to use [code] tags and make your code easier to read.

Use SQL*Plus and copy and paste your session, the WHOLE session.

If you post the CREATE TABLE statements for your table we can test your code.

For the moment, as you posted neither your errors nor your SQL*Plus session nor the CREATE TABLE statements we can do nothing for you.

[Updated on: Thu, 30 October 2014 00:58]

Report message to a moderator

Re: XMLTYPE procedure [message #626615 is a reply to message #626613] Thu, 30 October 2014 01:01 Go to previous messageGo to next message
alagpereira
Messages: 5
Registered: October 2014
Location: Vasai
Junior Member
SQL> CREATE OR REPLACE PROCEDURE PerXML
  2  IS
  3  INSERT INTO Personal VALUES (XMLTYPE('<?xml version="1.0" encoding="UTF-8"?
>
  4  <Personal>
  5   <contacts>
  6  <contact>
  7  <name>alag</name>
  8   <phone>12345</phone>
  9   <address>Vasai</address>
 10   </contact>
 11   <contact>
 12  <name>JINESH</name>
 13   <phone>42346</phone>
 14   <address>Andheri</address>
 15   </contact>
 16  </contacts>
 17  </Personal>
 18  '));
 19  CURSOR  XML_cur IS SELECT * FROM Personal;
 20  XML_rec XML_cur%ROWTYPE;
 21  BEGIN
 22  FOR XML_cur IN XML_rec
 23  LOOP
 24  INSERT INTO PersonalOut (name,phone,address)
 25   SELECT xt.*from Personal Pers,
 26  XMLTable('/Personal/contacts/contact'
 27                    PASSING Pers.per
 28                    COLUMNS
 29                    name varchar2(10)        path 'name',
 30                    phone        number(10)        path 'phone',
 31                    address varchar2(500) path 'address') xt;
 32  END LOOP;
 33  END;
 34  /

Warning: Procedure created with compilation errors.


SQL> execute PerXML;
BEGIN PerXML; END;

      *
ERROR at line 1:
ORA-06550: line 1, column 7:
PLS-00905: object ALAG.PERXML is invalid
ORA-06550: line 1, column 7:
PL/SQL: Statement ignored

tables:

create table Personal(per XMLTYPE);

create table PersonalOut(name varchar2(10), phone Number(10), address varchar2(500));



[Edit MC: add code tags]

[Updated on: Thu, 30 October 2014 01:50] by Moderator

Report message to a moderator

Re: XMLTYPE procedure [message #626616 is a reply to message #626615] Thu, 30 October 2014 01:07 Go to previous messageGo to next message
Michel Cadot
Messages: 68645
Registered: March 2007
Location: Nanterre, France, http://...
Senior Member
Account Moderator

Please read OraFAQ Forum Guide and How to use [code] tags and make your code easier to read.

Use SHOW ERROR after CREATE PROCEDURE there we have not the errors at compilation time.

[Updated on: Thu, 30 October 2014 01:08]

Report message to a moderator

Re: XMLTYPE procedure [message #626618 is a reply to message #626616] Thu, 30 October 2014 01:16 Go to previous messageGo to next message
alagpereira
Messages: 5
Registered: October 2014
Location: Vasai
Junior Member
im getting this.

SQL> show errors
Errors for PROCEDURE PERXML:

LINE/COL ERROR
-------- -----------------------------------------------------------------
3/1      PLS-00103: Encountered the symbol "INSERT" when expecting one of
         the following:
         begin function pragma procedure subtype type <an identifier>
         <a double-quoted delimited-identifier> current cursor delete
         exists prior external language
         The symbol "begin" was substituted for "INSERT" to continue.

19/9     PLS-00103: Encountered the symbol "XML_CUR" when expecting one of
         the following:
         := . ( @ % ;

SQL>

is the code working for you?



[Edit MC: add code tags]

[Updated on: Thu, 30 October 2014 01:55] by Moderator

Report message to a moderator

Re: XMLTYPE procedure [message #626623 is a reply to message #626618] Thu, 30 October 2014 01:54 Go to previous messageGo to next message
Michel Cadot
Messages: 68645
Registered: March 2007
Location: Nanterre, France, http://...
Senior Member
Account Moderator

Please read OraFAQ Forum Guide and How to use [code] tags and make your code easier to read.

See how code tags I added to your posts improve the readability. Please help us to help you in all ways.

Line 3: INSERT should be after BEGIN in the code section not in the declaration section.

Re: XMLTYPE procedure [message #626629 is a reply to message #626623] Thu, 30 October 2014 02:37 Go to previous messageGo to next message
alagpereira
Messages: 5
Registered: October 2014
Location: Vasai
Junior Member
it works after that??
Re: XMLTYPE procedure [message #626631 is a reply to message #626629] Thu, 30 October 2014 02:41 Go to previous messageGo to next message
Michel Cadot
Messages: 68645
Registered: March 2007
Location: Nanterre, France, http://...
Senior Member
Account Moderator

I don't know, try it, is this not your job?
In addition, what does "work" mean? Compile? maybe. Do what you want it does? we don't know what your procedure intends to do.

Re: XMLTYPE procedure [message #626639 is a reply to message #626631] Thu, 30 October 2014 03:34 Go to previous messageGo to next message
alagpereira
Messages: 5
Registered: October 2014
Location: Vasai
Junior Member
its working now. thank u. there were 2 mistakes. first the 'insert' in the declaration section and then in the 'for' statement i wrote cursor in record instead of record in cursor.
silly errors but nonetheless thank u for your help.
Re: XMLTYPE procedure [message #626641 is a reply to message #626639] Thu, 30 October 2014 03:47 Go to previous message
Michel Cadot
Messages: 68645
Registered: March 2007
Location: Nanterre, France, http://...
Senior Member
Account Moderator

Thanks to let us know.
Previous Topic: Error about Oracle External Table
Next Topic: Oracle GTT vs SQL Temporary Table
Goto Forum:
  


Current Time: Thu Apr 25 14:23:59 CDT 2024