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
查看全文
相关阅读:
MessageFormat使用记录
在IDEA中使用MyBatis Generator逆向工程生成代码
mybatis报错invalid types () or values ()解决方法
关于jrebel碰到的一次问题记录
I/O限制异步操作
线程基础和异步执行计算限制
模板方法模式(Head first 设计模式——7)
适配器模式和外观模式(head first设计模式——6)
命令模式(head first 设计模式5)
工厂模式——(Head first设计模式4)
原文地址:https://www.cnblogs.com/zsy/p/443034.html
最新文章
单利模式
随笔
c++异常捕获
iocp还是select
Bitmap类
C#用openfiledialog文件和savefileDialog打开和保存文件
简单易懂的解释c#的abstract和virtual的用法和区别
C#中Abstract和Virtual
详解C#中的反射
C# Activator.CreateInstance()方法使用
热门文章
C#中Invoke的用法
谈C#中的Delegate
C#中使用正则表达式验证电话号码、手机号、身份证号、数字和邮编
C#中如何获取一个二维数组的两维长度,即行数和列数?以及多维数组各个维度的长度?
记录一次直播转码失败的经历
mac下 IDEA 的pom下 出现 Cannot access in offline mode 问题
order by 多条件查询 case when
json 对象里面含有 =的解决办法
mac下 安装tomcat 后项目无法启动以及 错误 找不到或无法加载主类
使用ajax请求后返回数据显示undefinded解决办法
Copyright © 2011-2022 走看看