博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
6.13 判别可作为数值的字符串
阅读量:7038 次
发布时间:2019-06-28

本文共 884 字,大约阅读时间需要 2 分钟。

问题:如果数值与字符混合在一起,需要删除那些字符,只返回数字。

create view v as 

select concat(
substr(ename,1,2),
replace(cast(deptno as char(4)),' ',''),
substr(ename,3,2)
) as mixed
from emp
where deptno=10
union all
select replace(cast(empno as char(4)),' ','')
from emp where deptno=20
union all
select ename from emp where deptno=30;

select * from v;

+--------+

| mixed  |
+--------+
| CL10AR |
| KI10NG |
| MI10LL |
| ALLEN  |
| WARD   |
| MARTIN |
| BLAKE  |
| TURNER |
| JAMES  |
+--------+

 

解决方案:

select cast(group_concat(c order by pos separator '' ) as unsigned) as MIXED1

from (
select v.mixed,iter.pos,substr(v.mixed,iter.pos,1) as c
from v,
(select id pos from t10)iter
where iter.pos <=length(v.mixed)
and ascii(substr(v.mixed,iter.pos,1)) between 48 and 57
)y 
group by mixed
order by 1;

+--------+

| MIXED1 |
+--------+
|     10 |
|     10 |
|     10 |
+--------+

转载于:https://www.cnblogs.com/liang545621/p/7523177.html

你可能感兴趣的文章
二分基础
查看>>
物流英语
查看>>
[iOS]iOS8可用的识别用户方式(idfa、UUID、idfv)
查看>>
hdu1507--二分图最大匹配
查看>>
排序(6)---------归并排序(C语言实现)
查看>>
jsp 中对jar 包的引用
查看>>
AndroidStudio怎样导入library项目开源库
查看>>
悲观锁和乐观锁使用场景
查看>>
Oracle 12c: RMAN restore/recover pluggable database
查看>>
substance新版及问题
查看>>
centOSmini安装教程
查看>>
Android开发之SoundPool使用具体解释
查看>>
【数据结构与算法】二叉树深度遍历(递归)
查看>>
iOS开发--基于AFNetWorking3.0的图片缓存分析
查看>>
使用jqMobi开发app基础:弹出内容的设计
查看>>
3.Java集合总结系列:Set接口及其实现
查看>>
ExtJs之Element.select函数
查看>>
驱动程序调试方法之printk——自制proc文件(一)
查看>>
Swift 可选类型-备
查看>>
使用开源软件的原因
查看>>