如何使用DB2 Function查找字符串中每个字符的ASCII? [英] How to find ASCII of every character in string using DB2 Function?
问题描述
我已经在DB2中编写了一个函数-计算特定列中记录的ASCII.我想要一些帮助,因为我想检查字符串中每个字符的ASCII,如果该记录的ASCII大于127,则返回yes.
I have written a function in DB2 - that is calculating ASCII of records in a particular column. I want to some help as I want to check the ASCII of every single character in string return yes if the ASCII of that record is greater than 127.
BEGIN
ATOMIC DECLARE POS,
INT;
IF INSTR IS NULL THEN RETURN NULL;
END IF;
SET
(
POS,
LEN
)=(
1,
LENGTH(INSTR)
);
WHILE POS <= LEN DO IF ASCII( SUBSTR( INSTR, POS, 1 ))> 128 THEN RETURN 'Y';
END IF;
SET
POS = POS + 1;
END WHILE;
RETURN 'N';
推荐答案
如果目标只是获取此类行,为什么要计算该列中每个字符的ascii?
Why to calculate ascii of every character in that column, if the goal is just to get such rows?
SELECT STR
FROM
(
VALUES
'Hello, world'
, 'Привет, мир'
) T (STR)
WHERE xmlcast(xmlquery('fn:matches($s, "[^\x00-\x7F]")' passing t.str as "s") as int) = 1;
t.str 的值包含此类字符,则该函数将返回1,否则返回0.
The fn:matches function uses regular expressions.
The [^\x00-\x7F]
regular expression means "a character with hex value not in the 0x00 - 0x7F
interval". If a value of passed t.str
contains such a character, the function returns 1 and 0 otherwise.
这篇关于如何使用DB2 Function查找字符串中每个字符的ASCII?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!