I know that I can run an sql file directly from the command line as follows:
/sql -LOGON user/password@tnsname ./scripts/sql_script.sql parameter1
And I know that I can call a javascript program from within the sqlcl shell as follows:
/sql>script scripts/js_script.js &1
The question is do I have to use the sql-wrapper script, or how can I run the javascript directly from the command line without the wrapper as follows:
/sql -LOGON user/password@tnsname ./scripts/js_script.js parameter1
How have I not made that possible yet?? It's now on my todo list..
In the meantime you could do something like this.
➜ examples echo "script lsEngines.js" | sql klrice/klrice
SQLcl: Release 21.3 Production on Tue Jul 20 13:33:26 2021
Copyright (c) 1982, 2021, Oracle. All rights reserved.
Last Successful login time: Tue Jul 20 2021 13:33:28 -04:00
Connected to:
Oracle Database 19c Enterprise Edition Release 19.0.0.0.0 - Production
Version 19.3.0.0.0
login.sql found in the CWD. DB access is restricted for login.sql.
Adjust the SQLPATH to include the path to enable full functionality.
ScriptEngineFactory Info
jdk.nashorn.api.scripting.NashornScriptEngineFactory@373f7450
Script Engine: Oracle Nashorn (14.0.2)
Engine Alias: nashorn
Engine Alias: Nashorn
Engine Alias: js
Engine Alias: JS
Engine Alias: JavaScript
Engine Alias: javascript
Engine Alias: ECMAScript
Engine Alias: ecmascript
Language: ECMAScript (ECMA - 262 Edition 5.1)
Disconnected from Oracle Database 19c Enterprise Edition Release 19.0.0.0.0 - Production
Version 19.3.0.0.0
Where my "lsEngines.js" is this content
var ScriptEngineManager = Java.type("javax.script.ScriptEngineManager")
mgr = new ScriptEngineManager();
var factories = mgr.getEngineFactories();
factories.forEach(function(factory) {
ctx.write("ScriptEngineFactory Info\n" + factory.toString() + "\n");
var engName = factory.getEngineName();
var engVersion = factory.getEngineVersion();
var langName = factory.getLanguageName();
var langVersion = factory.getLanguageVersion();
ctx.write("\tScript Engine: "+engName+" ("+engVersion+")\n");
var engNames = factory.getNames();
engNames.forEach(function(name) {
ctx.write("\tEngine Alias: "+ name + "\n");
})
ctx.write("\tLanguage: "+langName+" ("+langVersion+")\n");
})