oracle中判断某列是否为数字-replace和translate函数详解

简要比较:
replace:字符串级别的代替
如: SELECT REPLACE (' acdd', 'cd','ef') FROM dual;     --aefd
translate:
字符级别的代替
如: SELECT TRANSLATE('acdd', 'cd', 'ef') FROM dual;  --aeff
解释: repalce 中,每个search_ string 都被replacement string 所代替。
select replace ('acdd', 'cd', 'ef') from dual;   →aefd
如果replacement string 为空或为NULL,那么所有的search string 都被移除。
select replace ('acdd', 'cd','') from dual;  -ad
如果search string 为null 那么就返回原来的char
select replace ('acdd','', 'ef') from dual; +acdd
select replace('acdd','','') from dual;-acdd (也是两者都为空的情况)

可以看出translate是逐字符替换的,

oracle中判断某列是否为数字
1.使用trim+translate函数:
select Case When trim(translate('2586.820258','0123456789.',' ')) is NULL
then 1 else 0 end as isnumeric from dual --1 (纯数字返回1,否则返回0)
select * from table where trim(translate(column,'0123456789',' ')) is NULL;
select * from k_dic st where regexp_like(st.id,'^[0-9]+[0-9]$');
sql server
select ISNUMERIC(isnull(100,0))
ORACLE取出字段里的全部数字
SELECT(REGEXP_REPLACE('LSS12345', '[^0-9]')) FROM DUAL;---取出值里面的全部数字


 

posted @   IT情深  阅读(215)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· DeepSeek 开源周回顾「GitHub 热点速览」
· 物流快递公司核心技术能力-地址解析分单基础技术分享
· .NET 10首个预览版发布:重大改进与新特性概览!
· AI与.NET技术实操系列(二):开始使用ML.NET
· 单线程的Redis速度为什么快?
点击右上角即可分享
微信分享提示