我们可以直接从命令行在 sqlcl 中 运行 javascript,还是需要 sql 包装脚本?

Can we run javascript in sqlcl directly from command line, or do we need an sql wrapper script?

我知道我可以 运行 一个 sql 文件直接从命令行如下:

/sql -LOGON user/password@tnsname ./scripts/sql_script.sql parameter1

而且我知道我可以从 sqlcl shell 中调用 javascript 程序,如下所示:

/sql>script scripts/js_script.js &1

问题是我是否必须使用 sql-wrapper 脚本,或者如何在没有包装器的情况下直接从命令行 运行 javascript,如下所示:

/sql -LOGON user/password@tnsname ./scripts/js_script.js parameter1

我怎么还没有做到这一点??它现在在我的待办事项列表中..

同时你可以做这样的事情。

➜  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

我的“lsEngines.js”是这个内容

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");

      })