简体   繁体   English

Oracle DB程序员:如何识别表中的双字节字符数据?

[英]Oracle DB Programmer: How to identify double byte character data in a table?

Hi Oracle sql programmers, how do you identify double byte character in the db which I mean to find all the data in column 1 in table1 which contain double byte character such as Chinese character(s)? 嗨,Oracle SQL程序员,您如何确定db中的双字节字符,我的意思是在table1的第1列中查找包含双字节字符(例如汉字)的所有数据?

UPDATE 1: I don't even know what Chinese characters would be in the column, I just need to find all the first_name and last_name columns which users entered any non-English characters, then change the value to NA. 更新1:我什至不知道该列中将包含什么中文字符,我只需要查找用户输入了任何非英语字符的所有first_name和last_name列,然后将其值更改为NA。

The simplest option assuming you truly mean non-English (ie any character not in the US7ASCII character set) would be something like 假设您真正是指非英语(即,不在US7ASCII字符集中的任何字符),则最简单的选择是

UPDATE table_name
   SET first_name = 'NA'
 WHERE length( first_name ) != lengthb( first_name )

LENGTH returns the length of a string in characters while LENGTHB returns the length of a string in bytes. LENGTH返回以字符为单位的字符串的长度,而LENGTHB返回以字节为单位的字符串的长度。 UTF-8 encodes the US7ASCII characters with a single byte. UTF-8用单个字节编码US7ASCII字符。 If there are any non-US7SACII characters, the length in bytes will be greater than the length in characters. 如果有任何非US7SACII字符,则以字节为单位的长度将大于以字符为单位的长度。

I've never tried this, but I guess you could convert each character to a number and look for values over 256: 我从未尝试过,但是我想您可以将每个字符转换为数字并查找超过256的值:

SQL> select ascii(unistr('\53f0')) from dual;

ASCII(UNISTR('\53F0'))
----------------------
                 21488

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM