为什么要使用除VARCHAR2(4000)之外的其他任何东西可以将字符串存储在Oracle数据库中? [英] Why using anything else but VARCHAR2(4000) to store strings in an Oracle database?
问题描述
I found an Ask Tom article explaining that there is not much difference between CHAR and VARCHAR2 in Oracle. It gave the impression that I should use VARCHAR2(4000 BYTE) for every column where I would like to store strings, even for ISO 639-1 language codes, because it does not make any difference.
我知道使用CHAR(2)进行ISO 639-1语言代码来强制执行基本的数据约束是有道理的。但这并不是一个充分的约束,因为它允许在不是有效的语言代码的列中存储'xy'
。另一方面,我支付这个基本约束,限制我必须更改数据库,如果我想更改我的应用程序使用ISO 639-2语言代码,需要3个字符。所以我倾向于从数据库级别中删除约束,因为在我看来,成本高于收益。
I know that it makes sense to use CHAR(2) for ISO 639-1 language codes to enforce a basic data constraint. But this is not a sufficient constraint, because it permits storing 'xy'
in the column which is not a valid language code. On the other side I pay for this basic constraint with the limitation that I have to change the database if I want to change my application to use ISO 639-2 language codes, which require 3 characters. So I tend to drop the constraint at all from the database level, because it seems to me that the cost is higher than the benefit.
考虑到这一点,我想知道是否有任何其他重要的原因,为什么我不应该使用VARCHAR2(4000 BYTE)任何短于4000字节的字符串,我打算存储在Oracle数据库中?
With that in mind, I am wondering if there is any other significant reason why I should not use VARCHAR2(4000 BYTE) for any string shorter than 4000 bytes that I intend to store in an Oracle database?
推荐答案
汤姆·凯特也反驳了你的命题: https://asktom.oracle.com/pls/asktom/f?p=100:11:0::::P11_QUESTION_ID:1145132537055
Tom Kyte also rebuts your proposition here: https://asktom.oracle.com/pls/asktom/f?p=100:11:0::::P11_QUESTION_ID:1145132537055
这篇关于为什么要使用除VARCHAR2(4000)之外的其他任何东西可以将字符串存储在Oracle数据库中?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!