表中有一个字段 email , 约束位 unique表中 有一条记录 [email protected]现在 要插入 另一个 email:  [email protected]结果报错,提示 违反 约束, 因为 在oracl 插入 [email protected] 会以类似下面的sql去查询是否已经有相同的email
select * from table where email like '[email protected]' ,在这条sql 中 _ 是个通配符,匹配任意一个字符,所以 会找到 [email protected], 产生了冲突这个问题要怎么解决?

解决方案 »

  1.   

    SQL> select 1 from dual where '[email protected]' like '[email protected]';         1
    ----------
             1
    SQL> select 1 from dual where '[email protected]' like replace('[email protected]','_','\_') escape '\';未选定行SQL>
      

  2.   

    select * from table where email like 'aa[_][email protected]'
      

  3.   

    我的问题是 在 表里有 [email protected] 这个用户时,怎么插入 [email protected]这个用户而不报错insert into table (email) values ([email protected])  这里面怎么用通配符?
      

  4.   

    奇怪,我用下面的代码在oracle上试了一下,好像没问题呀。是不是你oracle数据库的版本比较老。
    CREATE TABLE test5
    (
    USER_NAME VARCHAR2(60) NOT NULL
    )CREATE UNIQUE INDEX test5_idx ON test5(USER_NAME)insert into test5 values('a.b')
    insert into test5 values('a_b')
    insert into test5 values('aa.bb.com')
    insert into test5 values('aa_bb.com')
      

  5.   

    insert into TEST (EMAIL) values('aa'||chr(95)||'[email protected]')chr(95) = '_'
      

  6.   

    oracle有通配字符,也有转义字符,比如 ',''表示一个'
    通配字符如果一定要用,可用ASCII码代替。
      

  7.   

    你用的是什么版本的,
    我在9I中试过了
    insert into table (email) values ('[email protected]');
    可以通过 
    除了在WHERE后面的'_'代表通配符,其它地方可以当正常的字符使用