在ORACLE的存储过程中,我们可以通过特点的包调用WEBSERVICE程序。先到ORACLE官方网站上去下载:dbws-callout-utility-10131.zip,然后解压这个包里的/sqlj/lib/里的内容到$ORACLE_HOME/sqlj/lib文件夹中。
执行如下命令行:
export PATH=$ORACLE_HOME/bin:$PATH
cd $ORACLE_HOME/sqlj/lib
loadjava -u 用户名/密码 -r -v -f -genmissing -s -grant public dbwsclientws.jar dbwsclientdb11.jar (注意是11g数据库)
然后进入数据库,如果发现utl_dbws包不存在,就直接在编译包utl_dbws_decl.sql和utl_dbws_body.sql。
这样,就实现了包的设置,无需重新启动数据库。
以下为一个程序的例子,来自网络,特此声明。
CREATE OR REPLACE FUNCTION get_city_from_zipcode (p_zipcode IN VARCHAR2)
RETURN VARCHAR2
AS
l_service UTL_DBWS.service;
l_call UTL_DBWS.call;
l_result ANYDATA;
l_wsdl_url VARCHAR2(32767);
l_namespace VARCHAR2(32767);
l_service_qname UTL_DBWS.qname;
l_port_qname UTL_DBWS.qname;
l_operation_qname UTL_DBWS.qname;
l_input_params UTL_DBWS.anydata_list;
BEGIN
l_wsdl_url := 'http://webservices.imacination.com/distance/Distance.jws?wsdl';
l_namespace := 'http://webservices.imacination.com/distance/Distance.jws';
l_service_qname := UTL_DBWS.to_qname(l_namespace, 'DistanceService');
l_port_qname := UTL_DBWS.to_qname(l_namespace, 'Distance');
l_operation_qname := UTL_DBWS.to_qname(l_namespace, 'getCity');
l_service := UTL_DBWS.create_service (
wsdl_document_location => URIFACTORY.getURI(l_wsdl_url),
service_name => l_service_qname);
l_call := UTL_DBWS.create_call (
service_handle => l_service,
port_name => l_port_qname,
operation_name => l_operation_qname);
l_input_params(0) := ANYDATA.ConvertVarchar2(p_zipcode);
l_result := UTL_DBWS.invoke (
call_handle => l_call,
input_params => l_input_params);
UTL_DBWS.release_call (call_handle => l_call);
UTL_DBWS.release_service (service_handle => l_service);
RETURN ANYDATA.AccessVarchar2(l_result);
END;
/