SQL Oracle 中 varchar(max) 的等价物是什么?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/414817/
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-01 00:38:11  来源:igfitidea点击:

What is the equivalent of varchar(max) in Oracle?

sqlsql-serveroracle

提问by YourMomzThaBomb

What is the equivalent of varchar(max) in Oracle?

Oracle 中 varchar(max) 的等价物是什么?

CLOB?

克洛布?

采纳答案by cletus

Varchars are limited to 4000 characters in Oracle. Other than that, you have to use a LONG or a CLOB. Prefer CLOBs. LONGs are the older equivalent.

在 Oracle 中,Varchar 限制为 4000 个字符。除此之外,您必须使用 LONG 或 CLOB。首选 CLOB。LONG 是较旧的等价物。

From this Oracle documentation:

这个 Oracle 文档

LOBs vs. LONG and LONG RAW

LOBs are different from the older LONG and LONG RAW datatypes in many ways.

  • The maximum size of a LOB is 4 Gigabytes versus 2 Gigabytes for LONG and LONG RAW.
  • You can use random as well as sequential access methods on LOBs; you can only use sequential access methods on LONG and LONG RAW.
  • LOBs (except NCLOBs) can be attributes of an object type that you define.
  • Tables can have multiple LOB columns, but can have only one LONG or LONG RAW column.

Migration of existing LONG and LONG Raw attributes to LOBs is recommended by Oracle. Oracle plans to end support of LONG and LONG RAW in future releases. See Oracle8 Migration for more information on migration.

LOB 与 LONG 和 LONG RAW

LOB 在许多方面与旧的 LONG 和 LONG RAW 数据类型不同。

  • LOB 的最大大小为 4 GB,而 LONG 和 LONG RAW 为 2 GB。
  • 您可以对 LOB 使用随机和顺序访问方法;您只能在 LONG 和 LONG RAW 上使用顺序访问方法。
  • LOB(NCLOB 除外)可以是您定义的对象类型的属性。
  • 表可以有多个 LOB 列,但只能有一个 LONG 或 LONG RAW 列。

Oracle 建议将现有的 LONG 和 LONG Raw 属性迁移到 LOB。Oracle 计划在未来的版本中终止对 LONG 和 LONG RAW 的支持。有关迁移的更多信息,请参阅 Oracle8 迁移。

回答by Nick Pierpoint

As I understand it, a VARCHAR(MAX) data type is a SQL Server 2005 specific way of specifying a text field that can either be small (up to 8000 characters in SQL Server) orbig (up to 2GB in SQL Server). The database handles the change in storage behind the scenesas the content grows from the small range to the large range.

据我了解,VARCHAR(MAX) 数据类型是 SQL Server 2005 指定文本字段的特定方式,该文本字段可以小(SQL Server 中最多 8000 个字符)大(SQL Server 中最多 2GB)。随着内容从小范围增长到大范围,数据库处理幕后存储的变化。

There is no equivalent in Oracle.

Oracle 中没有等效项。

You either have a smallish bit of text in a VARCHAR2 - which is up to 32767 bytes in pl/sql and up to 4000 bytes in SQL (i.e. in a table definition) - or you have a potentially very big bit of text in a CLOB (which is a specialised BLOB).

你要么在 VARCHAR2 中有一小段文本——在 pl/sql 中最多 32767 个字节,在 SQL 中最多 4000 个字节(即在表定义中)——或者你在 CLOB 中有一个可能非常大的文本(这是一个专门的 BLOB)。

回答by Gary Myers

In PL/SQL, VARCHAR2 can be up to 32767 bytes. For SQL the limit is 4000 bytes (which may be less than 4000 characters if you are using a multi-byte character set).

在 PL/SQL 中,VARCHAR2 最多可以有 32767 个字节。对于 SQL,限制为 4000 字节(如果使用多字节字符集,则可能少于 4000 个字符)。

回答by Raymond de Vries

The Oracle 11g Gateway translates a Varchar(Max) to LONG Not very handy and causing major problems for our loading of SQL Server data into Oracle.

Oracle 11g 网关将 Varchar(Max) 转换为 LONG 不是很方便,并且会给我们将 SQL Server 数据加载到 Oracle 中造成重大问题。

See following url for more details:- http://docs.oracle.com/cd/B28359_01/gateways.111/b31049/apa.htm

有关更多详细信息,请参阅以下网址:- http://docs.oracle.com/cd/B28359_01/gateways.111/b31049/apa.htm

回答by Dave Markle

AFAIK, there is no equivalent. The closest you get in ORACLE is the CLOB, which has the same limitations that TEXT had in SQL Server back in the 'bad old days'.

AFAIK,没有等价物。您在 ORACLE 中获得的最接近的是 CLOB,它具有与 TEXT 在“糟糕的过去”的 SQL Server 中相同的限制。

回答by Dave Markle

An approach I have used in the past (MS SQL, prior to Varchar(max)):

我过去使用过的一种方法(MS SQL,在 Varchar(max) 之前):

Put two columns in the table, one smallish Varchar (255, for example), and another Text. Then build your application so that it will use the Varchar column for small data, leaving the Text null. If the data is larger than the Varchar, leave that null and store it in the Text. This way, small data doesn't take up its own page on the server. The tradeoff here is that all applications using the data have to agree to this scheme, and have logic to account for it. But it works well.

将两列放在表中,一列小 Varchar(例如 255),另一列 Text。然后构建您的应用程序,以便它将 Varchar 列用于小数据,而将 Text 保留为空。如果数据大于 Varchar,则保留该空值并将其存储在 Text 中。这样,小数据就不会在服务器上占据自己的页面。这里的权衡是所有使用数据的应用程序都必须同意这个方案,并且有逻辑来解释它。但它运作良好。

I presume the same is true in Oracle, just substiture Varchar2 for Varchar, and CLOB for Text. I don't pretend to know what the right size for the varchar should be - that's data dependent, and also depends on the rest of the columns in the table.

我认为在 Oracle 中也是如此,只是用 Varchar2 代替 Varchar,用 CLOB 代替 Text。我不假装知道 varchar 的正确大小应该是多少 - 这取决于数据,也取决于表中的其余列。

回答by bernd_k

There is noequivalent in Oracle up to 11g-r2. If you need it, migrate to another DMMS which supports it.

在11g-r2 之前的 Oracle 中没有等效项。如果需要,请迁移到另一个支持它的 DMMS。