Thursday, August 14, 2008

Get TinyURL from PL/SQL - APEX

Here is an example of how to use a PL/SQL function to convert an URL into a TinyURL using their api. This is very simple stuff yet it can save a lot of space!



create or replace FUNCTION get_tinyURL(t_url IN VARCHAR2)
RETURN VARCHAR
IS
http_req utl_http.req;
http_resp utl_http.resp;
res_value VARCHAR2(4000);
BEGIN
--utl_http.set_proxy('http://www.yourproxy.com:80'); --If you need to specify a proxy use this.
http_req := utl_http.begin_request('http://tinyurl.com/api-create.php?url=' || t_url, 'GET');
http_resp := utl_http.get_response(http_req);
utl_http.read_text(http_resp,res_value);
utl_http.end_response(http_resp);

return res_value;

END get_tinyURL;