Skip to Main Content
  • Questions
  • plsql function or apex javascript function return url code status 404

Breadcrumb

Question and Answer

Chris Saxon

Thanks for the question, ahmed.

Asked: October 04, 2023 - 6:51 pm UTC

Last updated: January 08, 2025 - 2:29 am UTC

Version: 19.2

Viewed 100+ times

You Asked

Hi Tom,
I have sql statement with pdf book url attribute. I need virtual column till me the url is valid or not found. So I need page http status code either java function in oracle apex, or sql query.
example:

select title_no, title_name, pub_date, ' https://library.iugaza.edu.ps/thesis/'||a.TITLE_NO||'.pdf' as pdf_url
from lib_master.

The result as follow:

TITLE_NO TITLE_NAME PUB_DATE PDF_URL
-------- ------------------------------------------------------------------------------------------------- ------- ----------------------------------------------
55171 measurement of radon and ils daughter's concentrations in indoor and outdoor throughout gaza strip 2003 https://library.iugaza.edu.ps/thesis/55171.pdf
55172 ance system" in the gaza strip using geographical information system and decision support system 2003 https://library.iugaza.edu.ps/thesis/55172.pdf
55234 study of the onset of the earth magnetosphere under the influence of the solar wind 2003 https://library.iugaza.edu.ps/thesis/55234.pdf
55335 study of the measurement of labor productivity in the palestinian construcrtion industry 2003 https://library.iugaza.edu.ps/thesis/55335.pdf

I need display attribute return url status code, i.e. 200, 404, etc.

Thank you.

and Connor said...

Something like this might help

SQL> create or replace
  2  function get_status(p_url varchar2) return number is
  3    l_http_request   utl_http.req;
  4    l_http_response  utl_http.resp;
  5    l_status         int;
  6  begin
  7    l_http_request  := utl_http.begin_request(p_url);
  8    l_http_response := utl_http.get_response(l_http_request);
  9
 10    l_status :=  l_http_response.status_code;
 11    utl_http.end_response(l_http_response);
 12    return l_status;
 13  exception
 14      when others then
 15        utl_http.end_response(l_http_response);
 16        return -1;
 17  end;
 18  /

Function created.

SQL>
SQL> select get_status('https://www.oracle.com') from dual;

GET_STATUS('HTTPS://WWW.ORACLE.COM')
------------------------------------
                                 403

SQL> select get_status('https://www.oracle123.com') from dual;

GET_STATUS('HTTPS://WWW.ORACLE123.COM')
---------------------------------------
                                     -1



You'll need to ensure the appropriate network ACL's etc are setup

Is this answer out of date? If it is, please let us know via a Comment

More to Explore

PL/SQL demos

Check out more PL/SQL tutorials on our LiveSQL tool.

PL/SQL docs

PL/SQL reference manual from the Oracle documentation library