Oracle DBMS_JAVASCRIPT
Version 19.3

General Information
Library Note Morgan's Library Page Header
For how many years have you been working with physical servers that are starving your database of the memory necessary to deploy important new performance features such as the Result Cache, Memoptimize Pool, In-Memory Aggregation, In-Memory Column Store, and Full Database Caching? Too long? Contact me to learn how to improve all queries ... not just some queries.
Purpose Used to execute a Java Script file stored in the file system.
AUTHID CURRENT_USER
Dependencies STANDARD only
Documented No
Exceptions
Error Code Reason
ORA-29532 Java call terminated by uncaught Java exception: java.lang.Error: No such resource found
First Available 12.2.0.1
Security Model Owned by SYS with EXECUTE granted to PUBIC
Source {ORACLE_HOME}/rdbms/admin/initdbj.sql
 
RUN
Run a java script dbms_javascript.run(script_name IN VARCHAR2);
exec dbms_javascript.run('/home/oracle/jscripts/uwprocess.js');
 
Demo
Full package demo -- create file and store at $ORACLE_HOME/rdbms/jlib
var Driver = Packages.oracle.jdbc.OracleDriver;
var oracleDriver = new Driver();
var url = "jdbc:default:connection:"; // server-side JDBC driver
var query ="SELECT first_name, last_name from employees";
// Establish a JDBC connection
var connection = oracleDriver.defaultConnection();
// Prepare statement
var preparedStatement = connection.prepareStatement(query);
// execute Query
var resultSet = preparedStatement.executeQuery();
// display results
while(resultSet.next()) {
print(resultSet.getString(1) + " == " + resultSet.getString(2) + " " );
}
// cleanup
resultSet.close();
preparedStatement.close();
connection.close();



SQL> CREATE ROLE c##nashorn;

Role created.

SQL> exec dbms_java.grant_permission('C##NASHORN', 'SYS:java.lang.RuntimePermission', 'createClassLoader', '' );

Call completed.

SQL> exec dbms_java.grant_permission('C##NASHORN', 'SYS:java.lang.RuntimePermission', 'getClassLoader', '' );

PL/SQL procedure successfully completed.

SQL> exec dbms_java.grant_permission('C##NASHORN', 'SYS:java.util.logging.LoggingPermission', 'control', '' );

PL/SQL procedure successfully completed.

GRANT c##nashorn TO hr;

Grant succeeded.

SQL> exec dbms_java.loadjava('-v -r rdbms/jlib/database.js');

PL/SQL procedure successfully completed.

SQL> hr/hr@orcl
SQL> serveroutput on
SQL> exec dbms_java.set_output(80000);
PL/SQL procedure successfully completed.

SQL> exec dbms_javascript.run('rdbms/jlib/database.js'); Dan == Morgan

PL/SQL procedure successfully completed.

SQL> exec dbms_java.dropjava('-s rdbms/jlib/database.js');

PL/SQL procedure successfully completed.

Related Topics
Built-in Functions
Built-in Packages
DBMS_JAVA
What's New In 18cR3
What's New In 19cR3

Morgan's Library Page Footer
This site is maintained by Dan Morgan. Last Updated: This site is protected by copyright and trademark laws under U.S. and International law. © 1998-2019 Daniel A. Morgan All Rights Reserved