Skip to content Skip to sidebar Skip to footer

NPM Oracle: Inserting BLOBs

I am trying to use the NPM oracle library and update some tables with BLOB values created from files on my computer. Oracle documentation says to use the createLob() function like

Solution 1:

Based on your use case (small files and limited concurrency), I think the buffer APIs will be the best bet as they are very simple. From the doc:

Given the table:

CREATE TABLE mylobs (id NUMBER, c CLOB, b BLOB);

an INSERT example is:

var fs = require('fs');
var str = fs.readFileSync('example.txt', 'utf8');
. . .

conn.execute(
  `INSERT INTO mylobs (id, myclobcol) VALUES (:idbv, :cbv)`,
  { idbv: 1,
    cbv: str },  // type and direction are optional for IN binds
  function(err, result) {
    if (err)
      console.error(err.message);
    else
      console.log('CLOB inserted from example.txt');
. . .

Also, in case you ever need it, I'm wrapping up a mini-series on this topic but it's framed more around web server uploads: https://jsao.io/2019/06/uploading-and-downloading-files-with-node-js-and-oracle-database/


Post a Comment for "NPM Oracle: Inserting BLOBs"