当前位置:首页 » 编程语言 » sql取出字符中的中文
扩展阅读
webinf下怎么引入js 2023-08-31 21:54:13
堡垒机怎么打开web 2023-08-31 21:54:11

sql取出字符中的中文

发布时间: 2022-06-18 09:39:58

sql数据库只提取汉字

public string NoHTML(string Htmlstring) //去除HTML标记
{
//删除脚本
Htmlstring = Regex.Replace(Htmlstring, @"<script[^>]*?>.*?</script>", "", RegexOptions.IgnoreCase);
//删除HTML
Htmlstring = Regex.Replace(Htmlstring, @"<(.[^>]*)>", "", RegexOptions.IgnoreCase);
Htmlstring = Regex.Replace(Htmlstring, @"([\r\n])[\s]+", "", RegexOptions.IgnoreCase);
Htmlstring = Regex.Replace(Htmlstring, @"-->", "", RegexOptions.IgnoreCase);
Htmlstring = Regex.Replace(Htmlstring, @"<!--.*", "", RegexOptions.IgnoreCase);

Htmlstring = Regex.Replace(Htmlstring, @"&(quot|#34);", "\"", RegexOptions.IgnoreCase);
Htmlstring = Regex.Replace(Htmlstring, @"&(amp|#38);", "&", RegexOptions.IgnoreCase);
Htmlstring = Regex.Replace(Htmlstring, @"&(lt|#60);", "<", RegexOptions.IgnoreCase);
Htmlstring = Regex.Replace(Htmlstring, @"&(gt|#62);", ">", RegexOptions.IgnoreCase);
Htmlstring = Regex.Replace(Htmlstring, @"&(nbsp|#160);", " ", RegexOptions.IgnoreCase);
Htmlstring = Regex.Replace(Htmlstring, @"&(iexcl|#161);", "\xa1", RegexOptions.IgnoreCase);
Htmlstring = Regex.Replace(Htmlstring, @"&(cent|#162);", "\xa2", RegexOptions.IgnoreCase);
Htmlstring = Regex.Replace(Htmlstring, @"&(pound|#163);", "\xa3", RegexOptions.IgnoreCase);
Htmlstring = Regex.Replace(Htmlstring, @"&(|#169);", "\xa9", RegexOptions.IgnoreCase);
Htmlstring = Regex.Replace(Htmlstring, @"&#(\d+);", "", RegexOptions.IgnoreCase);

Htmlstring.Replace("<", "");
Htmlstring.Replace(">", "");
Htmlstring.Replace("\r\n", "");
Htmlstring = HttpContext.Current.Server.HtmlEncode(Htmlstring).Trim();

return Htmlstring;
}

❷ 如何用SQL语句,在数字加中文的混合数据中提取出中文

是Oracle数据库吗?
可以用截取字符串的函数。
select
Substr(字段,1,INSTR(字段,'/')-1)
from
al
例如
select
Substr('sdhfuiasdh/asdfsadf',1,INST('sdhfuiasdh/asdfsadf','/')-1)
from
al

❸ sql如何获取字符串中的指定字符

1、创建测试表,

create table test_int(value varchar2(50));

❹ sql 表中一个字段含有大量的中文字符,怎么替换掉

意思是不显示中国字呗,那就不用能显示中国字的电脑编码系统

❺ 跪求各位大侠!怎样提取sql字段存储的字符串中的单个字符

我这里由一个存储过程可以把逗号前面第一个词取出来,你用个循环就可以把所有的都取出来了
CREATE
PROCEDURE
PopFirstWord
@SourceString
NVARCHAR(4000)
=
NULL
OUTPUT,
@FirstWord
NVARCHAR(4000)
=
NULL
OUTPUT
AS
SET
NOCOUNT
ON
DECLARE
@Oldword
NVARCHAR(4000)
DECLARE
@Length
INT
DECLARE
@CommaLocation
INT
SELECT
@Oldword
=
@SourceString
IF
NOT
@Oldword
IS
NULL
BEGIN
SELECT
@CommaLocation
=
CHARINDEX(',',@Oldword)
SELECT
@Length
=
DATALENGTH(@Oldword)
IF
@CommaLocation
=
0
BEGIN
SELECT
@FirstWord
=
@Oldword
SELECT
@SourceString
=
NULL
RETURN
0
END
SELECT
@FirstWord
=
SUBSTRING(@Oldword,
1,
@CommaLocation
-1)
SELECT
@SourceString
=
SUBSTRING(@Oldword,
@CommaLocation
+
1,
@Length
-
@CommaLocation)
RETURN
@Length
-
@CommaLocation
END
RETURN
0

❻ SQL语句提取出中文的拼音首字母

正好最近收藏了一个 你可以看下思路
--将中文字符串转化成文字首拼音的组合
create function fun_getPY(@str nvarchar(4000))
returns nvarchar(4000)
as
begin
declare @word nchar(1),@PY nvarchar(4000)
set @PY=''
while len(@str)>0
begin
set @word=left(@str,1)
--如果非汉字字符,返回原字符
set @PY=@PY+(case when unicode(@word) between 19968 and 19968+20901
then (select top 1 PY from (
select 'A' as PY,N'骜' as word
union all select 'B',N'簿'
union all select 'C',N'错'
union all select 'D',N'鵽'
union all select 'E',N'樲'
union all select 'F',N'鳆'
union all select 'G',N'腂'
union all select 'H',N'夻'
union all select 'J',N'攈'
union all select 'K',N'穒'
union all select 'L',N'鱳'
union all select 'M',N'旀'
union all select 'N',N'桛'
union all select 'O',N'沤'
union all select 'P',N'曝'
union all select 'Q',N'囕'
union all select 'R',N'鶸'
union all select 'S',N'蜶'
union all select 'T',N'箨'
union all select 'W',N'鹜'
union all select 'X',N'鑂'
union all select 'Y',N'韵'
union all select 'Z',N'咗'
) T
where word>=@word collate Chinese_PRC_CS_AS_KS_WS
order by PY ASC) else @word end)
set @str=right(@str,len(@str)-1)
end
return @PY
end
--函数调用实例:
select dbo.fun_getPY('中华人民共和国AAA01')

/*

----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
ZHRMGHGAAA01

(1 行受影响)

*/

❼ sqlsever中消除记录中的中文,提取非中文字符

建立函数来处理吧。
createfunctionfun_del_zh
(@colvarchar(1000))
returnsvarchar(1000)
AS
begin
declare@returncharvarchar(1000),@lenint
select@returnchar='',@len=1

while(@len<=len(@col))
begin
if(ASCII(substring(@col,@len,1))<122)
set@returnchar=@returnchar+substring(@col,@len,1)
set@len=@len+1
end
return@returnchar
end
go

selectid,dbo.fun_del_zh(name)nmfromtest;
idnm
test test
test1 test
test2 test2
有问题再追问。

❽ SQL语句查询返回字符串中中文字符前的字符(包含数字与字母)

select substring(field1,1,patindex('%[吖-咗]%',field1)-1) from table

❾ sql语句中有中文,符号等怎么处理

对于特殊字符
要用到转义符
name like '%\%%' escape '\'意思就是保留\后面的一个字符,无视\
就是name中包含%的记录

你给几个改完的字段的例子阿
比如说'你好(%><;'i9hh %()'你要改成怎样
‘你不好%*#@)%’这个又要改成怎么

❿ 如何解决SQL语句中含有中文字符无法查询

package oop.hu.ytu.;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import oop.hg.ytu.beans.LoginBean;
import oop.hg.ytu.utils.JdbcUtils;
/**
* 处理用户登录请求
* @author Administrator
*
*/
public class LoginDomain {
public LoginBean select(String tableName,String username){
Connection con = null;
PreparedStatement pt = null;
ResultSet rs = null;
LoginBean bean = new LoginBean();
try {
username = "\""+username+"\"";
con = JdbcUtils.getConnection();
String sql = "select name,password from "+tableName+" where name="+username+"";
pt = con.prepareStatement(sql);
// pt.setString(1, tableName);
// pt.setString(2, u);
rs = pt.executeQuery();
while(rs.next()){
bean.setUsername(rs.getString("name"));
bean.setPassword(rs.getString("password"));
}
} catch (Exception e) {
throw new RuntimeException(e);
}finally{
JdbcUtils.free(rs, pt, con);
}
return bean;
}
}
username = "\""+username+"\"";这句话是进行字符串处理,加上双引号。
<pre name="code" class="java" style="background-color: rgb(255, 255, 255); ">String sql = "select name,password from "+tableName+" where name="+username+"";
这句话是重点,一定不能使用PreparedStatement提供的字符串处理方法,一定要直接自己拼接出字符串来运行,这样对于中文的处