如何在Oracle中存储字节数组? [英] How to store an array of bytes in Oracle?
问题描述
我想在Oracle数据库中存储64个字节的短数组(密码哈希).我以为char(64 byte)
是我所需要的,但似乎不起作用.在Microsoft SQL中,我使用binary
和varbinary
类型.我需要在Oracle中使用哪种类型?
I want to store a short array of 64 bytes in Oracle database (a password hash). I thought char(64 byte)
is what I need, but it seems like it doesn't work. In Microsoft SQL, I use binary
and varbinary
types. What type do I need to use in Oracle?
我发现的每个示例都使用blob
存储二进制数据,但是我想blob
仅用于大型对象,而不用于固定大小的短数组.
Every example I've found uses blob
to store binary data, but I suppose blob
is intended only for large objects, not for fixed size short arrays.
在更新数据时,这样的代码是否合适:
When updating the data, is the code like this appropriate:
byte[] passwordHash = GenerateHash();
using (OracleCommand updateHash = new OracleCommand("update A set passwordHash = :hash where EntryId = :id", oracleConnection))
{
updateHash.Parameters.Add(":hash", passwordHash);
updateHash.Parameters.Add(":id", entryId);
if (updateHash.ExecuteNonQuery() != 1)
{
// ...
}
}
还是我丢失了某些东西,字节数组参数无法像这样添加?
or am I missing something and byte array parameters cannot be added like this?
推荐答案
除了blob
,Oracle还具有RAW
数据类型
In addition to blob
, Oracle also has the RAW
datatype,
RAW是一个可变长度的数据类型,例如 VARCHAR2
RAW is a variable-length datatype like VARCHAR2
RAW的最大大小可以设置为2000个字节,而LONG RAW
的最大大小可以为2GB.
RAW can be set up to a max size of 2000 bytes, with LONG RAW
having a max size of 2GB.
但是:
Oracle强烈建议您 将LONG RAW列转换为二进制 LOB(BLOB)列. LOB列是 受更少的限制 长列.
Oracle strongly recommends that you convert LONG RAW columns to binary LOB (BLOB) columns. LOB columns are subject to far fewer restrictions than LONG columns.
这篇关于如何在Oracle中存储字节数组?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!