2

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

/sql -LOGON 用户/密码@tnsname ./scripts/sql_script.sql 参数1

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

/sql>脚本脚本/js_script.js &1

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

/sql -LOGON 用户/密码@tnsname ./scripts/js_script.js 参数1

4

1 回答 1

3

我怎么还没有做到这一点?它现在在我的待办事项清单上。。

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

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

      })
于 2021-07-20T17:35:39.110 回答