Forum Stats

  • 3,876,212 Users
  • 2,267,082 Discussions


How to require a module from a dbms_mle script (JavaScript)

Philipp Salvisberg
Philipp Salvisberg Member Posts: 181 Silver Badge

I have installed the validator example according (changed username, password and dbinstance accordingly).

The following query works (returns 1):

select isemail('[email protected]') from dual;

Now, I tried to use the validator within dbms_mle as follows:

create or replace function isemail_dyn(in_email in varchar2) return number is  l_script clob;  l_handle dbms_mle.script_handle_t;  l_result number;begin  l_script := q'[mle.binds.result = require('validator').isEmail(;]';  l_handle := DBMS_MLE.CREATE_SCRIPT('JS', l_script);  dbms_mle.bind_variable(l_handle, 'email', in_email);  dbms_mle.execute_script(l_handle);   dbms_mle.variable_value(l_handle, 'result', l_result);  dbms_mle.drop_script(l_handle);  return l_result;end;/

The query using this function fails:

select isemail_dyn('[email protected]') from dual;

The error stack looks like this:

ORA-06550: line 1, column 20:dynamic-mle-script--1156712892.js: ReferenceError: require is not definedORA-06512: at "SYS.DBMS_MLE_CAPI", line 97ORA-06512: at "SYS.DBMS_MLE", line 57ORA-06512: at "DEMO.ISEMAIL_DYN", line 906550. 00000 -  "line %s, column %s:\n%s"*Cause:    Usually a PL/SQL compilation error.*Action:

I've tried tried different variants for "require('validator')", but all with more or less the same result.

Now the question. Is it possible to use previously loaded modules from dbms_mle? If yes, how?

Thank you very much.