我在oracle9i中打算用转义字符,可是碰到了奇怪的问题请教一下:问题如下:
我使用
select * from t_photo where tph_memo like '%\_%' ESCAPE '\';的时候提示
错误ORA-01425,可是明明是一个字符呀。
然后我换成
select * from t_photo where tph_memo like '%\\%%' ESCAPE '\\';就不提示错误了
可是查询结果不正确,不能查出任何数据。请大虾帮忙解释一下?我的数据库安装的时候
使用的是unicode32,我怀疑是不是和这个有关系。请问如何才能解决。

解决方案 »

  1.   

    select * from t_photo where tph_memo like '%\_%' ESCAPE '\';你可以不用'\'的啊,其他字符都可以:
    select * from t_photo where tph_memo like '%#_%' ESCAPE '#';
      

  2.   

    没遇到过这种情况,实在不行就用instr吧
    select * from t_photo where instr(tph_memo,'_') >0;
      

  3.   

    ORA-01425: 换码符必须是长度为 1 的字符串你再试试下面的方法:
    select * from t_photo where tph_memo like '%' || chr(0) || '_%' escape chr(0);
      

  4.   

    强烈建议使用函数chr()来获取特殊字符。
    比如"&"等
      

  5.   

    我用duanzilin(寻)大虾的方法试过了,可是问题仍然存在;
    用select * from t_photo where instr(tph_memo,'_') >0
    倒是可以实现,但是需要改动的地方太多了,希望还是可以能
    使用like关键字。请问还有其它的方法吗?是否和数据库安装
    的时候选择的编码有关系?
      

  6.   

    问题解决了用
    select * from t_photo where tph_memo like '%\%%' escape chr(92 USING NCHAR_CS);
    可以实现了