一聚教程网:一个值得你收藏的教程网站

最新下载

热门教程

sql 字符串连接函数

时间:2010-09-06 编辑:简简单单 来源:一聚教程网

sql 字符串连接函数在sql中字符串连接函数我们学用到concat()来,concat() 的语法如下:concat(字串1, 字串2, 字串3, ...): 将字串1、字串2、字串3,等字串连在一起。请注意,oracle的concat()只允许两个参数;换言之,一次只能将两个字串串连起来。不过,在oracle中,我们可以用'||'来一次串连多个字串。

select region_name + ' ' + store_name from geography
where store_name = 'boston';

 

实例方法

a:

id value

1 111111111

2 222222222

3 333333333


表 b:

id data

9 11-11111-11

10 22-22222-22

11 33-33333-33

 

select * from a where substring(value,1,2) + '-' + substring(value,3,5) + '-' + substring(value,8,2)

not in (select b from data);


方法二

select *
from a
where (substr(value, 0, 2) || '-' || substr(value, 2, 5) || '-' ||
substr(value, 8, 9)) not in (select b from data);
或者直接更新value

update a set value=(substr(value, 0, 2) || '-' || substr(value, 2, 5) || '-' ||
substr(value, 8, 9));


如果不是oracle 的话substr 换成substring ,||换成+

热门栏目