简体   繁体   中英

Inserting XML data into Oracle table

I have a table that contains XML of HUGECLOB data type, I need to extract CLOB data as XML and get some specific XML tag value to insert it into another table.

I used dbms_lob to get XML and the following is my code to insert XML into another table.

create or replace procedure xml_into_table(l_xml in xmltype)
as
begin
insert into emp( EMPNO,ENAME,JOB,MGR,HIREDATE,SAL,COMM,DEPT) 
SELECT * FROM xmltable('employees' passing l_xml
                                columns EMPNO NUMBER PATH ' /employee/empno',
                                        ENAME VARCHAR2 PATH '/employee/ename',
                                        JOB VARCHAR2 PATH '/employee/job',
                                        HIREDATE DATE PATH '/employee/hiredate');
                                      END;
                                      /

Error(7,56): PL/SQL: ORA-00906: missing left parenthesis.

Can some one please guide me, what is the right way for achieving this.

The VARCHAR2 data type needs a size and you are missing the columns MGR , SAL , COMM and DEPT so SELECT * will only get 4 columns and not the 8 you have named in the INSERT .

create or replace procedure xml_into_table(l_xml in xmltype)
as
begin
insert into emp( EMPNO,ENAME,JOB,MGR,HIREDATE,SAL,COMM,DEPT) 
SELECT empno,
       ename,
       job,
       NULL,
       hiredate,
       NULL,
       NULL,
       NULL
FROM   xmltable(
         'employees'
         passing l_xml
         columns
           EMPNO    NUMBER        PATH ' /employee/empno',
           ENAME    VARCHAR2(200) PATH '/employee/ename',
           JOB      VARCHAR2(200) PATH '/employee/job',
           HIREDATE DATE          PATH '/employee/hiredate'
       );
END;
/

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM