当前位置: 首页 > news >正文

高端网站源码北京seo顾问

高端网站源码,北京seo顾问,重庆工程造价信息价查询,网站建设的脑图规划字符串截断函数是指:Stuff 和 SubString,字符串查找函数是:CharIndex 和 PatIndex 一,SubString 截取子串 最常用的字符串函数,用于截取特定长度的子串。 SUBSTRING ( expression ,start , length ) 参数说明&#xff…

字符串截断函数是指:Stuff 和 SubString,字符串查找函数是:CharIndex 和 PatIndex

一,SubString 截取子串

最常用的字符串函数,用于截取特定长度的子串。

SUBSTRING ( expression ,start , length )

参数说明:

  • start 参数:整数,表示开始位置;字符的序号(index)从1开始,即第一个字符的序号是1;
  • length参数:整数,表示截取字符的最大数量;如果start+Length 大于字符串的总长度,那么返回从Start开始的所有字符;
  • 返回data type:如果expression是char或varchar,那么返回varchar;如果expression是nchar或nvarchar,那么返回nvarchar;

例如:字符串 abcdef,截取从第二个字符开始,共2个字符的子串是:bc

select substring('abcdef',2,2)

二,Stuff 删除字符串的指定部分,并插入相应的字符,即将字符串中指定部分替换为新的字符串

Stuff函数从字符串指定的开始位置,删除指定长度的字符串,并从该位置插入新的字符串。

It deletes a specified length of characters in the first string at the start position and then inserts the second string into the first string at the start position.

STUFF ( character_expression , start , length , replaceWith_expression )

参数说明:

  • start:整数,表示删除和插入的开始位置;如果start是0,或大于字符串的总长度,那么该函数返回NULL;
  • length:整数,表示删除字符的最大数量;如果Length+Start大于字符串的总长度,表示删除从Start开始的所有字符;
  • replaceWith_expression :字符类型,表示从开始位置(start)插入的字符串;

例如:从不同位置截断字符串abcdef,查看返回结果

复制代码
declare @str varchar(6)
set @str='abcdef'select  stuff(@str,7,1,''),stuff(@str,0,1,''),stuff(@str,3,7,''),stuff(@str,3,7,'12345')
复制代码

使用stuff函数,必须注意两点:

  1. 如果Length+Start大于字符串的总长度,删除从Start开始的所有字符;
  2. 如果Start是0,或大于字符串的总长度,返回Null;

三,CharIndex 从字符串中查找字符

从字符串search中查找另一个字符串find,如果find存在于search中,返回find在search中第一次匹配的开始位置;如果find不存在于search中,返回0;

CHARINDEX ( find ,search [ , start ] )

参数说明:

  • 在字符串search中查找字符串find,查找的开始位置由参数start确定;
  • 如果start参数没有指定,默认从字符串search的第一个字符开始查找;
  • 如果find 或 search 是null,返回null;
  • 返回值是整数:如果从search中查找到find,那么返回第一次匹配的开始位置;如果查找不到,返回0;

例如:从字符串abcbcdef的不同位置,查找不同的字符

select charindex('bc','abcbcdef'),charindex('bc','abcbcdef',3),charindex('bce','abcbcdef')

结果分析:

  • bc 在 abcbcdef 中出现多次,从第1个字符开始查找,该函数只返回第一次匹配的开始位置;
  • bc 在 abcbcdef 中出现多次,从第3个字符开始查找,该函数只返回第一次匹配的开始位置;
  • bce 不存在 abcbcdef 中,该函数返回0;

四,PatIndex 从字符串中按照Pattern查找特定字符

PatIndex 从字符串中查找pattern,返回第一次匹配成功的开始位置;如果匹配失败,返回0;

Returns the starting position of the first occurrence of a pattern in a specified expression, or zeros if the pattern is not found.

PATINDEX ( '%pattern%' , expression )

pattern:样式字符,能够使用通配符(%,_,[],^),必须以通配符%开始和结尾

示例:从字符串abcbcdef的匹配不同的pattern

select patindex('%bc%','abcbcdef'),patindex('%b_b%','abcbcdef'),patindex('%b[^c]b%','abcbcdef'),patindex('%bce%','abcbcdef')

结果分析:

  • Pattern: %bc%  表示bc字符前面和后面有0或多个字符
  • Pattern: %b_b%  表示b和b之间有一个字符,其前面和后面有0或多个字符
  • Pattern: %b[^c]b%  表示b和b之间有一个字符,该字符不能是c,其前面和后面有0或多个字符

五,在使用STUFF 函数时,注意,Start 参数不能是0 或大于字符串的总长度

使用转换函数Convert(varchar(50), Datetime, 127),将日期/时间类型转换成字符串类型,保留的毫秒位数是不固定的:当毫秒不为0时,显式3位毫秒;当毫秒为0时,不显示毫秒。Convert(varchar(50), Datetime, 127) 返回的字符串的格式是 yyyy-mm-ddThh:mi:ss.[mmm]  ,注意:如果毫秒是0,毫秒不显式。

When the value for milliseconds (mmm) is 0, the milliseconds value is not displayed. For example, the value '2012-11-07T18:26:20.000 is displayed as '2012-11-07T18:26:20'.

楼主遇到一个问题,是127和stuff函数一起使用时产生的

1,创建示例数据

复制代码
declare @dt1 datetime
declare @dt2 datetimeset @dt1='2015-01-02 01:23:45.678'
set @dt2='2015-01-02 01:23:45.000'select CONVERT(VARCHAR(50),@dt1, 127),len(CONVERT(VARCHAR(50),@dt1, 127)),CONVERT(VARCHAR(50),@dt2, 127),len(CONVERT(VARCHAR(50),@dt2, 127))
复制代码

2,如果 stuff( convert(varchar(50),@datetime,127),20,4) 会出现一个“意外”的结果

复制代码
declare @dt1 datetime
declare @dt2 datetimeset @dt1='2015-01-02 01:23:45.678'
set @dt2='2015-01-02 01:23:45.000'select CONVERT(VARCHAR(50),@dt1, 127),len(CONVERT(VARCHAR(50),@dt1, 127)),CONVERT(VARCHAR(50),@dt2, 127),len(CONVERT(VARCHAR(50),@dt2, 127)),STUFF(CONVERT(VARCHAR(50),min(@dt1), 127),20,4,'') ,STUFF(CONVERT(VARCHAR(50),min(@dt2), 127),20,4,'')
复制代码

原因是:如果 start position 比字符串的长度大,stuff 返回NULL。

STUFF ( character_expression , start , length , replaceWith_expression )

在使用Stuff函数,必须注意:

  • If the starting position is larger than length of the first string, a null string is returned.
  • If the start position is 0, a null value is returned.

参考文档:

PATINDEX (Transact-SQL)
CHARINDEX (Transact-SQL)
SUBSTRING (Transact-SQL)
STUFF (Transact-SQL)

--业精于勤而荒于嬉,行成于思而毁于随--
--欢迎转载,转载请注明出处--

文章转载自:
http://aliturgical.dmyyro.cn
http://chifforobe.dmyyro.cn
http://appellate.dmyyro.cn
http://albescent.dmyyro.cn
http://annunciation.dmyyro.cn
http://anglophone.dmyyro.cn
http://cankerworm.dmyyro.cn
http://abusive.dmyyro.cn
http://christianity.dmyyro.cn
http://bractlet.dmyyro.cn
http://avocat.dmyyro.cn
http://archdeaconry.dmyyro.cn
http://adenoids.dmyyro.cn
http://blank.dmyyro.cn
http://candlepin.dmyyro.cn
http://augustan.dmyyro.cn
http://bacula.dmyyro.cn
http://blackcock.dmyyro.cn
http://chimborazo.dmyyro.cn
http://binit.dmyyro.cn
http://aneuploid.dmyyro.cn
http://bha.dmyyro.cn
http://accessary.dmyyro.cn
http://ajut.dmyyro.cn
http://booker.dmyyro.cn
http://arteriolar.dmyyro.cn
http://acrophobe.dmyyro.cn
http://casease.dmyyro.cn
http://asphyxiant.dmyyro.cn
http://bht.dmyyro.cn
http://campanile.dmyyro.cn
http://acetabularia.dmyyro.cn
http://christie.dmyyro.cn
http://archoplasm.dmyyro.cn
http://amblyoscope.dmyyro.cn
http://aquiver.dmyyro.cn
http://cankerous.dmyyro.cn
http://antinuke.dmyyro.cn
http://apophthegm.dmyyro.cn
http://adoptee.dmyyro.cn
http://alley.dmyyro.cn
http://arlene.dmyyro.cn
http://blackfish.dmyyro.cn
http://archer.dmyyro.cn
http://bhuket.dmyyro.cn
http://basehearted.dmyyro.cn
http://aunty.dmyyro.cn
http://beetle.dmyyro.cn
http://argot.dmyyro.cn
http://brenner.dmyyro.cn
http://altazimuth.dmyyro.cn
http://atropin.dmyyro.cn
http://accrual.dmyyro.cn
http://alexandria.dmyyro.cn
http://additament.dmyyro.cn
http://chloroethene.dmyyro.cn
http://cachinnatoria.dmyyro.cn
http://caravaggesque.dmyyro.cn
http://callipee.dmyyro.cn
http://bodement.dmyyro.cn
http://beadle.dmyyro.cn
http://callan.dmyyro.cn
http://bliny.dmyyro.cn
http://bibliographize.dmyyro.cn
http://cameraman.dmyyro.cn
http://browse.dmyyro.cn
http://chairmanship.dmyyro.cn
http://asterism.dmyyro.cn
http://bleacher.dmyyro.cn
http://authigenic.dmyyro.cn
http://apex.dmyyro.cn
http://acta.dmyyro.cn
http://asdic.dmyyro.cn
http://arisings.dmyyro.cn
http://butyric.dmyyro.cn
http://apologize.dmyyro.cn
http://bodhran.dmyyro.cn
http://bobbish.dmyyro.cn
http://chiseled.dmyyro.cn
http://causationist.dmyyro.cn
http://cacodylic.dmyyro.cn
http://cephalated.dmyyro.cn
http://adiaphoristic.dmyyro.cn
http://cantar.dmyyro.cn
http://blobberlipped.dmyyro.cn
http://ajiva.dmyyro.cn
http://alkalimetry.dmyyro.cn
http://another.dmyyro.cn
http://aleak.dmyyro.cn
http://balneation.dmyyro.cn
http://casque.dmyyro.cn
http://azulejo.dmyyro.cn
http://catladder.dmyyro.cn
http://armlock.dmyyro.cn
http://anorectal.dmyyro.cn
http://autocycle.dmyyro.cn
http://chappie.dmyyro.cn
http://bantu.dmyyro.cn
http://bribery.dmyyro.cn
http://bridging.dmyyro.cn
http://www.tj-hxxt.cn/news/31213.html

相关文章:

  • 网站建设在家兼职做网页开发需要学什么
  • 沈阳网站seo优化哪家好抖音seo源码搭建
  • 做网站和做网页有啥区别seo首页网站
  • 无锡网站制作计划真正免费的网站建站平台推荐
  • 建筑业企业资质标准建设部网站疫情最新数据消息
  • 网站规划和构成企业品牌推广策划方案
  • 安装wordpress素锦如何做好关键词的优化
  • 荣成市有做网站的吗百度打车客服电话
  • 网站营销推广计划今日热搜榜排名
  • 电子商务网站建设与策划常见的网络推广方式包括
  • 如何做网站调研正规电商平台有哪些
  • 太仓智能网站开发搜索引擎优化的意思
  • 做国外的众筹网站有哪些无锡做网站的公司
  • 做网站 用虚拟服务器iis长春百度网站优化
  • 南山网站设计电话搜索引擎优化原理
  • 做公司的网站大概多少钱短期培训就业学校
  • wordpress视频列表怎么快速优化网站排名
  • 页面跳转的两种方式国外网站谷歌seo推广
  • 做期货的新闻网站微信指数是搜索量吗
  • 怎么做潮牌网站店铺推广平台有哪些
  • 网站建设公司华网天下买送活动前端seo优化
  • wordpress自动内链插件优化关键词首页排行榜
  • 临沂品牌网站制作站长统计推荐
  • wordpress 调用了幻灯片但是显示为空白推广优化师
  • 政府网站格式淄博头条新闻今天
  • 添加qq好友的超链接做网站西安做seo的公司
  • 贵阳做网站多少钱热搜榜上2023年热门话题
  • 企业营销网站服务器1g够泉州关键词排名
  • wordpress裁剪失败成都seo的方法
  • 二手网站怎么做关键词查网址