Skip to Main Content

SQL & PL/SQL

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Interested in getting your voice heard by members of the Developer Marketing team at Oracle? Check out this post for AppDev or this post for AI focus group information.

How to generate XPath string from XML file

New RootsAug 18 2016 — edited Aug 23 2016

Hi,

   Below is my XML format:

<project>

    <projectNumber>311927</projectNumber>

    <projectType>BUILD</projectType>

    <lineOfBusiness>COMMERCIAL</lineOfBusiness>

    <projectStatus>PROGRASS</projectStatus>

    <summary>

      <creationDate>08/02/2016</creationDate>

      <workflowStateDate></workflowStateDate>

      <effectiveDate>01/01/2014</effectiveDate>

      <clientRequested>FALSE</clientRequested>

      <mandatoryReview>FALSE</mandatoryReview>

      <internalProject>FALSE</internalProject>

      <clientType>Permanent</clientType>

      <description>Test Data 2</description>

      <appliesTo>

        <Retail>TRUE</Retail>

        <Mail>TRUE</Mail>

      </appliesTo>

    </summary>

</project>   

I'm loading above xml in one oracle configuration table  and querying by using below query. As of now I'm passing "XPath_string" manually.

Is there any way to generate "XPath_string" from xml file by using any inbuilt oracle function?  That function should read my xml and should produce xpath string for each tag value.

Eg output : 

Tagvalue:                                   Xpath

lineOfBusiness                        /project[1]/lineOfBusiness/text()

SELECT *

FROM

  (SELECT 1924901                                                                     AS "KEY_IND_1" ,

    1924801                                                                           AS "KEY_IND_2" ,

    EXTRACTVALUE(VALUE(P),'/project[1]/lineOfBusiness/text()', 'xmlns:"RXCONSTRUCT"') AS "KEY_IND_3" ,

    EXTRACTVALUE(VALUE(P),'/project[1]/projectNumber/text()', 'xmlns:"RXCONSTRUCT"')  AS "KEY_IND_4" ,

    EXTRACTVALUE(VALUE(P),'/project[1]/projectStatus/text()', 'xmlns:"RXCONSTRUCT"')  AS "KEY_IND_5" ,

    EXTRACTVALUE(VALUE(P),'/project[1]/projectType/text()', 'xmlns:"RXCONSTRUCT"')    AS "KEY_IND_6"

  FROM TABLE (XMLSEQUENCE(

    (SELECT NVL(xml_clob,'') FROM input_files WHERE extract_level = 1

    ) )) P

  )

WHERE key_ind_1 IS NOT NULL

AND key_ind_2   IS NOT NULL

AND key_ind_3   IS NOT NULL

AND key_ind_4   IS NOT NULL

AND key_ind_5   IS NOT NULL

AND key_ind_6   IS NOT NULL;

SELECT *

FROM

  (SELECT 1925001 AS "KEY_IND_1" ,

    (SELECT MAX(project_id)

    FROM XML_USER.project

    WHERE file_seq_id = 1924801

    )                                                                                    AS "KEY_IND_2" ,

    1924801                                                                              AS "KEY_IND_3" ,

    EXTRACTVALUE(VALUE(P),'/summary[1]/clientRequested/text()', 'xmlns:"RXCONSTRUCT"')   AS "KEY_IND_4" ,

    EXTRACTVALUE(VALUE(P),'/summary[1]/clientType/text()', 'xmlns:"RXCONSTRUCT"')        AS "KEY_IND_5" ,

    EXTRACTVALUE(VALUE(P),'/summary[1]/creationDate/text()', 'xmlns:"RXCONSTRUCT"')      AS "KEY_IND_6" ,

    EXTRACTVALUE(VALUE(P),'/summary[1]/description/text()', 'xmlns:"RXCONSTRUCT"')       AS "KEY_IND_7" ,

    EXTRACTVALUE(VALUE(P),'/summary[1]/effectiveDate/text()', 'xmlns:"RXCONSTRUCT"')     AS "KEY_IND_8" ,

    EXTRACTVALUE(VALUE(P),'/summary[1]/internalProject/text()', 'xmlns:"RXCONSTRUCT"')   AS "KEY_IND_9" ,

    EXTRACTVALUE(VALUE(P),'/summary[1]/mandatoryReview/text()', 'xmlns:"RXCONSTRUCT"')   AS "KEY_IND_10" ,

    EXTRACTVALUE(VALUE(P),'/summary[1]/workflowStateDate/text()', 'xmlns:"RXCONSTRUCT"') AS "KEY_IND_11" ,

    EXTRACTVALUE(VALUE(P),'/summary[1]/appliesTo/Retail/text()', 'xmlns:"RXCONSTRUCT"')  AS "KEY_IND_12" ,

    EXTRACTVALUE(VALUE(P),'/summary[1]/appliesTo/Mail/text()', 'xmlns:"RXCONSTRUCT"')    AS "KEY_IND_13"

  FROM TABLE (XMLSEQUENCE(

    (SELECT NVL(xml_clob,'') FROM input_files WHERE extract_level = 1

    ) )) P

  )

WHERE key_ind_1 IS NOT NULL

AND key_ind_2   IS NOT NULL

AND key_ind_3   IS NOT NULL

AND key_ind_4   IS NOT NULL

AND key_ind_5   IS NOT NULL

AND key_ind_6   IS NOT NULL

AND key_ind_7   IS NOT NULL

AND key_ind_8   IS NOT NULL

AND key_ind_9   IS NOT NULL

AND key_ind_10  IS NOT NULL

AND key_ind_11  IS NOT NULL

AND key_ind_12  IS NOT NULL

AND key_ind_13  IS NOT NULL;

Comments

Jasper Tanglib

Tried to clear browser's cache and tried to use another browser (Firefox). I does not work.

Jasper Tanglib

I am able to delete other files like
image.pngimage.png
But for some reason I cannot delete this specific file I uploaded named Process.zip, When I try to delete this rows, it would just hang or the page just freezes forever.
image.png
I am working with files called Process.zip and I have successfully uploaded and deleted this kind of file before. Just this day it decides to be freezing now.

jariola

I don't know what is issue with your browser. But you shouldn't directly update, insert or delete anything from APEX internal tables. That isn't supported.

Billy Verreynne

Do the DELETE statement - then find that session in v$session and look at its wait and event states.

Jasper Tanglib

@billy-verreynne , I found out about the term locks and this is very new to me and I think this is the cause of my issue. It's something like a session that's still running so I think I'll need to find out where that is and then kill it.
I remember I did execute a WHILE LOOP on those rows that will never exit the loop.
I have tried to query FROM v$session, or v$lock, or dba_objects but I'm only getting table or view does not exist.
image.pngCan you help how I could query this in Oracle Apex?

Billy Verreynne

Your Oracle schema needs select privs on the data dictionary.
Talk to your DBA about providing this grant, or to assist in determining the wait and events states of the problem session.
Wearing my DBA hat, I have no issues granting developers access to v$ virtual performance views in dev environments - it provides them with better insights into the technical workings of Oracle.

Jasper Tanglib

Would the query my DBA need to execute be this? grant select any dictionary to schema_name;

Billy Verreynne

Would the query my DBA need to execute be this? grant select any dictionary to schema_name;
Yes.

Jasper Tanglib

Thank you @billy-verreynne. I'll be trying this approach as it also seems to be the only solution I have seen through my extensive research on this today.

Jasper Tanglib
Answer

Just a reference for anyone reading this thread.
We were not sure how to specifically locate the locked rows and table and was taking much time so a workaround that my DBA did was restart the Autonomous database and that seemed to kill all the sessions on the locked rows so now it's working well.
I think this is not recommended if you have multiple developers and your app should be running all the time.

Marked as Answer by Jasper Tanglib · Apr 20 2021
Billy Verreynne

Jasper, the v$session view has columns indicating the session (if any), blocking the current session.
Remember that hitting the db reset button, effectively destroys the runtime context and data required for root cause analysis - and usually leaves you blind from preventing the problem in future.

1 - 11
Locked Post
New comments cannot be posted to this locked post.

Post Details

Locked on Nov 2 2020
Added on Aug 18 2016
21 comments
3,382 views