0

This is how the XML within the table looks like

<?xml version="1.0" encoding="UTF-8"?>
<select multiselect="false" name="c_f_2441_select_dev" phiField="true" readOnly="false" title="select_dev">
  <dataValidationRule/>
  <CFData>false</CFData>
  <suppressRules>false</suppressRules>
  <options>
    <option code="1" status="A">Sel1</option>
    <option code="2" status="A">Sel2</option>
    <option code="3" status="A">Sel3</option>
  </options>
  <groups/>
</select>

Within the "options" element there are three values 'Sel1', 'Sel2' and 'Sel3'

select xt.* 
from  ST3_ENT1_REG4.custom_field cf,
      XMLTABLE('/select'
      PASSING cf.data_model_xml
         COLUMNS 
           options   VARCHAR2(20)  PATH 'options'
          ) xt
where field_name='c_f_2441_select_dev';

The above query concatenates the three values and gives me the output as "Sel1Sel2Sel3". Is there a way I can get those three values in three different row.

Thanks

1 Answer 1

2

SQL Fiddle

Oracle 11g R2 Schema Setup:

CREATE TABLE custom_field ( field_name, data_model_xml ) AS
SELECT
'c_f_2441_select_dev',
XMLTYPE( '<?xml version="1.0" encoding="UTF-8"?>
<select multiselect="false" name="c_f_2441_select_dev" phiField="true" readOnly="false" title="select_dev">
  <dataValidationRule/>
  <CFData>false</CFData>
  <suppressRules>false</suppressRules>
  <options>
    <option code="1" status="A">Sel1</option>
    <option code="2" status="A">Sel2</option>
    <option code="3" status="A">Sel3</option>
  </options>
  <groups/>
</select>' ) FROM DUAL;

Query 1:

If you just want the content of the 1st, 2nd and 3rd option element:

select xt.* 
from  custom_field cf,
      XMLTABLE('/select/options'
      PASSING cf.data_model_xml
         COLUMNS 
           option1   VARCHAR2(20)  PATH 'option[1]',
           option2   VARCHAR2(20)  PATH 'option[2]',
           option3   VARCHAR2(20)  PATH 'option[3]'
          ) xt
where field_name='c_f_2441_select_dev'

Results:

| OPTION1 | OPTION2 | OPTION3 |
|---------|---------|---------|
|    Sel1 |    Sel2 |    Sel3 |

Query 2:

If you want the text of the option element where the code attribute is 1, 2 and 3 then:

select xt.* 
from  custom_field cf,
      XMLTABLE('/select/options'
      PASSING cf.data_model_xml
         COLUMNS 
           option1   VARCHAR2(20)  PATH 'option[@code=1]',
           option2   VARCHAR2(20)  PATH 'option[@code=2]',
           option3   VARCHAR2(20)  PATH 'option[@code=3]'
          ) xt
where field_name='c_f_2441_select_dev'

Results:

| OPTION1 | OPTION2 | OPTION3 |
|---------|---------|---------|
|    Sel1 |    Sel2 |    Sel3 |

Query 3 - Update - in separate rows.:

select xt.* 
from  custom_field cf,
      XMLTABLE(
        '/select/options/option'
        PASSING cf.data_model_xml
        COLUMNS value VARCHAR2(20) PATH 'text()'
      ) xt
where field_name='c_f_2441_select_dev'

Results:

| VALUE |
|-------|
|  Sel1 |
|  Sel2 |
|  Sel3 |
Sign up to request clarification or add additional context in comments.

2 Comments

I wanted the data to be populated in three different rows but under single column.
@Mallikarjunasiraguppi Updated

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.