- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我是 Oracle 的新手。现在我正在尝试解析 XML 并将其放入 VK_ACCOUNTS 表中。我的 xml 示例在这里:
<?xml version="1.0" encoding="utf-8"?>
<response list="true">
<account>
<account_id>1656672360</account_id>
<account_type>general</account_type>
<account_status>1</account_status>
<access_role>reports</access_role>
</account>
</response>
我使用下面的函数请求 xml,据我所知它正确返回 xml:
create or replace function GET_CLOBFROMURL(
p_url varchar2,
p_charset varchar2 default 'UTF8'
) return clob
is
req utl_http.req;
resp utl_http.resp;
val varchar2(32547);
a clob;
BEGIN
a:='';
dbms_lob.createtemporary(a,true);
dbms_lob.open(a,dbms_lob.lob_readwrite);
req := utl_http.begin_request(p_url);
utl_http.set_body_charset(req, p_charset);
resp := utl_http.get_response(req);
LOOP
a := a||val;
utl_http.read_text(resp, val, 5000);
END LOOP;
utl_http.end_response(resp);
return a;
EXCEPTION
WHEN utl_http.end_of_body THEN
utl_http.end_response(resp);
return a;
WHEN others then
utl_http.end_response(resp);
raise;
END;
并将 xml 获取到 xml_clob
xml_clob := tableau.get_clobFromUrl(REQUEST);
IF xml_clob != EMPTY_CLOB() THEN
insert into tableau.VK_ACCOUNTS(account_id, account_type, account_status, access_role)
SELECT
proc.account_id,
proc.account_type,
proc.account_status,
proc.access_role
FROM XMLTABLE('response/account' passing (select xmltype(xml_clob) resp FROM dual)
columns account_id number path '/account/account_id',
account_type varchar2(20) path '/account/account_type',
account_status number path '/account/account_status',
access_role varchar2(20) path '/account/access_role'
) proc;
COMMIT;
END IF;
END;
最后我得到一个错误:
ORA-31011: XML parsing failed
ORA-19202: Error occurred in XML
LPX-00209: PI names starting with XML are reserved
Error at line 3
ORA-06512: на "SYS.XMLTYPE", line 272
ORA-06512: на line 1
ORA-06512: на "TABLEAU.VK_LOADDATA", line 11
ORA-06512: на line 2
我已经尝试过 XML 的 TRIM 函数,但它对我没有帮助。
有什么想法吗?
最佳答案
LPX-00209: PI names starting with XML are reserved
当 XML 字符串中存在前导空白字符时,就会出现这种情况。 See http://oraclequirks.blogspot.co.uk/2013/03/lpx-00209-pi-names-starting-with-xml.html .
您应该能够通过使用以下方法解决它:
XMLType( TRIM( xml_clob ) )
稍微简化你的功能:
create or replace function GET_CLOBFROMURL(
p_url varchar2,
p_charset varchar2 default 'UTF8'
) return clob
is
req utl_http.req;
resp utl_http.resp;
val varchar2(32547);
a clob := EMPTY_CLOB();
BEGIN
req := utl_http.begin_request(p_url);
utl_http.set_body_charset(req, p_charset);
resp := utl_http.get_response(req);
LOOP
BEGIN
utl_http.read_text(resp, val, 5000);
a := a||val;
EXCEPTION
WHEN utl_http.end_of_body THEN
utl_http.end_response(resp);
EXIT;
END;
END LOOP;
return a;
EXCEPTION
WHEN others THEN
utl_http.end_response(resp);
RAISE;
END;
然后插入可以完全用 SQL 完成:
insert into tableau.VK_ACCOUNTS (
account_id,
account_type,
account_status,
access_role
)
SELECT proc.account_id,
proc.account_type,
proc.account_status,
proc.access_role
FROM ( SELECT tableau.get_clobFromUrl(REQUEST) AS xml FROM DUAL ) c,
XMLTABLE(
'/response/account'
passing XMLType( TRIM( c.xml ) )
columns account_id number path './account_id',
account_type varchar2(20) path './account_type',
account_status number path './account_status',
access_role varchar2(20) path './access_role'
) proc
WHERE c.xml IS NOT NULL
AND DBMS_LOB.GETLENGTH( c.xml ) > 0;
关于Oracle xmltable解析返回LPX-00209,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41693602/
我试图通过这个脚本从下面的 XML 中获取作为 80621b17-97a8-926d945b602a 的信封_id,但没有任何结果。任何人都可以有任何想法吗? SELECT b.EnvelopeID
我有以下 XML 结构: 1 10000 11 1000
我有这样的 XML: A A1 A2 A3 B C D
什么是 XMLTABLE。 请告诉我创建 XMLTABLE 的语法 从 XMLTABLE 获取记录的示例查询。 创建 XMLTABLE 之前是否需要任何数据库级别的先决条件。 最佳答案 函数XMLTA
我有这样的 XML: A A1 A2 A3 B C D
我想知道是否可以在带有 XPATH 的 Oracle XMLTABLE 结构中使用 if 或条件语句。出于设计原因,我只能在 XMLTABLE 中使用 xpath。我在 XQUERY 中使用了 if
使用此 XML : A B C D 1 2 3
在PL/SQL中有没有办法获取最深深度的所有节点? 示例1: A B A11 示例2: A B D
我有一个函数可以解析 XMLTYPE 变量,并且对于每条消息,为 XMLTYPE 变量中的每个标记附加一个具有特定结构的 CLOB。像这样: FUNCTION myFunc (px_Header
我正在使用 Oracle 11.2.0.4.0并且在 XMLTABLE 时遇到过几次问题被卷入。我的最新问题可以通过以下示例(我设计得尽可能简单)来演示: with data as ( selec
我在 Oracle 的一列中有 XML,存储为 CLOB 类型。我的目的是解析这个 XML 并检索与感兴趣的列对应的数据。这是 XML 结构: G1_val G2_val
我正在尝试运行一个涉及 xmltable 的脚本,但我得到了一个 PLS-00428: an INTO clause is expected in this SELECT statement 如何更正
I want to parse a xml string that is a web service response sent from servier, the xml looks like th
我将以下 XML 文件从名为 ARCHIVDATA 的表中完全导入到一个名为 CLOB_CONTENT 的单元格中: 1 2
我是一名优秀的程序员,十分优秀!