为什么oracle区分大小写?

发布于 2024-12-04 10:04:18 字数 244 浏览 1 评论 0原文

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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(5

装迷糊 2024-12-11 10:04:18

默认情况下,Oracle 标识符(表名、列名等)不区分。您可以通过在它们周围使用引号来使它们区分大小写(例如:SELECT * FROM "My_Table" WHERE "my_field" = 1)。 SQL 关键字(SELECTWHEREJOIN 等)始终不区分大小写。

另一方面,字符串比较区分大小写(例如:WHERE field='STRING' 将仅匹配 'STRING' 的列) 默认情况下。您可以通过将 NLS_COMPNLS_SORT 设置为适当的值(例如:LINGUISTICBINARY_CI)来使它们不区分大小写。 , 分别)。

注意:查询数据字典视图(例如:dba_tables)时,如果您创建的数据字典视图不带引号,则名称将为大写,并且将应用第二段中解释的字符串比较规则在这里。

某些数据库(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 setting NLS_COMP and NLS_SORT to the appropriate values (eg: LINGUISTIC and BINARY_CI, respectively).

Note: When inquiring data dictionary views (eg: dba_tables) the names will be in upper-case if you created them without quotes, and the string comparison rules as explained in the second paragraph will apply here.

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.

记忆で 2024-12-11 10:04:18

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.

淤浪 2024-12-11 10:04:18

请记住,对于 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.

紫南 2024-12-11 10:04:18

如果我必须猜测,我会说出于历史/向后兼容性的原因。

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.

生死何惧 2024-12-11 10:04:18

对于某些应用程序,区分大小写很重要,而对于其他应用程序则不然。无论您使用哪种 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".

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文