如何在 Oracle SQL Developer 中编辑 BLOB(包含 JSON)?
如何在 Oracle SQL Developer 中编辑 BLOB(包含 JSON 文本)?
我可以打开并查看它们,但我需要外部编辑器来编辑它们吗?任何有关使用什么(即使只是记事本)以及如何进行操作的帮助都将在答案中得到极大的赞赏。
编辑:有问题的 BLOB 包含 JSON 文本。
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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
如果您在 SQL Developer 3.1(可能还有早期版本)中运行返回 BLOB 的查询,则可以双击您感兴趣的特定 BLOB,系统将提示您尝试将数据发送到外部编辑器或尝试让内置 SQL Developer 显示控件尝试将数据解释为图像或文本。如果您选择文本选项,您的 JSON 数据可能会正确显示。
但是,如果您想更改数据,则必须发出
UPDATE
才能实际设置数据。 SQL Developer 不具有直接编辑 LOB 数据的功能。例如,将使用数据库字符集编码的新 JSON 数据更新指定行。如果您想以其他字符集存储数据,
string_to_raw
采用指定字符集的可选第二个参数。因此,如果您想使用 UTF-8 字符集存储数据,您可以这样做当然,由于 JSON 数据是文本的,因此最好将数据存储在 CLOB 中,该 CLOB 旨在存储字符大型物体。然后,SQL Developer(和其他工具)可以只显示文本,而不需要您选择结果,然后采取其他操作将其转换为文本。而且您不必将数据转换为
RAW
即可更新数据库中的数据。如果数据太长,
string_to_raw
无法处理(这取决于字符集和数据,但只要RAW
数据超过 2000 字节就会发生),您可以存储CLOB
中的数据,然后将其转换为用于更新表的BLOB
。这有点复杂,但更灵活。在此示例中,我使用“*”将 JSON 数据填充到 3200 个字符——显然测试数据不再是有效的 JSON,但这对于本问题而言并不重要。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
UPDATE
to 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_raw
takes 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
RAW
in order to update the data in the database.If the data is too long for
string_to_raw
to handle (which depends on the character set and the data but will occur any time theRAW
data exceeds 2000 bytes), you can store the data in aCLOB
and then convert that into aBLOB
that 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.如果您希望在不编写任何 SQL 的情况下更改单个 Blob,则可以在 Oracle SQL Developer 中执行此操作:
(BLOB)
的单元格。编辑按钮(图标为铅笔)应出现在单元格的右侧。单击它。下载
。将其保存在某处。加载
。找到编辑后保存的文件。现在单击“编辑值”对话框中的确定
。提交更改
按钮;如果您改变主意,请点击回滚更改
按钮。我认为,如果这只是一个快速的一次性事情,那么比执行整个 dbms_lob.convertToBlob 容易得多。
If you're looking to change individual blobs without having to write any SQL, you can do this in Oracle SQL Developer:
(BLOB)
. An edit button (pencil for an icon) should appear to the right side of the cell. Click on it.Download
, to the right of Saved Data. Save it somewhere.Load
, to the right of Local Data. Find the file wherever you saved it after editing. ClickOK
in the Edit Value dialog now.Commit Changes
button if you're satisfied with your changes, or theRollback Changes
button if you've changed your mind.Much easier, I think, than doing the whole
dbms_lob.convertToBlob
if this is just a quick one-off thing.