Oracle BLOB vs VARCHAR

2019-06-17 11:41发布

I need to store a (large) SQL query in a column of a table and I thought using a BLOB field. To be clear, I want to store the query, not its result.

What's best to use: BLOB or a VARCHAR? Or something else maybe?

4条回答
兄弟一词,经得起流年.
2楼-- · 2019-06-17 12:10

Another option is CLOB. For text data it's more logical to use CLOB than BLOB. Even if you don't have to analyze the data within the database it might still make sense to use CLOB, because even viewing the data is easier.

Some features are only available using VARCHAR. For example, you can only create an index on VARCHAR columns (I'm not talking about fulltext index here, I know you can create a fulltext index on a CLOB column). You can't have a CLOB or BLOB primary key (I guess you don't need that; just as an example).

Most VARCHAR operations are much faster than CLOB / BLOB operations. Even reading data is faster if you use VARCHAR (unless there is really a lot of text in the column). VARCHAR needs less memory overhead, but they will usually be fully read in memory, so at the end VARCHAR might still use more memory.

查看更多
我命由我不由天
3楼-- · 2019-06-17 12:13

They are both different.

You use BLOB to store binary data like an image, audio and other multimedia data.

and VARCHAR to store text of any size up to the limit.

查看更多
孤傲高冷的网名
4楼-- · 2019-06-17 12:30

If you're going to store text data that can't fit in a VarChar2 then I think you're supposed to use a CLOB.

Quote from OraFaq: *A CLOB (Character Large Object) is an Oracle data type that can hold up to 4 GB of data. CLOB's are handy for storing text. *

查看更多
家丑人穷心不美
5楼-- · 2019-06-17 12:34

Short strings → VARCHAR

Long strings → CLOB

Binary data → BLOB

查看更多
登录 后发表回答