您可以查看example,它使用 utl_http 来了解如何操作
你需要注意的几件事
1)您需要从数据库服务器直接连接互联网
2)您需要编辑您的数据库 ACL 策略才能使其正常工作
3)您需要在用于搜索的 URL 中转义“&”符号
4)您需要使用 Oracle 钱包验证 SSL 证书
ACL 示例
BEGIN
--You need DBA to execute this function where www.xml is the ACL Name
--SCOTT is the schemaname,my.oracle.com is the host to access the webpage
DBMS_NETWORK_ACL_ADMIN.CREATE_ACL(acl => 'www.xml',
description => 'WWW ACL',
principal => 'SCOTT',
is_grant => true,
privilege => 'connect');
DBMS_NETWORK_ACL_ADMIN.ADD_PRIVILEGE(acl => 'www.xml',
principal => 'SCOTT',
is_grant => true,
privilege => 'resolve');
DBMS_NETWORK_ACL_ADMIN.ASSIGN_ACL(acl => 'www.xml',
host => 'my.oracle.com');
END;
/
COMMIT;
您可以向 ACL www.xml 添加用于访问 Internet 的其他主机名,如下所示
BEGIN
DBMS_NETWORK_ACL_ADMIN.ASSIGN_ACL(acl => 'www.xml',
host => 'www.google.co.in');
END;
/
COMMIT;
这里是一个使用谷歌搜索经纬度的例子
declare
httpuri HttpUriType;
x clob;
address VARCHAR2(32000):='New York';
lat_long_value VARCHAR2(4000);
begin
UTL_HTTP.set_transfer_timeout(60); --set timeout to 60 seconds
httpuri := HttpUriType('http://www.google.co.in/search?q=find+latitude+and+longitude+of+' ||address||'&'||'ie=utf-'||'8&'||'oe=utf-'||'8&'||'aq=t'||'&'||'rls=org.mozilla'||':'||'en-US'||':'||'official'||'&'||'client=firefox-a');
x := httpuri.getclob();
lat_long_value := regexp_substr(x, '<div class="_Xj">(.+)</div>');
if lat_long_value is not null then
select regexp_replace(lat_long_value,
'<div class="_Xj">(.+)</div>',
'\1')
into lat_long_value
FROM dual;
end if;
dbms_output.put_line(lat_long_value);
end;
如果你得到错误,
Ora-29024 Certification validation failure
请按照所需的步骤将谷歌证书添加到 Oracle 钱包here
最后你得到的输出是
40.7127° N, 74.0059° W