Oracle XMLTABLE语法错误

时间:2010-10-27 17:25:01

标签: oracle oracle10g

我创建了一个带有xmltype列

的表的简单示例
--set up the able
CREATE TABLE dept (name varchar2(20), employees XMLTYPE);

--insert a test row
INSERT INTO dept VALUES (
            'Sales',
            XMLTYPE.createxml(
            '<?xml version="1.0" encoding="UTF-8"?>
            <People>
              <Person>
                <Name>TED</Name>
                <Age>35</Age>
              </Person>
              <Person>
                <Name>BEN</Name>
                <Age>36</Age>
              </Person>
              <Person>
                <Name>EDI</Name>
                <Age>37</Age>
              </Person>
            </People>'
           )
   );

我只是想通过使用xml表来展平结果(在另一个查询中使用)以便我得到

Sales   | Ted | 35
Sales   | BEN | 36
Sales   | EDI | 37

所以我用xtable

写了这个查询
SELECT dept name, people.Name, people.Age
   FROM dept,
   XMLTABLE('/people'
      PASSING dept.employees
      COLUMNS 
         "Name" varchar2(6) PATH '/People/Person/Name',
         "Age" varchar2(6) PATH '/People/Person/Age'
      people;

但是我收到以下错误

“ORA-01780:需要字符串文字”

并且ide突出显示以下行

     "Name" varchar2(6) PATH '/People/Person/Name',

任何人都可以告诉我我错过了什么/做错了吗

1 个答案:

答案 0 :(得分:1)

编辑 - 运行此操作 - alter session set cursor_sharing = exact  或者在参数文件中设置cursor_sharing = exact。

然后你可能在COLUMNS(/ Age) -

之后也错过了一个结束括号
SELECT dept name, people.Name, people.Age
   FROM dept,
   XMLTABLE('/people'
      PASSING dept.employees
      COLUMNS 
         "Name" varchar2(6) PATH '/People/Person/Name',
         "Age" varchar2(6) PATH '/People/Person/Age' )
      people;