使用Oracle的XMLQuery

时间:2017-09-19 10:00:45

标签: sql xml oracle oracle11g xquery

我正在从工作簿中做例子。我创建了表并插入了几个记录。以下是我的代码:

创建表格:

CREATE TABLE test_Pracownicy
(IDPracownika NUMBER(3),
Dane XMLTYPE);

将记录插入表格:

INSERT INTO test_Pracownicy (IDPracownika, Dane)
VALUES (1,
  XMLTYPE('
    <PRecord>
      <Nazwisko>Kowalski</Nazwisko>
      <Imie>Jan</Imie>
      <RokUrodz>1980</RokUrodz>
      <Wzrost>1.77</Wzrost>
      <DataZatr>2001/02/10</DataZatr>
    </PRecord>')
);

现在我想运行XMLQuery:

SELECT IDPracownika,
  XMLQuery(
    'FOR $i IN /PRecord
      WHERE $i /Nazwisko = "Kowalski"
      ORDER BY $i/Imie
      RETURN $i'
    PASSING by VALUE Dane
    RETURNING CONTENT) NazwiskoXML
FROM test_Pracownicy;

我收到错误:

ORA-19114: XPST0003 - error during parsing the XQuery expression: 
LPX-00801: XQuery syntax error at 'i'
1   FOR $i IN /PRecord
-       ^
19114. 00000 -  "error during parsing the XQuery expression: %s"
*Cause:    An error occurred during the parsing of the XQuery expression.
*Action:   Check the detailed error message for the possible causes.
Error at Line: 117 Column: 6

1 个答案:

答案 0 :(得分:0)

我将查询更改为小(for,where,return ...)字母,它正在工作:

SELECT IDPracownika,
  XMLQuery(
    'for $i in /PRecord
      where$i /Nazwisko = "Kowalski"
      order by $i /Imie
      retrun $i'
    PASSING by VALUE Dane
    RETURNING CONTENT) NazwiskoXML
FROM test_Pracownicy;

区分大小写。