我想把字符串里面-和月都去掉,下面这句为啥把所有字符都变没了?
select TRANSLATE('01-1月 -11', '-','') from dual;

解决方案 »

  1.   

    select translate('01-1月 -11', '0123456789-月','0123456789') from dual;可能你没明白translate的用法:http://blog.csdn.net/wh62592855/archive/2009/11/16/4817476.aspx
      

  2.   

    我知道translate是按字符对应的,,我用'-'对应''替换,其它字符不应该保持原样吗?
    需要把字符串中可能出现的值全部给出对应替换?还是说这种替换至少要有一个不是被替换为''的?
      

  3.   

    其实我还想把'月'也替换成别的,这样好像replace做不到
      

  4.   

    加个字符也可以,后面为null是特例情况。
    SQL> select TRANSLATE('01-1月 -11', '1月-','1') from dual;
     
    TRANSLATE('01-1月-11','1月-','
    ------------------------------
    011 11
     
    SQL> 
      

  5.   

    TRANSLATE Syntaxtranslate::=Description of the illustration translate.gif
    PurposeTRANSLATE returns expr with all occurrences of each character in from_string replaced by its corresponding character in to_string. Characters in expr that are not in from_string are not replaced. If expr is a character string, then you must enclose it in single quotation s. The argument from_string can contain more characters than to_string. In this case, the extra characters at the end of from_string have no corresponding characters in to_string. If these extra characters appear in char, then they are removed from the return value.You cannot use an empty string for to_string to remove all characters in from_string from the return value. Oracle Database interprets the empty string as null, and if this function has a null argument, then it returns null.TRANSLATE provides functionality related to that provided by the REPLACE function. REPLACE lets you substitute a single string for another single string, as well as remove character strings. TRANSLATE lets you make several single-character, one-to-one substitutions in one operation.This function does not support CLOB data directly. However, CLOBs can be passed in as arguments through implicit data conversion.看标红部分