Melalui Yahoo Query Language kita dapat peroleh URI untuk exchange rate USD-IDR :
http://query.yahooapis.com/v1/public/yql?q=select * from yahoo.finance.xchange where pair in ("USDIDR")&env=store://datatables.org/alltableswithkeys
Lalu kemudian kita bangun fungsi didalam oracle untuk bisa dipakai dalam operasi sql pl/sql atau di APEX.
create or replace function get_yahoo_rate return number is /****************************************************************************** NAME: get_yahoo_rate PURPOSE: get latest USD-IDR rate from Yahoo finance exchange REVISIONS: Ver Date Author Description --------- ---------- --------------- ------------------------------------ 1.0 10/10/2014 Lutfi Hedir 1. Created this function. ******************************************************************************/ l_xml xmltype; l_yahoo_uri constant varchar2(500) := 'http://query.yahooapis.com/v1/public/yql?q=select%20*%20from%20yahoo.finance.xchange%20where%20pair%20in%20(%22USDIDR%22)&env=store://datatables.org/alltableswithkeys'; l_rate varchar2(500); l_rate_n number(10); begin -- get xml data l_xml := xmltype(utl_http.request(l_yahoo_uri)); -- extract rate value from xml data select extractvalue(l_xml, '/query/results/rate/Rate/text()') into l_rate from dual; -- convert to number l_rate_n := to_number(REGEXP_SUBSTR(l_rate,'[0-9]+')); return l_rate_n; end get_yahoo_rate; /
Catatan :
- Jangan lupa setting ACL untuk 11g supaya bisaakses internet.
- Jika akses SSL buatlah wallet terlebih dahulu
- Jika akses proxy modifikasi utl_http.request dengan signature proxy dan wallet
Tidak ada komentar :
Posting Komentar