为什么oracle区分大小写?
Oracle 区分大小写,而 SQL Server 和 MySQL 等其他数据库默认情况下不区分大小写,这是否有原因?
我知道有一些方法可以启用/禁用区分大小写,但 Oracle 的不同似乎很奇怪来自其他数据库。
我还试图了解区分大小写的原因。我可以看到“Table”和“TaBlE”在哪里可以被认为是等效的,但是否有一个例子,区分大小写实际上会产生影响?
我对数据库有点陌生,目前正在上课。
Is there a reason why Oracle is case sensitive and others like SQL Server, and MySQL are not by default?
I know that there are ways to enable/disable case sensitivity, but it just seems weird that oracle differs from other databases.
I'm also trying to understand reasons for case sensitivity. I can see where "Table" and "TaBlE" can be considered equivalent and not equivalent, but is there an example where case sensitivity would actually make a difference?
I'm somewhat new to databases and am currently taking a class.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
默认情况下,Oracle 标识符(表名、列名等)不区分。您可以通过在它们周围使用引号来使它们区分大小写(例如:
SELECT * FROM "My_Table" WHERE "my_field" = 1
)。 SQL 关键字(SELECT
、WHERE
、JOIN
等)始终不区分大小写。另一方面,字符串比较区分大小写(例如:
WHERE field='STRING'
将仅匹配'STRING'
的列) 默认情况下。您可以通过将NLS_COMP
和NLS_SORT
设置为适当的值(例如:LINGUISTIC
和BINARY_CI
)来使它们不区分大小写。 , 分别)。某些数据库(Oracle、IBM DB2、PostgreSQL 等)默认执行区分大小写的字符串比较,而其他数据库(SQL Server、MySQL、SQLite)则不区分大小写。无论如何,这都不是标准的,因此请注意您的数据库设置是什么。
By default, Oracle identifiers (table names, column names, etc.) are case-insensitive. You can make them case-sensitive by using quotes around them (eg:
SELECT * FROM "My_Table" WHERE "my_field" = 1
). SQL keywords (SELECT
,WHERE
,JOIN
, etc.) are always case-insensitive.On the other hand, string comparisons are case-sensitive (eg:
WHERE field='STRING'
will only match columns where it's'STRING'
) by default. You can make them case-insensitive by settingNLS_COMP
andNLS_SORT
to the appropriate values (eg:LINGUISTIC
andBINARY_CI
, respectively).Some databases (Oracle, IBM DB2, PostgreSQL, etc.) will perform case-sensitive string comparisons by default, others case-insensitive (SQL Server, MySQL, SQLite). This isn't standard by any means, so just be aware of what your db settings are.
Oracle 实际上以不区分大小写的方式处理字段和表名称,除非您在标识符周围使用引号。如果创建名称周围不带引号的表,例如 CREATE MyTable...,则生成的表名称将转换为大写(即 MYTABLE),并以不区分大小写的方式处理。 SELECT * from MYTABLE、SELECT * from MyTable、SELECT * from myTabLe 都将与 MYTABLE 匹配(请注意表名周围缺少引号)。这是一篇关于这个问题的好文章,它更详细地讨论了这个问题并比较了数据库。
Oracle actually treats field and table names in a case-insensitive manner unless you use quotes around identifiers. If you create a table without quotes around the name, for example CREATE MyTable..., the resulting table name will be converted to upper case (i.e. MYTABLE) and will be treated in a case insensitive manner. SELECT * from MYTABLE, SELECT * from MyTable, SELECT * from myTabLe will all match MYTABLE (note the lack of quotes around the table name). Here is a nice article on this issue that discusses this issue in more detail and compares databases.
请记住,对于 SQL Server,区分大小写是基于排序规则的。默认排序规则不区分大小写 - 但可以将其更改为区分大小写。一个类似的例子是,当使用非 ASCII 字符的全球应用程序需要 UTF 时,为什么默认的 Oracle 数据库使用西欧字符集?我认为这只是供应商的偏好。
Keep in mind too for SQL Server the case sensitivity is based on the collation. The default collation is case insensitive - but this could be changed to be case sensitive. A similar example is why do the default Oracle databases use a Western European character set when UTF is required for global applications that use non ASCII characters? I think it's just a vendor preference.
如果我必须猜测,我会说出于历史/向后兼容性的原因。
Oracle 于 1977 年首次问世,当时的技术计算成本可能很高为不区分大小写的搜索做额外的工作,所以他们只是选择完全匹配。
If I had to guess, I'd say for historical/backwards-compatibility reasons.
Oracle first came out in 1977, and it was likely computationally expensive with the technology at the time to do the extra work for case-insensitive searches, so they just opted for exact matches.
对于某些应用程序,区分大小写很重要,而对于其他应用程序则不然。无论您使用哪种 DBMS,业务需求都应该决定您是否需要区分大小写。我不会太担心“默认”。
For some applications case-sensitivity is important and for others it isn't. Whichever DBMS you use, business requirements should determine whether you need case-senitivity or not. I wouldn't worry too much about the "default".