当前位置: 动力学知识库 > 问答 > 编程问答 >

oracle - How to determine if a variable has a special character using dual table on sql?

问题描述:

I'm currently trying to check if a string has a special character (value that is not 0 to 9 A to Z a to z), but the inhouse language that I'm currently using has a very limited function to do it (possible but it will take a lot of lines). but I am able to do a query on sql. Now I would like to ask if it is possible to query using the dual table on sql, My plan is to pass the string to variable and this variable will be use on my sql command. Thanks in advance.

网友答案:

Here is what you can use

SELECT REGEXP_INSTR('Test!ing','[^[:alnum:]]') FROM dual;

This will return a number other than 0 whenever your string has anything other than letters or numbers.

网友答案:

You can use TRANSLATE to remove all okay characters from the string. You get back a string containing only undesired characters - or an empty string when there are none.

select translate(
  'AbcDefg1234%99.26XYZ', -- your string
  '.ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789',
  '.') from dual;

returns: %.

分享给朋友:
您可能感兴趣的文章:
随机阅读: