oracle / node-oracledb

Oracle Database driver for Node.js maintained by Oracle Corp.
http://oracle.github.io/node-oracledb/
Other
2.26k stars 1.08k forks source link

ORA-01484: arrays can only be bound to PL/SQL statements #1405

Closed HarisMohre closed 3 years ago

HarisMohre commented 3 years ago

Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 Node v14.17.5. OracleDB Ver 5.2.0

Hi,

I cannot seem to INSERT a BLOB (Which is a base64 string) to the Oracle DB. I keep having the error:

ORA-01484: arrays can only be bound to PL/SQL statements

Surprisingly , I have all the Parameters saved as var and not a single array is being passed.

I am including the DB schema below:

Include all SQL needed to create the database schema.

   (    "FRID" NUMBER NOT NULL ENABLE, 
    "PERSONCODE" VARCHAR2(50 CHAR), 
    "SUBJECTID" VARCHAR2(100 CHAR), 
    "LOCALPATH" VARCHAR2(100 CHAR), 
    "BASE64DATA" BLOB, 
    "SUBJECT" VARCHAR2(200 BYTE), 
     CONSTRAINT "FACERECOGMAPPINGTABLE_PK" PRIMARY KEY ("FRID")
  USING INDEX PCTFREE 10 INITRANS 2 MAXTRANS 255 COMPUTE STATISTICS 
  STORAGE(INITIAL 65536 NEXT 1048576 MINEXTENTS 1 MAXEXTENTS 2147483645
  PCTINCREASE 0 FREELISTS 1 FREELIST GROUPS 1 BUFFER_POOL DEFAULT FLASH_CACHE DEFAULT CELL_FLASH_CACHE DEFAULT)
  TABLESPACE "MAIN_MOL"  ENABLE
   ) SEGMENT CREATION IMMEDIATE 
  PCTFREE 10 PCTUSED 40 INITRANS 1 MAXTRANS 255 NOCOMPRESS LOGGING
  STORAGE(INITIAL 65536 NEXT 1048576 MINEXTENTS 1 MAXEXTENTS 2147483645
  PCTINCREASE 0 FREELISTS 1 FREELIST GROUPS 1 BUFFER_POOL DEFAULT FLASH_CACHE DEFAULT CELL_FLASH_CACHE DEFAULT)
  TABLESPACE "MAIN_MOL" 
 LOB ("BASE64DATA") STORE AS BASICFILE (
  TABLESPACE "MAIN_MOL" ENABLE STORAGE IN ROW CHUNK 8192 RETENTION 
  NOCACHE LOGGING 
  STORAGE(INITIAL 65536 NEXT 1048576 MINEXTENTS 1 MAXEXTENTS 2147483645
  PCTINCREASE 0 FREELISTS 1 FREELIST GROUPS 1 BUFFER_POOL DEFAULT FLASH_CACHE DEFAULT CELL_FLASH_CACHE DEFAULT)) ;

  CREATE OR REPLACE TRIGGER "MOL"."FACERECOGMAPPINGTABLE_TRG" 
BEFORE INSERT ON FACERECOGMAPPINGTABLE 
FOR EACH ROW 
BEGIN
  <<COLUMN_SEQUENCES>>
  BEGIN
    NULL;
  END COLUMN_SEQUENCES;
END;
/
ALTER TRIGGER "MOL"."FACERECOGMAPPINGTABLE_TRG" ENABLE; 

------------------------------------ Node.js Code --------------------------------

import oracledb from 'oracledb';

var oopcode = "1234567";
var subjectId = "3123-123123-3123123-AW21312-FDSD";
var FinalImagePath = "\\asdsad\dsdasd\asdsad\test.jpg";
var blobvalue = Buffer.from(soapBody.downloadFileResponse.downloadFileResult);
var subjectId = json.image_id;

connection.execute("INSERT INTO mol.FACERECOGMAPPINGTABLE (PERSONCODE, SUBJECTID, LOCALPATH, BASE64DATA, SUBJECT) VALUES (:opcode, :osubid, :oimpath, :ob64data, :osubname)",
  {
    opcode: oopcode,
    osubid: subjectId,
    oimpath: FinalImagePath,
    ob64data: {val: blobvalue, type: oracledb.BUFFER, dir: oracledb.BIND_IN},
    osubname: oopcode
  }, function(err, result) {
  if (err) { console.error(err.message);
        doRelease(connection);
        return;
   }
   doRelease(connection);
  });

I Have tried everything and I keep getting the error saying arrays can only be bound to PL/SQL statements. It would be nice if you can help me here.

Thanks, Harry

HarisMohre commented 3 years ago

Found the solution,

I had to convert all the Parameters (apart from the BLOB) to String for some reason. Here is the final Code:

connection.execute("INSERT INTO mol.FACERECOGMAPPINGTABLE (PERSONCODE, SUBJECTID, LOCALPATH,BASE64DATA, SUBJECT) VALUES (:opcode, :osubid, :oimpath, :OB64DATA, :osubname)", //connection.execute('BEGIN INSERTINTOFACERECOGTABLE(:OPCODE, :OSUBID, :OIMPATH , :OB64DATA , :OSUBNAME); END;', { OPCODE: String(oopcode), OSUBID: String(subjectId), OIMPATH: String(FinalImagePath), // ob64data: {val: blobvalue, type: oracledb.BUFFER, dir: oracledb.BIND_IN}, OB64DATA: blobvalue, OSUBNAME: String(oopcode) }