如何让Oracle不区分大小写

发布于 2024-08-31 23:57:52 字数 240 浏览 1 评论 0原文

Oracle 10g 中是否有设置将数据视为不区分大小写?我在此处看到了一个解决方案。然而,这是在会话中完成的。我正在寻找的是模式或表上的设置,以将其数据视为不区分大小写。如果是在会话上,那么我将不得不对所有存储过程进行更改。

Is there be a setting in Oracle 10g to consider data as case insensitive? I saw a solution here. However, that is done on a session. What I am looking for is a setting either on a schema or on a table to consider its data as case insensitive. If it is on a session then I will have to make the change on all the stored procedures.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(2

恰似旧人归 2024-09-07 23:57:52

没有选项可以使架构或表“不区分大小写”。

  • 您可以使用 NLS_ 参数在会话上执行此操作,或者在影响整个实例的数据库初始化文件中执行相同操作。
    但是这些搜索仅不区分大小写用于严格相等搜索。

  • 如果您需要使用 LIKE,则需要考虑使用 REGEXP_LIKE。
    对于 REGEXP_LIKE,您不需要 NLS_SORT 设置,因为 REGEXP_LIKE 有一个选项可以让它考虑不区分大小写的事物。

There is no option to make a schema or table 'case insensitive'.

  • You can do that on the session using the NLS_ parameters or do the same in the db init file where the whole instance is affected.
    However those searches are only case-insensitive for strict equality searches.

  • If you need to use LIKE you then need to consider using REGEXP_LIKE.
    In the case of REGEXP_LIKE you don't need an NLS_SORT setting because there is an option for REGEXP_LIKE to have it consider things case insensitive.

就此别过 2024-09-07 23:57:52

区分大小写是计算的基础,原因很简单,“yun”的 ASCII 值!=“YUN”的 ASCII 值。所以,当你说...

将数据视为不区分大小写

...您的意思是仅用于搜索还是存储?

在每次搜索中强制执行大小写的问题是:

SQL> create table t23 (id number, name varchar2(20))
  2  /

Table created.

SQL> create unique index  t23_uk on t23(name)
  2  /

Index created.

SQL> insert into t23 values (1, 'SAM-I-AM')
  2  /

1 row created.

SQL> insert into t23 values (2, 'sam-i-am')
  2  /

1 row created.

SQL> select id, name, ascii(name) from t23
  2  /

        ID NAME                 ASCII(NAME)
---------- -------------------- -----------
         1 SAM-I-AM                      83
         2 sam-i-am                     115

SQL>

如果在模式或表级别强制执行不区分大小写的搜索,我们如何区分“sam-I-am”和“SAM-I-AM”?

尽管是在单个列级别,但在某种程度上可以强制数据存储不区分大小写:

SQL> delete from t23
  2  /

2 rows deleted.

SQL> drop index t23_uk
  2  /

Index dropped.

SQL> create unique index  t23_uk on t23(upper(name))
  2  /

Index created.

SQL> insert into t23 values (1, 'SAM-I-AM')
  2  /

1 row created.

SQL> insert into t23 values (2, 'sam-i-am')
  2  /
insert into t23 values (2, 'sam-i-am')
*
ERROR at line 1:
ORA-00001: unique constraint (APC.T23_UK) violated


SQL>

Case sensitivity is fundamental to computing, for the simple reason that the ASCII value of 'yun' != the ASCII value of 'YUN'. So, when you say ...

consider data as case insensitive

... do you mean just for the purposes of search or for storage as well?

The problem with enforcing case on every search is this:

SQL> create table t23 (id number, name varchar2(20))
  2  /

Table created.

SQL> create unique index  t23_uk on t23(name)
  2  /

Index created.

SQL> insert into t23 values (1, 'SAM-I-AM')
  2  /

1 row created.

SQL> insert into t23 values (2, 'sam-i-am')
  2  /

1 row created.

SQL> select id, name, ascii(name) from t23
  2  /

        ID NAME                 ASCII(NAME)
---------- -------------------- -----------
         1 SAM-I-AM                      83
         2 sam-i-am                     115

SQL>

If case insensitive searches are enforced at the schema or table level how can we ever distinguish 'sam-I-am' from 'SAM-I-AM'?

It is - sort of - possible to enforce case-insensitivity for data storage, albeit at the individual column level:

SQL> delete from t23
  2  /

2 rows deleted.

SQL> drop index t23_uk
  2  /

Index dropped.

SQL> create unique index  t23_uk on t23(upper(name))
  2  /

Index created.

SQL> insert into t23 values (1, 'SAM-I-AM')
  2  /

1 row created.

SQL> insert into t23 values (2, 'sam-i-am')
  2  /
insert into t23 values (2, 'sam-i-am')
*
ERROR at line 1:
ORA-00001: unique constraint (APC.T23_UK) violated


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