我的xmltype中的示例记录是,
1 , XMLTYPE('<books> <book minprice = "10" maxprice="25"> .. </book> <book minprice = "15" maxprice="20"> </books>');
以下是我的pl / sql函数,用于查找整个plsql中的最大和最小价格,这是不完整的。
create or replace
FUNCTION DiffMaxMinPrice
return double precision
is
diffprice double precision := 0;
minprice long;
maxprice long;
value long;
begin
SELECT x.* into minprice , maxprice
FROM sampletable ,
XMLTABLE ('//book'
PASSING sampletable.xmlcol
COLUMNS maxprice VARCHAR2(30) PATH '@maxprice',
minprice VARCHAR2(30) PATH '@minprice') x
where sampletable.indexid = 2;
return 1;
end;
select查询返回多个值,如何遍历所有这些值。
我正在使用Oracle 11gr2。
答案 0 :(得分:4)
我相信你正在寻找光标。你可以做点像......
create or replace
FUNCTION DiffMaxMinPrice
return double precision
is
diffprice double precision := 0;
minprice long;
maxprice long;
value long;
begin
FOR row IN (
SELECT x.*
FROM sampletable ,
XMLTABLE ('//book'
PASSING sampletable.xmlcol
COLUMNS maxprice VARCHAR2(30) PATH '@maxprice',
minprice VARCHAR2(30) PATH '@minprice') x
where tbltagdata.indexid = 2)
LOOP
... (work with each row here)
END LOOP;
return 1;
end;