如何在oracle中使用xmltable?
我正在使用Oracle的XML数据库创建用户配置文件。我将用户配置文件存储在一个XMLTYPE列中,表中还有其他关系列(id、用户名、密码)。XML的格式如下:如何在oracle中使用xmltable?,xml,oracle,Xml,Oracle,我正在使用Oracle的XML数据库创建用户配置文件。我将用户配置文件存储在一个XMLTYPE列中,表中还有其他关系列(id、用户名、密码)。XML的格式如下: <profile> <subject>I <action>like <object>sports</object> ... <object>music</object
<profile>
<subject>I
<action>like
<object>sports</object>
...
<object>music</object
</action>
</subject>
</profile>
这对我来说毫无意义。我怎样才能让这东西工作 示例中的
操作
和对象
不在同一级别,因此您的查询必须执行其他步骤。下面是一个例子:
SQL> create table users (id number, profile xmltype);
Table created.
SQL> insert into users values (1, XMLTYPE('<profile>
2 <subject>I
3 <action>like
4 <object>sports</object>
5 <object>music</object>
6 </action>
7 </subject>
8 </profile>'));
1 row created.
SQL> select u.id, x.action, x.object.getStringVal()
2 from users u,
3 XMLTABLE('/profile/subject/action'
4 passing u.profile
5 columns action VARCHAR2(30) PATH 'text()',
6 object XMLTYPE PATH 'object') x;
ID ACTION X.OBJECT.GETSTRINGVAL()
--- ------- --------------------------------------------------
1 like <object>sports</object> <object>music</object>
SQL> create table users (id number, profile xmltype);
Table created.
SQL> insert into users values (1, XMLTYPE('<profile>
2 <subject>I
3 <action>like
4 <object>sports</object>
5 <object>music</object>
6 </action>
7 </subject>
8 </profile>'));
1 row created.
SQL> select u.id, x.action, x.object.getStringVal()
2 from users u,
3 XMLTABLE('/profile/subject/action'
4 passing u.profile
5 columns action VARCHAR2(30) PATH 'text()',
6 object XMLTYPE PATH 'object') x;
ID ACTION X.OBJECT.GETSTRINGVAL()
--- ------- --------------------------------------------------
1 like <object>sports</object> <object>music</object>
SQL> select u.id, x.action, y.object
2 from users u,
3 XMLTABLE('/profile/subject/action'
4 passing u.profile
5 columns action VARCHAR2(30) PATH 'text()',
6 object XMLTYPE PATH 'object') x,
7 XMLTABLE('/object'
8 passing x.object
9 columns object VARCHAR2(30) PATH '.') y;
ID ACTION OBJECT
--- ------- -------
1 like sports
1 like music