Précédent   Forum des professionnels en informatique > Bases de données > Oracle > PL/SQL
PL/SQL Forum d'entraide sur le PL/SQL
Partagez cette discussion sur d'autres réseaux sociaux : Viadeo Twitter Google Facebook Digg Delicious MySpace Yahoo
Réponse Proposer ce sujet en actualité
 
Outils de la discussion
Publicité
Vieux 03/02/2005, 16h58   #1
Invité de passage
 
Inscription : février 2005
Messages : 3
Détails du profil
Informations forums :
Inscription : février 2005
Messages : 3
Points : 1
Points : 1
Par défaut Chargement d'un XML en tables avec PL/SQL

Bonjour à tous,

Quelqu'un aurait-il un source PL/SQL réalisant un chargement de tables objets Oracle, via les procs du package DBMS_XMLSAVE, à partir d'un fichier XML déjà chargé dans un CLOB ?

Vous me seriez d'une aide trés précieuse .
jenlin est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 03/02/2005, 17h01   #2
Rédacteur/Modérateur
 
Avatar de orafrance
 
Inscription : janvier 2004
Messages : 15 861
Détails du profil
Informations personnelles :
Âge : 34

Informations forums :
Inscription : janvier 2004
Messages : 15 861
Points : 16 196
Points : 16 196


http://www.developpez.net/forums/viewtopic.php?t=76270&highlight=dbmsxmlsave
orafrance est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 03/02/2005, 17h21   #3
Invité de passage
 
Inscription : février 2005
Messages : 3
Détails du profil
Informations forums :
Inscription : février 2005
Messages : 3
Points : 1
Points : 1
Cette réponse utilise les procs du package DBMS_XMLQUERY (dans le sens Oracle vers XML).
Je souhaite plutot avoir des exemples de scripts PL/SQL pour charger des tables oracle avec un fichier XML .

Merci.
jenlin est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 03/02/2005, 17h29   #4
Expert Confirmé
 
Homme
Chef de projet en SSII
Inscription : janvier 2004
Messages : 2 866
Détails du profil
Informations personnelles :
Sexe : Homme
Localisation : France, Loire Atlantique (Pays de la Loire)

Informations professionnelles :
Activité : Chef de projet en SSII
Secteur : Conseil

Informations forums :
Inscription : janvier 2004
Messages : 2 866
Points : 3 448
Points : 3 448
Il me semble que ce lien pourra t'intéresser :
http://asktom.oracle.com/pls/ask/f?p=4950:8:4407922884164842212::NO::F4950_P8_DISPLAYID,F4950_P8_CRITERIA:2853285548502
__________________
Un problème sans solution est un problème mal posé

Merci de poser vos questions sur le forum, je ne réponds pas aux questions posées par MP.
plaineR est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 03/02/2005, 17h46   #5
Expert Confirmé
 
Homme
Chef de projet en SSII
Inscription : janvier 2004
Messages : 2 866
Détails du profil
Informations personnelles :
Sexe : Homme
Localisation : France, Loire Atlantique (Pays de la Loire)

Informations professionnelles :
Activité : Chef de projet en SSII
Secteur : Conseil

Informations forums :
Inscription : janvier 2004
Messages : 2 866
Points : 3 448
Points : 3 448
Voici également un exemple trouvé sur le metalink pour insérer mettre à jour et supprimer des données :
Citation:
PURPOSE
-------
The purpose of this document is to provide a very simple example (from start to
finish) on how to insert, update and delete rows into Oracle database using XML
parser for PL/SQL

SCOPE & APPLICATION
-------------------
This document is not intended to teach XML. The purpose of this document is
to provide a working example of how you use some of the features of the Oracle
XDK.
How to DML XML rows into the database using XSU?

1.-Create the table
Code :
1
2
3
4
CREATE TABLE empleados (empid NUMBER PRIMARY KEY, 
empname VARCHAR2(30), 
empjob VARCHAR2(30), 
empsal NUMBER);
2.-Create a procedure to insert rows into this table using XSU.
-- This procedure is generic for all tables
-- You can insert using this procedure in any table
-- xmlDoc can be VARCHAR2 or CLOB
Code :
1
2
3
4
5
6
7
8
9
10
CREATE OR REPLACE procedure InsertXML(xmlDoc IN VARCHAR2, 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_output.put_line(to_char(rows) || ' rows inserted'); 
DBMS_XMLSave.closeContext(insCtx); -- this closes the handle 
end; 
/
3.-Execute the procedure to insert
Assuming thet we have this XML document...
<?xml version="1.0"?>
<ROWSET>
<ROW num="1">
<EMPID>10</EMPID>
<EMPNAME>Perry Smith</EMPNAME>
<EMPJOB>Manager</EMPJOB>
<EMPSAL>800</EMPSAL>
</ROW>
<ROW num="1">
<EMPID>20</EMPID>
<EMPNAME>John Calvach</EMPNAME>
<EMPJOB>Principal Support Consultant</EMPJOB>
<EMPSAL>900</EMPSAL>
</ROW>
<ROW num="1">
<EMPID>30</EMPID>
<EMPNAME>Louis Bald</EMPNAME>
<EMPJOB>Technical Specialist</EMPJOB>
<EMPSAL>400</EMPSAL>
</ROW>
<ROW num="1">
<EMPID>40</EMPID>
<EMPNAME>Anthony Flowers</EMPNAME>
<EMPJOB>Technical Team Leader</EMPJOB>
<EMPSAL>500</EMPSAL>
</ROW>
<ROW num="1">
<EMPID>50</EMPID>
<EMPNAME>George Monk</EMPNAME>
<EMPJOB>Support Consultant</EMPJOB>
<EMPSAL>200</EMPSAL>
</ROW>
</ROWSET>

... we can execute the procedure like this:
Code :
1
2
3
4
5
6
SQL> exec InsertXML('<?xml version="1.0"?><ROWSET><ROW num="1"><EMPID>10</EMPID><EMPNAME>Perry Smith</EMPNAME><EMPJOB>Manager</EMPJOB><EMPSAL>800</EMPSAL></ROW><ROW 
num="1"><EMPID>20</EMPID><EMPNAME>John Calvach</EMPNAME><EMPJOB>Principal Support Consultant</EMPJOB><EMPSAL>900</EMPSAL></ROW><ROW 
num="1"><EMPID>30</EMPID><EMPNAME>Louis Bald</EMPNAME><EMPJOB>Technical Specialist</EMPJOB><EMPSAL>400</EMPSAL></ROW><ROW num="1"><EMPID>40</EMPID><EMPNAME>Anthony 
Flowers</EMPNAME><EMPJOB>Technical Team Leader</EMPJOB><EMPSAL>500</EMPSAL></ROW><ROW num="1"><EMPID>50</EMPID><EMPNAME>George Monk</EMPNAME><EMPJOB>Support Consultant</EMPJOB><EMPSAL>200</EMPSAL></ROW></ROWSET>','empleados'); 
5 rows inserted 
PL/SQL procedure successfully completed.
4.-Create a procedure to update rows into this table using XSU.
Code :
1
2
3
4
5
6
7
8
9
10
11
12
13
-- Like in insert procedure, xmlDoc can be VARVCHAR2 or CLOB 
CREATE OR REPLACE procedure UpdateEmpleados ( xmlDoc IN VARCHAR2) IS 
updCtx DBMS_XMLSave.ctxType; 
rows number; 
begin 
updCtx := DBMS_XMLSave.newContext('empleados'); -- get the context 
DBMS_XMLSave.clearUpdateColumnList(updCtx); -- clear the update settings.. 
DBMS_XMLSave.setKeyColumn(updCtx,'EMPID'); -- set EMPNO as key column 
rows := DBMS_XMLSave.updateXML(updCtx,xmlDoc); -- update the table. 
dbms_output.put_line(to_char(rows) || ' rows updated'); 
DBMS_XMLSave.closeContext(updCtx); -- close the context..! 
end; 
/
5.-Execute the procedure to update rows...
Assuming thet we have this XML document...
<?xml version="1.0"?>
<ROWSET>
<ROW num="1">
<EMPID>10</EMPID>
<EMPNAME>Perry Smith Johnson</EMPNAME>
</ROW>
<ROW num="1">
<EMPID>20</EMPID>
<EMPJOB>Principal Support Consultant I</EMPJOB>
<EMPSAL>700</EMPSAL>
</ROW>
<ROW num="1">
<EMPID>30</EMPID>
<EMPSAL>700</EMPSAL>
</ROW>
</ROWSET>

... we can execute the procedure like this:
Code :
1
2
3
4
SQL> exec UpdateEmpleados('<?xml version="1.0"?><ROWSET><ROW num="1"><EMPID>10</EMPID><EMPNAME>Perry Smith Johnson</EMPNAME></ROW><ROW 
num="1"><EMPID>20</EMPID><EMPJOB>Principal Support Consultant I</EMPJOB><EMPSAL>700</EMPSAL></ROW><ROW num="1"><EMPID>30</EMPID><EMPSAL>700</EMPSAL></ROW></ROWSET>'); 
3 rows updated 
PL/SQL procedure successfully completed.
6.-Create a procedure to delete rows into this table using XSU.
Code :
1
2
3
4
5
6
7
8
9
10
11
12
-- Like in above examples xmlDoc can be VARCHAR2 or CLOB 
CREATE OR REPLACE procedure DeleteEmpleados(xmlDoc IN VARCHAR2) IS 
delCtx DBMS_XMLSave.ctxType; 
rows number; 
begin 
delCtx := DBMS_XMLSave.newContext('empleados'); 
DBMS_XMLSave.setKeyColumn(delCtx,'EMPID'); 
rows := DBMS_XMLSave.deleteXML(delCtx,xmlDoc); 
dbms_output.put_line(to_char(rows) || ' rows deleted'); 
DBMS_XMLSave.closeContext(delCtx); 
end; 
/
Assuming thet we have this XML document...
<?xml version="1.0"?>
<ROWSET>
<ROW num="1">
<EMPID>50</EMPID>
</ROW>
</ROWSET>
... we can execute the procedure like this:
Code :
1
2
3
SQL> exec DeleteEmpleados('<?xml version="1.0"?><ROWSET><ROW num="1"><EMPID>50</EMPID></ROW></ROWSET>'); 
1 rows deleted 
PL/SQL procedure successfully completed.
__________________
Un problème sans solution est un problème mal posé

Merci de poser vos questions sur le forum, je ne réponds pas aux questions posées par MP.
plaineR est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 03/02/2005, 18h02   #6
Invité de passage
 
Inscription : février 2005
Messages : 3
Détails du profil
Informations forums :
Inscription : février 2005
Messages : 3
Points : 1
Points : 1
Des réponses bien appréciables dans des situations de crises (nerveuses)

Merci bien.



La seule question idiote est la question qu'on ne pose pas !
jenlin est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 03/02/2005, 18h07   #7
Expert Confirmé
 
Homme
Chef de projet en SSII
Inscription : janvier 2004
Messages : 2 866
Détails du profil
Informations personnelles :
Sexe : Homme
Localisation : France, Loire Atlantique (Pays de la Loire)

Informations professionnelles :
Activité : Chef de projet en SSII
Secteur : Conseil

Informations forums :
Inscription : janvier 2004
Messages : 2 866
Points : 3 448
Points : 3 448
Si cela résoud ton problème, n'oublie pas le bouton résolu
__________________
Un problème sans solution est un problème mal posé

Merci de poser vos questions sur le forum, je ne réponds pas aux questions posées par MP.
plaineR est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 21/03/2011, 12h55   #8
Invité de passage
 
Inscription : décembre 2006
Messages : 9
Détails du profil
Informations forums :
Inscription : décembre 2006
Messages : 9
Points : 2
Points : 2
Concernant le sujet "Chargement d'un XML en tables avec PL/SQL", j'ai essayer de réutiliser les exemples sités ci-dessus :

1-Les procédures 'InsertXML', 'UpdateEmpleados ' et 'DeleteEmpleados' sont bien créées, mais lorsque je fais un appel :

Code :
exec InsertXML('<?xml version="1.0"?><ROWSET><ROW num="1"><EMPID>10</EMPID><EMPNAME>Perry Smith</EMPNAME><EMPJOB>Manager</EMPJOB><EMPSAL>800</EMPSAL></ROW><ROW num="1"><EMPID>20</EMPID><EMPNAME>John Calvach</EMPNAME><EMPJOB>Principal Support Consultant</EMPJOB><EMPSAL>900</EMPSAL></ROW><ROW num="1"><EMPID>30</EMPID><EMPNAME>Louis Bald</EMPNAME><EMPJOB>Technical Specialist</EMPJOB><EMPSAL>400</EMPSAL></ROW><ROW num="1"><EMPID>40</EMPID><EMPNAME>Anthony Flowers</EMPNAME><EMPJOB>Technical Team Leader</EMPJOB><EMPSAL>500</EMPSAL></ROW><ROW num="1"><EMPID>50</EMPID><EMPNAME>George Monk</EMPNAME><EMPJOB>Support Consultant</EMPJOB><EMPSAL>200</EMPSAL></ROW></ROWSET>','empleados');
j'ai les erreurs suivantes :

Code :
1
2
3
4
5
6
7
 
ERREUR à la ligne 1 :
ORA-29532: appel Java arrêté par une exception Java non interceptée :
java.lang.ExceptionInInitializerError
ORA-06512: à "SYS.DBMS_XMLSAVE", ligne 111
ORA-06512: à "AXEL.INSERTXML", ligne 6
ORA-06512: à ligne 1
azazil est déconnecté   Envoyer un message privé Réponse avec citation 00
Réponse Proposer ce sujet en actualité Cette discussion est résolue.
Outils de la discussion



Fuseau horaire GMT +1. Il est actuellement 07h36.


 
 
 
 
Partenaires

Hébergement Web