我试图选择一个特定的xml值作为存储为XML的Oracle 11G表中的列-巨大的CLOB,但是无法。请帮助
XML内容如下
<Bid xmlns:i="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://schemas.datacontract.org/2004/07/LCC.Crew.FAReserves.wsvc.Entities.FAReserves">
<AggressiveBidType></AggressiveBidType>
<BidCriteria>
<BidCriteria i:type="RapBidCriteria">
<Value xmlns:d4p1="http://www.w3.org/2001/XMLSchema" i:type="d4p1:string">BAC</Value>
</BidCriteria>
</BidCriteria>
<BidItem>RAP</BidItem>
<BidName>BAC</BidName>
<BidType>Standing</BidType>
<CatsId>10023</CatsId>
<EmployeeBidId>10620</EmployeeBidId>
<EmployeeId>135289</EmployeeId>
<EndDate>2015-03-29T00:00:00Z</EndDate>
<IsAggressive>false</IsAggressive>
<IsLodo>false</IsLodo>
<IsOnPremiseReserve>false</IsOnPremiseReserve>
<OperatingDate>2015-02-25T00:00:00Z</OperatingDate>
<Priority>0</Priority>
</Bid>
以下语句返回空值
SELECT extract(XMLTYPE(XMLBIDCONTENT),'/Bid/BidName/text()') "REFERENCE"
FROM AOCREWBIDDING.EMPLOYEEBIDS
Where EmployeeBidID = 100
以下语句返回错误
ORA-00932:数据类型不一致:预期-得到- 00932。00000-“数据类型不一致:预期的%s得到了%s” *原因:
*操作:第83行的错误:第8列
SELECT extract(XMLBIDCONTENT,'/Bid/BidName/text()').getStringVal() "REFERENCE"
FROM AOCREWBIDDING.EMPLOYEEBIDS
Where EmployeeBidID = 100
答案 0 :(得分:2)
The extract()
function is deprecated。最好使用XMLQuery()
。
您需要声明一个默认名称空间以匹配XML文档中的名称空间:
select XMLQuery('
declare default element namespace
"http://schemas.datacontract.org/2004/07/LCC.Crew.FAReserves.wsvc.Entities.FAReserves"; (: :)
/Bid/BidName/text()'
passing XMLType(xmlbidcontent)
returning content) as BidName
from employeebids
where EmployeeBidID = 100;
BIDNAME
--------------------------------------------------------------------------------
BAC
或(更简单但更不可靠)使用通配符:
select XMLQuery('/*:Bid/*:BidName/text()'
passing XMLType(xmlbidcontent)
returning content) as BidName
from employeebids
where EmployeeBidID = 100;
BIDNAME
--------------------------------------------------------------------------------
BAC
db<>fiddle显示您的原始查询,并使用CTE提供样本CLOB值来显示这两个查询。