It's Time to Get Ready for the Power
of PL/SQL and JavaScript Combined
Rodrigo Mesquita
March 30th, 2023
About Rodrigo
• Senior Oracle Developer at QV Systems - UK leading software
provider of asset back finance such as Auto Finance.
• 20 years of Oracle Experience
• Oracle ACE Pro
• UKOUG - 2018 Best New UK Speaker
• Twitter: @mesquitarod
apexblog.dev
The Multilingual Engine (MLE)
• Available from Oracle 21c and APEX 20.2
• Oracle Database provides the DBMS_MLE PL/SQL package to evaluate
JavaScript code within a database session
• Powered by GraalVM Multilingual Engine: Javascript could be just the
beginning.
apex.server.process
Client Side Server Side
Javascript PL/SQL
Oracle Database
with APEX
MLE
Client Side Server Side
PL/SQL & Javascript
Oracle Database
with APEX
and MLE
MLE with APEX
• Processes
• Computations
• Validation
• Execute Server-side Code dynamic action
• SQL Commands
• Region Source
MLE
Non-MLE
Page
Submit
PL/SQL
JavaScript
PL/SQL
JavaScript
PL/SQL
JavaScript
PL/SQL
Before After
apex.env - allow us to interact with page items
apex.conn.execute - execute DML or PL/SQL
JavaScript as a Server-Side Language in Oracle APEX by Stephan Dobre
DECLARE
ctx dbms_mle.context_handle_t;
user_code clob := q'~
console.log('Hello World!');
~';
BEGIN
ctx := dbms_mle.create_context();
dbms_mle.eval(ctx, 'JAVASCRIPT', user_code);
dbms_mle.drop_context(ctx);
EXCEPTION
WHEN others THEN
dbms_mle.drop_context(ctx);
RAISE;
END;
DECLARE
ctx dbms_mle.context_handle_t;
result varchar2(100);
user_code clob := q'~
let bindings = require('mle-js-bindings');
let val = bindings.importValue('value');
bindings.exportValue('response', val+' is awesome');
~';
BEGIN
ctx := dbms_mle.create_context();
dbms_mle.export_to_mle(ctx, 'value', 'APEX');
dbms_mle.eval(ctx, 'JAVASCRIPT', user_code);
dbms_mle.import_from_mle(ctx, 'response', result);
dbms_mle.drop_context(ctx);
dbms_output.put_line(result);
EXCEPTION
WHEN others THEN
dbms_mle.drop_context(ctx);
RAISE;
END;
/
DECLARE
ctx dbms_mle.context_handle_t;
result varchar2(100);
user_code clob := q'~
let bindings = require('mle-js-bindings');
const oracledb = require('mle-js-oracledb');
const conn = oracledb.defaultConnection();
let val = bindings.importValue('value');
const code = "update customers set full_name = 'Rodrigo Mesquita' where customer_id = "+val;
conn.execute(code);
~';
BEGIN
ctx := dbms_mle.create_context();
dbms_mle.export_to_mle(ctx, 'value', 1);
dbms_mle.eval(ctx, 'JAVASCRIPT', user_code);
dbms_mle.drop_context(ctx);
EXCEPTION
WHEN others THEN
dbms_mle.drop_context(ctx);
RAISE;
END;
DECLARE
ctx DBMS_MLE.context_handle_t := DBMS_MLE.create_context();
user_code clob := q'~
const oracledb = require('mle-js-oracledb');
const OracleNumber = require('mle-js-plsqltypes').OracleClob;
let bindings = require('mle-js-bindings');
const conn = oracledb.defaultConnection();
let val = bindings.importValue('value');
const query = "SELECT full_name AS name FROM customers where customer_id = "+val;
const options = { fetchInfo: { name: { type: oracledb.ORACLE_CLOB } } };
const result = conn.execute(query, [], options);
console.log(result.rows[0][0]);
~';
BEGIN
DBMS_MLE.export_to_mle(ctx, 'value', 1);
DBMS_MLE.eval(ctx, 'JAVASCRIPT', user_code);
DBMS_MLE.drop_context(ctx);
EXCEPTION
WHEN others THEN
DBMS_MLE.drop_context(ctx);
RAISE;
END;
API USER
CLIENT SECRET
STRING =
API User +
Client Secret +
timestamp
Automation DB Procedure
It's Time to Get Ready for the Power  of PL/SQL and JavaScript Combined

It's Time to Get Ready for the Power of PL/SQL and JavaScript Combined

  • 1.
    It's Time toGet Ready for the Power of PL/SQL and JavaScript Combined Rodrigo Mesquita March 30th, 2023
  • 2.
    About Rodrigo • SeniorOracle Developer at QV Systems - UK leading software provider of asset back finance such as Auto Finance. • 20 years of Oracle Experience • Oracle ACE Pro • UKOUG - 2018 Best New UK Speaker • Twitter: @mesquitarod
  • 3.
  • 4.
    The Multilingual Engine(MLE) • Available from Oracle 21c and APEX 20.2 • Oracle Database provides the DBMS_MLE PL/SQL package to evaluate JavaScript code within a database session • Powered by GraalVM Multilingual Engine: Javascript could be just the beginning.
  • 5.
    apex.server.process Client Side ServerSide Javascript PL/SQL Oracle Database with APEX
  • 6.
    MLE Client Side ServerSide PL/SQL & Javascript Oracle Database with APEX and MLE
  • 7.
    MLE with APEX •Processes • Computations • Validation • Execute Server-side Code dynamic action • SQL Commands • Region Source
  • 8.
  • 9.
    apex.env - allowus to interact with page items apex.conn.execute - execute DML or PL/SQL JavaScript as a Server-Side Language in Oracle APEX by Stephan Dobre
  • 10.
    DECLARE ctx dbms_mle.context_handle_t; user_code clob:= q'~ console.log('Hello World!'); ~'; BEGIN ctx := dbms_mle.create_context(); dbms_mle.eval(ctx, 'JAVASCRIPT', user_code); dbms_mle.drop_context(ctx); EXCEPTION WHEN others THEN dbms_mle.drop_context(ctx); RAISE; END;
  • 11.
    DECLARE ctx dbms_mle.context_handle_t; result varchar2(100); user_codeclob := q'~ let bindings = require('mle-js-bindings'); let val = bindings.importValue('value'); bindings.exportValue('response', val+' is awesome'); ~'; BEGIN ctx := dbms_mle.create_context(); dbms_mle.export_to_mle(ctx, 'value', 'APEX'); dbms_mle.eval(ctx, 'JAVASCRIPT', user_code); dbms_mle.import_from_mle(ctx, 'response', result); dbms_mle.drop_context(ctx); dbms_output.put_line(result); EXCEPTION WHEN others THEN dbms_mle.drop_context(ctx); RAISE; END; /
  • 12.
    DECLARE ctx dbms_mle.context_handle_t; result varchar2(100); user_codeclob := q'~ let bindings = require('mle-js-bindings'); const oracledb = require('mle-js-oracledb'); const conn = oracledb.defaultConnection(); let val = bindings.importValue('value'); const code = "update customers set full_name = 'Rodrigo Mesquita' where customer_id = "+val; conn.execute(code); ~'; BEGIN ctx := dbms_mle.create_context(); dbms_mle.export_to_mle(ctx, 'value', 1); dbms_mle.eval(ctx, 'JAVASCRIPT', user_code); dbms_mle.drop_context(ctx); EXCEPTION WHEN others THEN dbms_mle.drop_context(ctx); RAISE; END;
  • 13.
    DECLARE ctx DBMS_MLE.context_handle_t :=DBMS_MLE.create_context(); user_code clob := q'~ const oracledb = require('mle-js-oracledb'); const OracleNumber = require('mle-js-plsqltypes').OracleClob; let bindings = require('mle-js-bindings'); const conn = oracledb.defaultConnection(); let val = bindings.importValue('value'); const query = "SELECT full_name AS name FROM customers where customer_id = "+val; const options = { fetchInfo: { name: { type: oracledb.ORACLE_CLOB } } }; const result = conn.execute(query, [], options); console.log(result.rows[0][0]); ~'; BEGIN DBMS_MLE.export_to_mle(ctx, 'value', 1); DBMS_MLE.eval(ctx, 'JAVASCRIPT', user_code); DBMS_MLE.drop_context(ctx); EXCEPTION WHEN others THEN DBMS_MLE.drop_context(ctx); RAISE; END;
  • 14.
    API USER CLIENT SECRET STRING= API User + Client Secret + timestamp
  • 15.