How do I edit BLOBs (containing JSON text) in Oracle SQL Developer?
I can open and view them, but do I need an external editor to edit them? Any help on what to use, even if just notepad, and how to go about it would be greatly appreciated in the answer.
EDIT: BLOBs in question contain JSON text.
If you run a query in SQL Developer 3.1 (and probably earlier releases) that returns a BLOB, you can double-click on the particular BLOB you’re interested in where you’ll be prompted either to try to send the data to an external editor or to try to have the built-in SQL Developer display control attempt to interpret the data as an image or as text. Your JSON data will probably display correctly if you choose the text option.
If you want to change the data, however, you’re going to have to issue an
UPDATEto actually set the data. SQL Developer doesn’t have the functionality to directly edit the LOB data. For examplewill update the specified row with the new JSON data encoded using the database character set. If you want to store the data in some other character set,
string_to_rawtakes an optional second parameter that specifies the character set. So if you want to store the data using the UTF-8 character set, you’d do something like thisOf course, since JSON data is textual, you’d be far better off storing the data in a CLOB which is designed to store character large objects. Then SQL Developer (and other tools) could just display the text rather than requiring you to select the result and then take additional actions to convert it to text. And you wouldn’t have to convert the data to
RAWin order to update the data in the database.If the data is too long for
string_to_rawto handle (which depends on the character set and the data but will occur any time theRAWdata exceeds 2000 bytes), you can store the data in aCLOBand then convert that into aBLOBthat you use to update the table. That’s a bit more complex but it is more flexible. In this example, I’m padding the JSON data out to 3200 characters with a ‘*’– obviously the test data is no longer valid JSON but that’s not important for purposes of this question.