Select in NODE returns empty

Asked

Viewed 48 times

0

When I run this query:

SELECT xml_nfe FROM NDD_COLD.COLD_PROD WHERE ide_id ='NFe42200602831172001104550000010390091233318028'

In plsql it returns me a line with information, then I pass the same query in the nodejs this way:

const dbConfig = require("./conexaoDBoracle.js");
const oracledb = require("oracledb");

class ConsultaXML {
async consultaXML() {

let connection;

try {

  connection = await oracledb.getConnection(dbConfig)

  let result = connection.execute(`SELECT xml_nfe FROM NDD_COLD.COLD_PROD WHERE ide_id ='NFe42200602831172001104550000010390091233318028'`);

  console.log((await result))
  return (await result).rows;

} catch (err) {

  console.error(err);
}
}
}
module.exports = new ConsultaXML;

and he returns it to me:

{ metaData: [ { name: 'XML_NFE' } ], rows: [] }

Does anyone have any idea what it might be?

  • You even tried to do this query using the bind pro ide_id?

  • after my connection I added the following: oracledb.fetchAsString = [oracledb.CLOB] , and the return of the method like this: const clob = (await result). Rows[0][0]; Return clob Because of the size of the return query, as per the oracle’s manual: https://blogs.oracle.com/opal/nodoracledb-112:-Working-with-lobs-as-string-and-buffer-Connection-Pinging

1 answer

0


Solved, due to the return of the query being very extensive I had to do the following

const dbConfig = require("./conexaoDBoracle.js");
const oracledb = require("oracledb");

class ConsultaXML {

async consultaXML(chave) {


let connection;


try {

  connection = await oracledb.getConnection(dbConfig)

  oracledb.fetchAsString = [oracledb.CLOB]

  let result = connection.execute(`SELECT XML_NFE AS XML
  FROM NDD_COLD.COLD_ENTR 
  WHERE IDE_ID = '${chave}'
  
  UNION ALL
  
  SELECT XML_NFE AS XML
  FROM NDD_COLD.COLD_PROD 
  WHERE IDE_ID = '${chave}'`);
  
  
  const clob = (await result).rows[0][0];

  
  return clob
  
} catch (err) {

  console.error(err);
}
}
}
module.exports = new ConsultaXML;

Browser other questions tagged

You are not signed in. Login or sign up in order to post.