zl程序教程

您现在的位置是:首页 >  数据库

当前栏目

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

Oracle 详解 函数 数字 判断 是否 replace 某列
2023-09-11 14:15:13 时间
简要比较:
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;---取出值里面的全部数字