2015-12-14 144 views
0

有沒有什麼方法可以設置表或字段忽略大小寫?我不想使用較低或較高的功能。如果他們不支持忽略大小寫,我對它感到震驚,但我仍然在尋找,但我沒有找到任何解決方案在Oracle 11g中忽略大小寫

回答

1

正如你所說的,你不能明確地創建一個「不區分大小寫」的列。

但是,您可以通過使用虛擬列,觸發器,檢查約束或僅使用不區分大小寫的謂詞和上/下函數來查詢它。

一些例子:

Connected to Oracle Database 11g Enterprise Edition Release 11.2.0.4.0 
Connected as [email protected] 

SQL> 
SQL> create table job (JOB_TITLE varchar2(40)); 
Table created 
SQL> alter table job add constraint ck_job_upper check (job_title = upper(job_title)); 
Table altered 
SQL> insert into job values ('clerk'); 
insert into job values ('clerk') 
ORA-02290: restrição de verificação (FSITJA.CK_JOB_UPPER) violada 
SQL> insert into job values ('CLERK'); 
1 row inserted 
SQL> commit; 
Commit complete 
SQL> create or replace trigger tr_br_upper_job_title before insert or update of job_title on job 
    2 for each row 
    3 begin 
    4 :new.job_title := upper(:old.job_title); 
    5 end; 
    6/
Trigger created 
SQL> insert into job values ('clerk'); 
1 row inserted 
SQL> select * from job; 
JOB_TITLE 
---------------------------------------- 
CLERK 

SQL> commit; 
Commit complete 

SQL> 
SQL> drop table job; 
Table dropped 
SQL> create table job (JOB_TITLE varchar2(40), upper_job_t as (upper(job_title))); 
Table created 
SQL> insert into job (job_title) values ('CLERK'); 
1 row inserted 
SQL> insert into job (job_title) values ('clerk'); 
1 row inserted 
SQL> commit; 
Commit complete 
SQL> select * from job where regexp_like(job_title, 'CLERK', 'i'); 
JOB_TITLE        UPPER_JOB_T 
---------------------------------------- ---------------------------------------- 
CLERK         CLERK 
clerk         CLERK 

SQL> 
+0

我還是從Oracle震驚,當我完成我的項目,我將返回到SQL服務器 –