I previously discussed new features in 22.2 here.

With a deep dive on the MLE feature here.

Creating an Always Free Autonomous Database in the Oracle Cloud (OCI) is one of the easiest ways to have a go with 21c.

One of the new features in 21c is MultiLingual Engine (MLE), powered by GraalVM, which allows the database to execute JavaScript!

JS in the SQL Worksheet

If you want to run some JS without the DBMS_MLE PL/SQL wrapper, we can do that for you. Simply ask for a new editor in JavaScript mode –

You’ll see this in 21c instances where you have exec privs on DBMS_MLE.

Once I’m in my new editor, I can simply put in my JavaScript –

const oracledb = require("mle-js-oracledb");
      const sql = "SELECT * FROM strava fetch first 1 rows only";
     // execute query
     const result = oracledb.defaultConnection().execute(sql);
     console.log(JSON.stringify(result.rows));

And then I can run it.

Based on an example from our Dev Evangelist, Alina.

Since we’re in ‘JavaScript’ mode, we know we need to wrapper the JS code with calls to DBMS_MLE (PL/SQL).

If you open up your browser dev tools, you can observe the POST to _/sql where we execute your code.

SET SERVEROUTPUT ON
SET define &;
SET escape OFF;
SET timing ON;
ALTER SESSION SET NLS_LANGUAGE = 'AMERICAN';
 
DECLARE
    CTX    DBMS_MLE.CONTEXT_HANDLE_T;
    SOURCE CLOB;
BEGIN
    CTX := DBMS_MLE.CREATE_CONTEXT(); -- Create execution context for MLE execution
    SOURCE := q'~
                        const oracledb = require("mle-js-oracledb");
      const sql = "SELECT * FROM strava fetch first 1 rows only";
     // execute query
     const result = oracledb.defaultConnection().execute(sql);
     console.log(JSON.stringify(result.rows));
                        ~';
    DBMS_MLE.EVAL(CTX, 'JAVASCRIPT', SOURCE); -- Evaluate the source code snippet in the execution context
END;

So we just save you some typing.

Of course, it’s more than just that, our editor also knows to work in ‘JavaScript’ mode vs PL/SQL mode which comes in handy for our parser and insight features.

If you want total control, just stay in the default SQL mode of the worksheet, and run PL/SQL blocks as you normally would.

First time visit to the worksheet as ADMIN?

You might see a warning like this –

What’s up with that, am I doing something wrong?

You’re not necessarily doing anything wrong. But, ADMIN is a very powerful account, in fact it’s the most powerful account available for your database.

So, you probably do not want to put your application data and programs in this schema.

One last thing…yes you can pretty print JSON 🙂

Thanks StackOverflow!

SO Answer here.

Strava, what’s that you say?

Author

I'm a Distinguished Product Manager at Oracle. My mission is to help you and your company be more efficient with our database tools.

Write A Comment