Home > Database > Mysql Tutorial > sqlserver2008中字符替换了几种方法

sqlserver2008中字符替换了几种方法

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
Release: 2016-06-07 17:48:50
Original
1520 people have browsed it

本文章来告诉你如何在sql中实现字符替换的语句,有需要的同学可以参考本实现,方法很简单利用了substring函数来操作。

 代码如下 复制代码
1、 substring(P_NO,2,6) from PEAMAIN

截取表PEAMAIN中的p_no字段中的第2个到第6个中的字符,比如p_no字段中的值为B00001,它将截取的值为000001。
sql语句中的字符串的索引是1开始的不是从0开始的。

 

 代码如下 复制代码
2、declare @onece varchar(1)
 set @onece =(select substring(P_NO,1,1) from PEAMAIN)
 
 select replace (P_NO,@onece,'0') from PEAMAIN

这个SQL语句主要功能是把表(PEAMAIN)中的p_no字段中值的第一个字符替换为0,比如p_no字段的值为B00001,首先通过substring获得第一个字符'B',然后通过replace方法把'B'替换为'0'。

Related labels:
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template