oracle的unistr报错问题

场景:表里面有一大批数据,查询SQL有用到unistr函数,将Unicode编码内容转译后查出。但是却查询报错,ORA-30186: '\' 的后面必须是四个十六进制字符。

尝试:怀疑是存的Unicode编码格式存在问题,用下面的语句并没有发现异常数据

select * from xxx_table where regexp_replace(name,'\\[0-9a-f]{4}','') is not null and instr(name,'\')>0;

  

解决:写了一段存储过程,发现原来是因为存在中文使得unistr报这种错误

declare
  v_str  varchar2(1000);
BEGIN
  for i in (select namefrom xxx_table) loop
    begin
      v_str := i.name;
      select unistr(i.name) into v_str from dual;
    exception
      when others then
        dbms_output.put_line(v_str);
    end;
  end loop;
END;

然后,存在错误的内容就蹦出来了,到这里就发现有些中文字通过这个函数竟然会报错诶

SELECT unistr('昞') FROM dual;
SELECT unistr('\661e') FROM dual;

补充:
a.何为Unicode
Unicode(统一码、万国码、单一码)是计算机科学领域里的一项业界标准,包括字符集、编码方案等。Unicode 是为了解决传统的字符编码方案的局限而产生的,它为每种语言中的每个字符设定了统一并且唯一的二进制编码,以满足跨语言、跨平台进行文本转换、处理的要求。1990年开始研发,1994年正式公布。

b.Java转Unicode

public String StringtoUnicode(String str) {
        str = (str == null ? "" : str);
        String tmp;
        StringBuffer sb = new StringBuffer(1000);
        char c;
        int i, j;
        sb.setLength(0);
        for (i = 0; i < str.length(); i++) {
            c = str.charAt(i);
            sb.append("\\u");
            j = (c >>> 8); //取出高8位
            tmp = Integer.toHexString(j);
            if (tmp.length() == 1)
                sb.append("0");
            sb.append(tmp);
            j = (c & 0xFF); //取出低8位
            tmp = Integer.toHexString(j);
            if (tmp.length() == 1)
                sb.append("0");
            sb.append(tmp);

        }
        return (new String(sb));
}

c.JS转Unicode

function StringtoUnicode(data) {
    var regexp = new RegExp("[^\\u4e00-\\u9fa5]");//匹配中文
    if(data && regexp.test(data)){
        var str = '';
        for(var i=0;i<data.length;i++) {
            var char = data[i].charCodeAt(0);
            var tmp = "";
            str += "\\u";
            //取出高8位
            tmp = parseInt(char >>> 8, 10).toString(16);
            if (tmp.length == 1)
                str += "0";
            str += tmp;
            //取出低8位
            tmp = parseInt(char & 0xFF, 10).toString(16);
            if (tmp.length == 1)
                str += "0";
            str += tmp;
        }
        return str;
    }
    else{
        return data;
    }
}

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
Oracle SQL Developer, v1.5.0.54.40 Release Notes 完整版下载:http://www.oracle.com/technology/global/cn/software/products/sql/index.html 1. Known Issues 1.1 General - Print prints only one page that is a truncation of the current tab. - Can't invoke SQL*Plus on Windows 2003. - The menu item, and right-click off a Connection node, for invoking SQL*Plus does not work with connections whose passwords are not persisted. 1.2 Connections - Cannot connect to remote database as OPS$ account. 1.3 Browse - If connected as sys with sysdba role, Types node displays built in data-types (e.g. BLOB, DATE, DECIMAL, etc.) If clicked on, will only see "create or replace". 1.4 Creating and Modifying Objects - Editing Triggers - If you have comments before the 'BEGIN' they will be lost if you edit. You will see when you click edit that they will not be there. To preserve them, they need to be below the BEGIN or you will need to edit via the SQL Worksheet. 1.5 Table > Data - Tables > Your_Table > Data - PageUp and PageDown buttons not working correctly if cursor is in the rownum column. 1.6 Export - Cannot export if result set contains duplicate column names. 2. Workarounds 2.1 To disable Code Insight Run SQL Developer from a command line using the following statement: Windows : sqldeveloper -J-Dsdev.insight=false Linux or Mac: Run sh sqldeveloper -J-Dsdev.insight=false or edit sqldeveloper.conf and add "AddVMOption -J-Dsdev.insight=false" 2.2 If DDL tab is null for all objects in a Connection Your dbms_metadata might be loaded incorrectly. If this statement fails when executed in a SQL Worksheet against the Connection select dbms_metadata.get_ddl('TABLE',table_name , user ) from user_tables; You need to reload $ORACLE_HOME/rdbms/admin/catmeta.sql 2.3 If Snippets are not accessible You may have not done a clean install. SQL Developer needs to be installed into a clean directory, not over a previous release. 3. Accessibility Issues The following is a li

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值