如何编写一个SQL语句,将所有x'BF'替换为包含ASCII缺点的某个数据字段的x'00'?将其替换为空 x'00'



我如何正确编码以在Oracle SQL中工作:

更新table_name 设置field_name = 替换(field_name, x'BF', x'00') 其中条件表达式 ;

不确定如何编码将十六进制"BF"的所有出现替换为数据字段field_name中包含的空值十六进制"00"。

您可以使用unistr()函数提供 Unicode 字符。 例如:

update table_name
set field_name = replace(field_name, unistr('0bf'))
where condition expression ;

这将完全删除¿字符;或者将其替换为空字符:

set field_name = replace(field_name, unistr('0bf'), unistr('000'))

尽管我怀疑将 null 粘贴在那里会在以后更加混乱,当其他系统尝试读取该文本并停止在 null 时。

快速演示:

with t (str) as (
select 'A ¿ char' from dual
)
select str,
replace(str, unistr('0bf')) as removed,
replace(str, unistr('0bf'), unistr('000')) as replaced,
dump(replace(str, unistr('0bf')), 16) as removed_hex,
dump(replace(str, unistr('0bf'), unistr('000')), 16) as replaced_hex
from t;
STR       REMOVED   REPLACED  REMOVED_HEX                         REPLACED_HEX
--------- --------- --------- ----------------------------------- -----------------------------------
A ¿ char  A  char   A   char  Typ=1 Len=7: 41,20,20,63,68,61,72   Typ=1 Len=8: 41,20,0,20,63,68,61,72

(作为您将遇到的问题的一个例子 - 由于空值,我无法从 SQL 开发人员复制和粘贴它,不得不切换到 SQL*Plus...

第一个转储显示彼此相邻的两个空格(十六进制 20);第二个转储显示它们之间的空字符。

最新更新