How to get xml attribute with plsql?

15,511
select x.col1.extract('//car/@model').getStringVal() from xtest01 x;
Share:
15,511
avj
Author by

avj

.NET web-developer

Updated on July 23, 2022

Comments

  • avj
    avj almost 2 years
    create table xtest01(col1 xmltype);
    insert into xtest01 values ('<car><model>Audi TT</model></car>');
    insert into xtest01 values ('<car model="BMW X5"/>');
    

    -- I know how to get Audi TT:

    select x.col1.extract('//car/model/text()').getStringVal() from xtest01 x;
    

    -- But how to get BMW X5?

  • avj
    avj almost 13 years
    thanks! (this is the answer; I can accept it after some minutes, as pop-up says to me)