0

I need to INSERT JSON data into the Oracle DB table BLOB column, also I need to SELECT the BLOB column value from the table?

This is my Query to INSERT:

INSERT INTO table_Name values('Test','test1',UTL_RAW.cast_to_raw ({"JSON data"}))

How can I SELECT? Also When inserting the large JSON object it's throwing Error : "PL/SQL: numeric or value error: raw variable length too long"

4
  • stackoverflow.com/questions/828650/… Commented Sep 26, 2018 at 13:02
  • If you can, avoid to store JSON data in one column, create a DB structure instead. Commented Sep 26, 2018 at 15:22
  • What is the DB structure? This is my requirement I want to store JSON into DB. Commented Sep 27, 2018 at 13:16
  • Possible duplicate of How do I get textual contents from BLOB in Oracle SQL Commented Oct 3, 2018 at 13:59

2 Answers 2

0
Try this:

create table demo
    ( id           int primary key,
      theBlob      blob
    );

INSERT INTO demo (id) values (1);

update demo set theBlob = utl_raw.cast_to_raw('Hello World') where id = 1;

commit;

select * from demo where id = 1;

select utl_raw.cast_to_varchar2(dbms_lob.substr(theBlob)) 
from demo 
where ID = '1';
Sign up to request clarification or add additional context in comments.

1 Comment

Want to store a large JSON object into a BLOB field, not a string?
0

That cast_to_raw takes a VARCHAR2 as a parameter and your string is too large. You need to open the BLOB and write it in pieces. It's all in the DBMS_LOB package.

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.