zoukankan
html css js c++ java
数据库截取一定长度的字符串
数据库截取一定长度的字符串:
/**/
/*
******************************************
作者:小朱
功能:获取一定长度的字符串
日期:2004年11月01日
******************************************
*/
CREATE
FUNCTION
[
dbo
]
.
[
uf_GetString
]
(
@str
VarChar
(
2000
)
=
''
,
--
要截取的字符串
@getLen
Int
=
0
--
要截取的长度,按中文的汉字计算
)
RETURNS
VarChar
(
2000
)
AS
BEGIN
Declare
@lastStr
VarChar
(
2000
)
Declare
@tempStr
VarChar
(
2000
)
Declare
@str1
VarChar
(
2
)
Declare
@pos
Int
Declare
@ChineseCount
Int
Declare
@EnglishCount
Int
Select
@ChineseCount
=
0
Select
@EnglishCount
=
0
Select
@pos
=
1
Select
@tempStr
=
LTrim
(
RTrim
(
@str
))
While
@EnglishCount
/
2
+
@ChineseCount
<
@getLen
Begin
If
Len
(
@tempStr
)
<
@getLen
OR
@pos
+
1
>
Len
(
@tempStr
)
Begin
Select
@lastStr
=
@tempStr
Break
End
Else
Begin
Select
@str1
=
SubString
(
@tempStr
,
@pos
,
1
)
If
DataLength
(
@str1
)
=
Len
(
@str1
)
Select
@EnglishCount
=
@EnglishCount
+
1
Else
Select
@ChineseCount
=
@ChineseCount
+
1
If
@EnglishCount
/
2
+
@ChineseCount
>=
@getLen
Begin
If
@EnglishCount
%
2
<>
0
Select
@lastStr
=
SubString
(
@tempStr
,
1
,
@pos
-
1
)
+
'
'
Else
Select
@lastStr
=
SubString
(
@tempStr
,
1
,
@pos
)
+
'
'
Break
End
Select
@pos
=
@pos
+
1
End
End
Return
@lastStr
END
查看全文
相关阅读:
好的开源项目汇总
强制SVN上传代码时添加日志
微信开发-回调模式
Struct2中自定义的Filter无效
Ajax 传包含集合的JSON
PostgreSQL数据库PL/PGSQL学习使用
单用户对比PG 9.5.4和SYBASE 15.7对超大表的操作性能
一场一波三折的SQL优化经历
聚簇索引对数据插入的影响
磁盘IO初探
原文地址:https://www.cnblogs.com/zsy/p/443034.html
最新文章
基础
基础
基础
基础
基础
基础
FZU2105 Digits Count(按位建线段树)题解
BZOJ1001 狼抓兔子(网络流转最短路:对偶图)
HDU 6706 huntian oy(杜教筛 + 一些定理)题解
HDU 5608 function(莫比乌斯反演 + 杜教筛)题解
热门文章
P4213 【模板】杜教筛(杜教筛)题解
HDU 6390 GuGuFishtion(莫比乌斯反演 + 欧拉函数性质 + 积性函数)题解
HDU 4675 GCD of Sequence(莫比乌斯反演 + 打表注意事项)题解
HDU 4746 Mophues(莫比乌斯反演)题解
SPOJ VLATTICE Visible Lattice Points(莫比乌斯反演)题解
HDU 6704 K-th occurrence(主席树 + RMQ + 后缀数组)题解
使用 Oracle Data Access Components连接oracel
left join不同写法导致数据差异
极点五笔不联想解决办法
使用mybatis-generator生成代码
Copyright © 2011-2022 走看看