用SQL查询实时汇率
-用文本方式集成html网页数据
Internet中大量数据都是html格式的,对它的集成有着很重要的意义。html格式类似于xml,如果能将html修正为标准的xml文件,用xpath查询获取数据是最理想的,Sqlhub支持这种集成凡是。但现实中由于html的格式非常灵活,并且经常出现少标签,错误标签等,很难转换为标准的xml。在这种情况下只能用文本方式来处理数据了。
下面是从中国银行网站查询汇率的例子:


create or replace schema txt type txt url '';
create or replace table txt.huilv
create or replace table txt.huilv
url 'http://www.boc.cn/cn/common/service.jsp?querytype=bydate&t_oneday=2007%2F10%2F01' charset 'gb2312' rowsep '/n' fieldsep '$$' (
f1 VARCHAR
);
create or replace procedure huilv(d) return rowset as
begin
execute('alter table txt.huilv set
f1 VARCHAR
);
create or replace procedure huilv(d) return rowset as
begin
execute('alter table txt.huilv set
url ''http://www.boc.cn/cn/common/service.jsp?querytype=bydate&t_oneday='
+ replace(d,'-','%2F') + '''');
select getseg(f1, ',', 1) 货币名称,
getseg(f1, ',', 2) 现汇买入价,
getseg(f1, ',', 3) 现钞买入价,
getseg(f1, ',', 4) 卖出价 ,
getseg(f1, ',', 5) 基准价 ,
getseg(f1, ',', 6) 中行折算价,
getseg(f1, ',', 7) 发布时间 ,
from (select strsum(f1, ',') f1
from (select floor((rowno() - 1) / 7) rowno, replace(f1, ' ') f1
from (select substr(f1, 1, instr(f1, '<') - 1) f1
from (select substr(f1, instr(f1, '>', 1) + 1) f1
from txt.huilv limit 207, 182)
where substr(f1, 1, instr(f1, '<') - 1) != ''))
group rowno)
where rowno() > 1;
end;
select * from huilv(curdate());
+ replace(d,'-','%2F') + '''');
select getseg(f1, ',', 1) 货币名称,
getseg(f1, ',', 2) 现汇买入价,
getseg(f1, ',', 3) 现钞买入价,
getseg(f1, ',', 4) 卖出价 ,
getseg(f1, ',', 5) 基准价 ,
getseg(f1, ',', 6) 中行折算价,
getseg(f1, ',', 7) 发布时间 ,
from (select strsum(f1, ',') f1
from (select floor((rowno() - 1) / 7) rowno, replace(f1, ' ') f1
from (select substr(f1, 1, instr(f1, '<') - 1) f1
from (select substr(f1, instr(f1, '>', 1) + 1) f1
from txt.huilv limit 207, 182)
where substr(f1, 1, instr(f1, '<') - 1) != ''))
group rowno)
where rowno() > 1;
end;
select * from huilv(curdate());