This site is currently read-only as we are migrating to Oracle Forums for an improved community experience. You will not be able to initiate activity until January 30th, when you will be able to use this site as normal.

    Forum Stats

  • 3,889,831 Users
  • 2,269,775 Discussions
  • 7,916,823 Comments

Discussions

sqlcl on windows. Error trying to execute javascript.

IOcampo
IOcampo Member Posts: 2
edited Apr 26, 2016 8:05PM in SQLcl

I'm using sqlcl trying to execute a javascript to upload files into blob field.

https://github.com/oracle/oracle-db-tools/blob/master/sqlcl/examples/blob.helper.all.js

DB connexion it's ok bet when I ran the script I receive the following error:

SQL> script load_file_to_db.js

javax.script.ScriptException: sun.org.mozilla.javascript.internal.EcmaError: ReferenceError: "load" is not defined. (<Unknown source>#1) in <Unknown source> at line number 1

My script:

load('https://raw.githubusercontent.com/oracle/Oracle_DB_Tools/master/sqlcl/lib/helpers.js');

/* File name */

var files= helpers.exec('find . -maxdepth 1 -type f ').stdout.split('\n');

/* bind for reuse */

var binds = helpers.getBindMap();

for(f in files ) {

    /* load the blob */

  blob = helpers.getBlobFromFile(files[f]);

  /* assign the binds */

  binds.put("path",files[f]);

  binds.put("b",blob);

/* Just do it */

  var ret = util.execute("insert into k(path,blob_content,when) values(:path , :b, sysdate)",binds);

}

Answers