[英]sql fetching special character from DB2
Name = McDonald's | 名称=麦当劳| # 176 address lane
#176地址巷
Name = KFC | 名称=肯德基| 67 address lane
67地址巷
condition : 条件:
The special character (.,/-!@#$^&.....) with name and address should be printed. 应打印带有名称和地址的特殊字符(。,/-!@#$ ^&.....)。
So, the name McDonald's and # 176 address lane should be printed and the rests of the names and addresses without the special characters should be eliminated 因此,应打印名称“ McDonald's”和“#176”地址通道,并应删除其余没有特殊字符的名称和地址
Expected Output : 预期产量:
McDonald's # 176 address lane 麦当劳#176地址巷
Take a look at LIKE
for comparison. 看一下
LIKE
进行比较。 It will allow you to use %
(or another character) as a wild card for string comparison. 它将允许您使用
%
(或其他字符)作为通配符来进行字符串比较。 If you need more help after looking in the manual, please explain what part you did not understand. 如果在阅读手册后需要更多帮助,请说明您不了解的部分。
You can probably use TRANSLATE
: 您可能可以使用
TRANSLATE
:
SELECT Name, Address FROM mytable WHERE Name <> TRANSLATE(Name,' ', '(.,/-!@#$^&.....)') OR Address <> TRANSLATE(Address,' ', '(.,/-!@#$^&.....)')
The second parameter for TRANSLATE()
is a string consisting of all characters you want to trap. TRANSLATE()
的第二个参数是一个字符串,其中包含要捕获的所有字符。 The first parameter is a string of blanks the same length as the second parameter. 第一个参数是一串与第二个参数相同长度的空格。
If any characters are found in Name
or Address
that match any characters in the second string, a changed value will be used for the comparison. 如果在“
Name
或“ Address
中找到与第二个字符串中的任何字符匹配的字符,则将使用更改后的值进行比较。 By comparing against the original values, you'll catch rows that have the special characters. 通过与原始值进行比较,您将捕获具有特殊字符的行。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.