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

本文共 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

你可能感兴趣的文章
【转】Delphi 关键字详解
查看>>
四:Ionic Framework不支持Android4.2.2的解决方法
查看>>
转载:JAR包介绍大全用途作用详解JAVA
查看>>
从零开始学React:二档 React生命周期以及组件开发
查看>>
ruby, gem install 出现网络错误
查看>>
Android 验证APK是否已经签名或是否是Debug签名
查看>>
H.264简介
查看>>
ORB
查看>>
CAAnimation
查看>>
MySQL索引背后的数据结构及算法原理
查看>>
docker 8 docker的镜像命令
查看>>
CentOS 7 开放3306端口访问
查看>>
执行力
查看>>
关于毛刺
查看>>
微信小程序自定义微信客服按钮
查看>>
Ural 1014 Product of Digits NYOJ 270 数的分解 解题报告
查看>>
SPOJ1812 LCS2 - Longest Common Substring II
查看>>
CSS属性(display)
查看>>
具体数学第二版第二章习题(1)
查看>>
第十四章 字符、字符串、编码
查看>>