0

I'm a begginer and I trying to write a Python script that will go through Rows and put them into my database

This is a structure of my xml:

Root>
    -<SvcNf>
        -<PersonNf>
            -<PersonList>
                -<Row>
                    <SysName>MI6</SysName>
                    <ServerDt>2016-10-28 03:00:12 +03:00</ServerDt>
                    <UID>9457A55E17341AA7ASDEDS057A8BFFF3</UID>
                    <PersID>007</PersID>
                    <Emp_name>James Bond</Emp_name>
                    <EventID>25</EventID>
                    <EventTXT>Drinking alcohol</EventTXT>
                    <CauseEventID>03</CauseEventID>
                    <CauseEventTXT>Martini with vodka</CauseEventTXT>
                    <EventBegda>2017-10-18</EventBegda>
                    <EventEndda>2017-10-18</EventEndda>
                    <AccrualsSum>171.0</AccrualsSum>
                    <AccrualsProz>0.0</AccrualsProz>
                    <AccrualsName>Chinees_</AccrualsName>
                    <OrderNum>P-336</OrderNum>
                    <Perg>0</Persg>
                    <Perk>15</Persk>
                    <Awart/>
                </Row>
                -<Row>
                    .....
                </Row>
                <Row/>
            </PersonList>
        </PersonNf>
    </SvcNf>
</Root>

So, when i use this code to Parse XML:

# PARSE XML FILE
sql = """   
DECLARE
    xml_value varchar2(32767);
BEGIN
    xml_value := :i_param;
INSERT INTO HR.EVENTS_TST (PersID, Emp_name, EventID, EventTXT...etc.)
    SELECT 
        e.PersID
        ,e.Emp_name
        ,e.EventID
        ,e.EventTXT
        ....
    FROM XMLTABLE('/Root/SvcNf/PersonNf/PersonList/Row' 
    PASSING XMLTYPE(xml_value)
    COLUMNS 
        ServerDt VARCHAR2(512) PATH 'ServerDt',
        PersID VARCHAR2(512) PATH 'PersID ',
        Emp_name VARCHAR2(512) PATH 'Emp_name ',
        EventID VARCHAR2(512) PATH 'EventID',
        EventTXT VARCHAR2(512) PATH 'EventTXT',
        .....) AS e;
commit;
END;"""          
xmlstr = ET.tostring(doc.getroot(), 'unicode')
ora_cursor.execute(sql, {'i_param':xmlstr})

So, after that i have Oracle errors ORA-06502: PL/SQL: numeric or value error ORA-06512: at line 5 (xml_value := :i_param;)

4
  • Posting the table column types and the Python code would be helpful. Commented Nov 10, 2017 at 1:32
  • Also, the length of the xmlstr would be useful as well. Commented Nov 10, 2017 at 2:35
  • all columns like in xml with VARCHAR2(512) type Commented Nov 10, 2017 at 8:54
  • i had another answer but i cant understand this mistakes Commented Nov 10, 2017 at 8:55

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.