Find file Copy path
Fetching contributors…
Cannot retrieve contributors at this time
47 lines (24 sloc) 1.99 KB

SODA for JavaScript Stored Procedures

SODA for Java is Oracle's fluent Java API for accessing JSON collections and documents without any knowledge of SQL.

See SODA for Java in the Database for running SODA with OJVM.

The goal of this write up is to furnish the steps for performing fluent JavaScript programming (i.e., No SQL and dot notation) in OJVM and manipulate the JSON collection directly in the database session without moving data around.

Requirements for SODA for JavaScript Stored Procedures

JavaScript in Oracle database is enabled using Nashorn in the embedded JVM (a.k.a. OJVM). Leveraging the interoperability of Java and JavaScript with Nashorn, we will reuse the SODA for Java APIs in JavaScript code.

(i) Follow steps (i), (ii) and (iii) in the section titled Requirements to run SODA with Java in the database


(i) We've rewritten in JavaScript (i.e., testSODA.js), using SODA for Java API. Grap testSODA.js from Oracle DB Examples - JavaScript - Nashorn

(ii) load testSODA.js in your schema using

        loadjava -r -v -user hr/hr testSODA.js

(iii) enable printing SQL output then invoke testSODA.js set serveroutput on call dbms_java.set_output(2000); call'testSODA.js');

From a database SQLPLUS session, issue the following call

sqlplus hr/hr @testSODAjs.sql

You should see the following output

 * Retrieving the first document by its key *

{ "name" : "Alex", "friends" : "50" }

* Retrieving documents representing users with at least 300 friends *

{ "name" : "Mia", "friends" : "300" }
{ "name" : "Gloria", "friends" : "399" }