SQL Oracle 中的 VARCHAR(MAX) 与 VARCHAR(n)
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/1668606/
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
VARCHAR(MAX) versus VARCHAR(n) in Oracle
提问by Aaron Fi
回答by Tony Andrews
Because it doesn't work in Oracle! You coulddeclare all columns as VARCHAR2(4000) if you wanted, but it isn't recommended by any means. There will be no difference in storage or performance of the database, but:
因为它在 Oracle 中不起作用!如果需要,您可以将所有列声明为 VARCHAR2(4000),但无论如何都不建议这样做。数据库的存储或性能不会有差异,但是:
- you lose a constraint on the sensible values that can be stored in the column
- some client applications will allocate 4000 bytes of memory to receive data from the column when (say) 10 is all it will ever contain.
- 你失去了对可以存储在列中的合理值的约束
- 某些客户端应用程序将分配 4000 字节的内存来从列接收数据,当(例如)10 是它将包含的全部内容时。
回答by Quassnoi
Probably because Oracle
does not support VARCHAR(MAX)
.
可能是因为Oracle
不支持VARCHAR(MAX)
。
VARCHAR
should not be used in Oracle
at all.
VARCHAR
根本不应该使用Oracle
。
As for now, it's a synonym for VARCHAR2
, but it may change in future so that it will distinguish between an empty string and a NULL
.
至于现在,它是 的同义词VARCHAR2
,但将来可能会发生变化,以便区分空字符串和NULL
。
VARCHAR
is supposed to do it but doesn't in current versions of Oracle
, and hence should not be used.
VARCHAR
应该这样做,但在当前版本中没有Oracle
,因此不应使用。
In Oracle
, maximum length for a VARCHAR2
is 4000
in SQL
and 32767
in PL/SQL
.
In Oracle
, a 的最大长度VARCHAR2
是4000
inSQL
和32767
in PL/SQL
。
For larger values, you should use CLOB
, but it's very different from a VARCHAR2
. You should use special methods to access it, etc.
对于较大的值,您应该使用CLOB
,但它与VARCHAR2
. 您应该使用特殊方法来访问它等。
回答by OMG Ponies
For starters, Oracle doesn't havea VARCHAR(MAX) datatype
对于初学者来说,Oracle不会有一个VARCHAR(MAX)数据类型
Reference:
参考: