1

I am trying to read a BLOB data type from Oracle using a nodejs from npm package called oracledb and this is my select statement, it hold picture in it:

select media from test_data

I have tried using a few solution but it doesn't work.

Here is my response from the res.json:

{
        "MEDIA": {
            "_readableState": {
                "objectMode": false,
                "highWaterMark": 16384,
                "buffer": {
                    "head": null,
                    "tail": null,
                    "length": 0
                },
                "length": 0,
                "pipes": [],
                "flowing": null,
                "ended": false,
                "endEmitted": false,
                .....
   
    },

How do I get the hex value of it?

1
  • 1
    Please edit your question to include a minimal reproducible example with the node.js code you have attempted; the errors that you get and what your expected output is. Commented Mar 28, 2021 at 8:28

1 Answer 1

3

You are seeing an instance of the node-oracledb Lob class which you can stream from.

However, it can be easiest to get a Buffer directly. Do this by setting oracledb.fetchAsBuffer, for example:

oracledb.fetchAsBuffer = [ oracledb.BLOB ];

const result = await connection.execute(`SELECT b FROM mylobs WHERE id = 2`);

if (result.rows.length === 0)
  console.error("No results");
else {
  const blob = result.rows[0][0];
  console.log(blob.toString());  // assuming printable characters
}

Refer to the documentation Simple LOB Queries and PL/SQL OUT Binds.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.