GOOGLE搜索中,将“中国”转成“%E4%B8%AD%E5%9B%BD”,而如果用百度搜索即转成“%D6%D0%B9%FA”;
通过UTL_RAW.CAST_TO_VARCHAR2('D6D0B9FA')可以转换为“中国”,有没有相应的函数将GOOGLE这一串转成中文?

解决方案 »

  1.   

    楼主观察细致啊,
    我认为
    1:GOOGLE对编码进行了简单的转换
    2:GOOGLE进行解析的数据库不是采用ORACLE的,
    抑或其它的原因,可以的话,最好问GOOGLE了
      

  2.   

    在JAVA中已经可以将GOOGLE的编码转成中文了,但就是不知道在ORACLE如果转
      

  3.   

    JAVA中如何转换,不知道是是否是字符集影响?
      

  4.   

    public static String decodeUTF8( String src )
        {
    char[] chars = null;
    int leng = 0;

    try
    {
    if ( null != src && src != "" )
    {
    src = src.trim();
            String [] unitArray = src.split("%");
            chars = new char[unitArray.length];
            
            for (int i = 1; i < unitArray.length;)
            {
                int data = 0;
                byte [] bytes = new byte[5];
                bytes[0] = hexStringToByte(unitArray[i]);
                int byteNum = getLeftCountOf1InByte(bytes[0]);

                for (int j = 1; j < byteNum; j++)
                {
                 bytes[j] = (byte)(hexStringToByte(unitArray[i + j]) & 0x3F);
                }
                bytes[0] = maskFirstByte(bytes[0]);
                int byteCount = 0;
                for (int j = byteNum - 1; j >= 0; j--)
                {
                    data |=  bytes[j] << (6 * byteCount);
                    byteCount++;
                }
                chars[leng++] = (char)data;
                i += byteNum;
            }
            
            return new String( chars, 0, leng );
    }
    }
    catch ( Exception e )
    {

    }
           
    return "";
        }    public static byte hexStringToByte(String hexStr)
        {
            hexStr = hexStr.toUpperCase();
              char high = hexStr.charAt(0);
              char low  = hexStr.charAt(1);          int highVal = 0;
              if (high >= '0' && high <= '9')
              {
                  highVal = high - '0';
              }
              else
              {
                  highVal = 10 + (high - 'A');
              }
              int lowVal = 0;
              if (low >= '0' && low <= '9')
              {
                  lowVal = low - '0';
              }
              else
              {
                  lowVal = 10 + (low - 'A');
              }
              return (byte)((highVal << 4) | lowVal);
        }    public static int getLeftCountOf1InByte(byte b)
        {
            int count = 0;
            int mask = 1 << 7;
            for (int i = 0; i < 8; i++)
            {
                if ((b & mask) == 0)
                {
                    break;
                }
                else
                {
                    count++;
                    mask >>= 1;
                }
            }
            return count;
        }    private static byte maskFirstByte(byte b)
        {
            int mask = 1 << 7;
            for (int i = 0; i < 8; i++)
            {
                if ((b & mask) == 0)
                {
                    break;
                }
                else
                {
                    b &= ~mask;
                    mask >>= 1;
                }
            }
            return (byte)b;
        }
      

  5.   

    更改客户端字符集后得到的"中国"
    C:\Documents and Settings\Administrator>set NLS_LANG=american_america.UTF8C:\Documents and Settings\Administrator>sqlplus scott/tigerSQL*Plus: Release 9.2.0.1.0 - Production on Sun Apr 11 15:57:08 2010Copyright (c) 1982, 2002, Oracle Corporation.  All rights reserved.
    Connected to:
    Oracle9i Enterprise Edition Release 9.2.0.1.0 - Production
    With the Partitioning, OLAP and Oracle Data Mining options
    JServer Release 9.2.0.1.0 - ProductionSQL> SELECT utl_raw.cast_to_raw('中国') from dual;UTL_RAW.CAST_TO_RAW('锛??')
    -----------------------------------------------------------------------------A3BF3F3F
      

  6.   

    找到结果了,呵呵
     select DUMP(CONVERT('中国', 'UTF8', 'zhs16gbk'), 1016) D_STR from dual;
    D_STR
    Typ=1 Len=6 CharacterSet=ZHS16GBK: e4,b8,ad,e5,9b,bd
      

  7.   

    按我的理解,ORACLE服务器的编码是UTF8字符集的,中文页面请求的时候转换成中文字符集显示,对字符集理解不深,等待高人指点
      

  8.   


    我反过来,想把“e4b8ade59bbd”转成“中国”却不成功?你那里可以转吗?
      

  9.   

      select CONVERT(UTL_RAW.CAST_TO_VARCHAR2('e4b8ade59bbd'), 'zhs16gbk', 'UTF8') from dual;
    CONVERT(UTL_RAW.CAST_TO_VARCHA
    中国
    将他转换为UTF8