
在数据库中能使用百度查询是件很有意思的事情,在其它关系数据库中这是不可能的事情,但在虚拟数据库
sqlhub3.0
中却非常简单,脚本如下:
--
创建模式
create or replace schema html type html url '' ;
-- 创建表
create or replace table HTML.baidu
url 'http://www.baidu.com/s?wd= 北京 &cl=3'
charset 'gb2312'
row_xpath '/html/body/table/tr/td'
(href VARCHAR FORMAT 'ELE_ATTRIBUTE' ELEMENT 'a' ATTRIBUTE 'href'
,title VARCHAR ELEMENT 'a/font'
,content VARCHAR FORMAT 'ELEMENT' ELEMENT 'font' );
-- 创建函数(存储过程)
create or replace procedure baidu(word,page) return rowset as
begin
execute( 'alter table html.baidu set url ''http://www.baidu.com/s?wd=' + word + '&cl=3&rn=100&pn=' + page * 100 + '''' );
select * from html.baidu where title != null;
end;
-- 引用
select * from baidu( ' 北京 ' , 1 )
我们可以干想干的事情了,比如合并查询结果:
create or replace schema html type html url '' ;
-- 创建表
create or replace table HTML.baidu
url 'http://www.baidu.com/s?wd= 北京 &cl=3'
charset 'gb2312'
row_xpath '/html/body/table/tr/td'
(href VARCHAR FORMAT 'ELE_ATTRIBUTE' ELEMENT 'a' ATTRIBUTE 'href'
,title VARCHAR ELEMENT 'a/font'
,content VARCHAR FORMAT 'ELEMENT' ELEMENT 'font' );
-- 创建函数(存储过程)
create or replace procedure baidu(word,page) return rowset as
begin
execute( 'alter table html.baidu set url ''http://www.baidu.com/s?wd=' + word + '&cl=3&rn=100&pn=' + page * 100 + '''' );
select * from html.baidu where title != null;
end;
-- 引用
select * from baidu( ' 北京 ' , 1 )
我们可以干想干的事情了,比如合并查询结果:
select
'
北京
'
city,* from baidu(
'
北京
'
)
union all
select ' 北京 ' ,* from baidu( ' 天津 ' )
union all
select ' 北京 ' ,* from baidu( ' 天津 ' )
