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;---取出值里面的全部数字


 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值