Oracle BLOB 与 VARCHAR

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/3683582/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-18 21:29:41  来源:igfitidea点击:

Oracle BLOB vs VARCHAR

sqloracletypesblobvarchar

提问by CC.

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

我需要在表的一列中存储一个(大)SQL 查询,我想使用一个BLOB字段。明确地说,我想存储查询,而不是它的结果。

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

最好使用什么:BLOBVARCHAR? 或者别的什么?

回答by Hans Olsson

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

如果您要存储无法放入 a 的文本数据,VarChar2那么我认为您应该使用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. *

从报价OraFaq:* A CLOB(字符大对象)是可以容纳多达4 GB数据的Oracle数据类型。CLOB 可以方便地存储文本。*

回答by Thomas Mueller

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.

另一种选择是 CLOB。对于文本数据,使用 CLOB 比使用 BLOB 更合乎逻辑。即使您不必分析数据库中的数据,使用 CLOB 可能仍然有意义,因为即使查看数据也更容易。

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).

某些功能仅在使用 VARCHAR 时才可用。例如,您只能在 VARCHAR 列上创建索引(我在这里不是在谈论全文索引,我知道您可以在 CLOB 列上创建全文索引)。您不能拥有 CLOB 或 BLOB 主键(我猜您不需要那个;仅作为示例)。

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.

大多数 VARCHAR 操作比 CLOB / BLOB 操作快得多。如果使用 VARCHAR,即使读取数据也会更快(除非列中确实有很多文本)。VARCHAR 需要较少的内存开销,但它们通常会在内存中完全读取,因此最终 VARCHAR 可能仍会使用更多内存。

回答by PaulJWilliams

Short strings → VARCHAR

短字符串 → VARCHAR

Long strings → CLOB

长字符串 → CLOB

Binary data → BLOB

二进制数据 → BLOB

回答by codaddict

They are both different.

他们都是不同的。

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

您用于BLOB存储二进制数据,如图像、音频和其他多媒体数据。

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

VARCHAR存储任意大小的文本到限制。