473,396 Members | 2,121 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Trying (and failing) to use PL/SQL variable in a XML query in a cursor

I'm sure I'm just being thick, but I just can't get the following to work.

I have loaded an XSD file into an Oracle xmltype table (called xsd_table here). The xsd looks roughly like this:

Expand|Select|Wrap|Line Numbers
  1. <xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
  2.  <xs:element name="BASE_ELEMENT">
  3.    <xs:complexType>
  4.     <xs:sequence>
  5.      <xs:element name="MID_ELEMENT_A">
  6.       <xs:complexType>
  7.        <xs:sequence>
  8.         <xs:element name="TOP_ELEMENT_A_1">
  9.          BLAH
  10.         </xs:element>
  11.         <xs:element name="TOP_ELEMENT_A_2">
  12.          BLAH
  13.         </xs:element>
  14.         ...
  15.         ...
  16.        </xs:sequence>
  17.       </xs:complexType>
  18.      </xs:element>
  19.      <xs:element name="MID_ELEMENT_B">
  20.       <xs:complexType>
  21.        <xs:sequence>
  22.         <xs:element name="TOP_ELEMENT_B_1">
  23.          BLAH
  24.         </xs:element>
  25.         <xs:element name="TOP_ELEMENT_B_2">
  26.          BLAH
  27.         </xs:element>
  28.         ...
  29.         ...
  30.        </xs:sequence>
  31.       </xs:complexType>
  32.      </xs:element>
  33.      ...
  34.      ...
  35.     </xs:sequence>
  36.    </xs:complexType>
  37.  </xs:element>
  38. </xs:schema>
I have extracted all the element names at MID_ELEMENT_# level into a table (called mid_element_table here)

I'm now trying to extract all the element names at TOP_ELEMENT_X_# level (so I end up with a table containing mid_element_name, top_element_name for each top_element.

To do this, I've created the following:

[For now I've just hardcoded the variable V_MID_ELEM - once I get this working a bit, I'll try to properly integrate it with the cursor]

Expand|Select|Wrap|Line Numbers
  1. declare
  2. cursor c1 is
  3.   select mid_element
  4.   from mid_element_table;
  5. V_MID_ELEM VARCHAR2(10) := 'MID_ELEMENT_A';
  6. BEGIN
  7.   for c1_rec in c1
  8.   loop
  9.     insert into top_element_table
  10.       (mid_element, top_element)
  11.     select c1_rec.mid_element,
  12.               value(t).extract('/xs:element/@name',
  13.                                'xmlns:xs="http://www.w3.org/2001/XMLSchema"')
  14.     from xsd_table x,
  15.          table(xmlsequence(value(x).extract('/xs:schema/xs:element/xs:complexType/xs:sequence/xs:element[@name=V_MID_ELEM]/xs:complexType/xs:sequence/xs:element',
  16.                                             'xmlns:xs="http://www.w3.org/2001/XMLSchema"'))) t;
  17. end loop;
  18. END;
But it doesn't work (inserts 0 rows).

I can get it to work by replacing the V_MID_ELEM within the XML query with a hardcoded value, but that's no good. It won't work if I replace it with "c1_rec.mid_element" either.

I've been reading manuals and searching the web for days, but I'm not even sure what I'm looking for. This is driving me nuts!

Can anyone help me, or at least point me in a useful direction to look?
Sep 3 '07 #1
1 2114
jkmyoung
2,057 Expert 2GB
Sounds like string concatenation is needed:

'/xs:schema/xs:element/xs:complexType/xs:sequence/xs:element[@name=' + V_MID_ELEM + ']/xs:complexType/xs:sequence/xs:element'

not entirely familiar with the language you're using, so you might need to replace + with something else, like .
Sep 5 '07 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

11
by: Alban Hertroys | last post by:
Oh no! It's me and transactions again :) I'm not really sure whether this is a limitation of psycopg or postgresql. When I use multiple cursors in a transaction, the records inserted at the...
2
by: Mage | last post by:
Hello, I started to write my PostgreSQL layer. I tried pyPgSQL and PyGreSQL. I made a *very minimal* performance test and comparsion with the same thing in php. Table "movie" has 129 record and...
1
by: RayP | last post by:
I'd appreciate some help I'm having trying to run a cursor. First, some background. The Status field of all records on Table A needs changing from 1 to 0 where there is no corresponding record...
4
by: sci | last post by:
Could someone help me by answering the questions below? What's a cursor? What's difference between Query and View? Is a RecordSet just part of a table? Can it be part of a query of view? If...
3
by: ssb | last post by:
Hello, This may be very elementary, but, need help because I am new to access programming. (1) Say, I have a column EMPLOYEE_NAME. How do I fetch (maybe, cursor ?) the values one by one and...
1
by: johnpremi | last post by:
Hi there, I have to pass a query string parameter in my Web Config for loading a URL. We have two environments (production and devlopment) and MonitorURL needs to be changed when the deployment is...
5
by: jcolino | last post by:
Hi, I usually get stuck with one of two questions that keep coming up. Perhaps some of you brilliant people can shed some light... 1. How to do use if statements in load commands (I usually...
0
bartonc
by: bartonc | last post by:
This is a work in progress (current and active). There are some issues to resolve in supporting multiple connection types and I plan to add PySQLite to the mix. The this update is due to my...
4
by: MLH | last post by:
I have the following saved UNION query named qryPeople2NameInNPaperAd: SELECT & " " & & " " & & " " & & ", " & & " " & AS Item, tblVehicleJobs.VehicleJobID FROM tblVehicleJobs INNER...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.