Chinaunix首页 | 论坛 | 博客
  • 博客访问: 57392
  • 博文数量: 20
  • 博客积分: 0
  • 博客等级: 民兵
  • 技术积分: 282
  • 用 户 组: 普通用户
  • 注册时间: 2014-11-20 17:23
个人简介

我的博客园;http://www.cnblogs.com/geekpaul/

文章分类

全部博文(20)

文章存档

2015年(7)

2014年(13)

我的朋友

分类: Mysql/postgreSQL

2014-11-29 20:29:03

将一个IP地址字段分解到列中,如121.32.3.4

要得到如下结果:

 A               B               C                D

121            32              3                4
Mysql方案:

点击(此处)折叠或打开

  1. select substring_index(substring_index(y.ip,.,1),.,-1) a,
  2.      substring_index(substring_index(y.ip,.,2),.,-1) b,
  3.      substring_index(substring_index(y.ip,.,3),.,-1) c,
  4.      substring_index(substring_index(y.ip,.,4),.,-1) d
  5. from (select ‘121.32.3.4’ as ip from temp) y
Oracle方案:

点击(此处)折叠或打开

  1. select ip,
  2.      substr(ip, 1, instr(ip,.)-1) a,
  3.      substr(ip, instr(ip,.)+1, instr(ip,.,1,2)- instr(ip,.)-1) b,
  4.      substr(ip, instr(ip,.,1,2)+1, instr(ip,.,1,3)- instr(ip,.,1,2)-1) c,
  5.      substr(ip, instr(ip,.,1,3)+1) d
  6. from (select ‘121.32.3.4’ as ip from temp)

阅读(848) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~