如何在存储过程中将varchar转换为整数 [英] How to convert varchar to integer in stored procedure

查看:122
本文介绍了如何在存储过程中将varchar转换为整数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好,如果您能帮助我解决问题,我将不胜感激.我需要编写获取字符串的存储过程.字符串中的每个char必须转换为int类型,并且转换后的类型必须插入到表中.

知道要这么做吗?

预先谢谢您.

Hello I would be grateful if you could help me to solve the problem. I need to write stored procedure that gets string. Each char in string have to be converted to int type and the converted type have to be inserted to the table.

Any idea haow to do it?

Thank you in advance.

推荐答案

对于MSSQL

For MSSQL

convert(int,'01235') 







DECLARE @Pos int
SET @Pos=1;
DECLARE @inputString varchar(10)
SET @inputString='012345'

DECLARE @intValue int

while(@Pos<=LEN(@inputString))
BEGIN
	SET @intValue = CONVERT(int,substring(@inputstring,@Pos,1));
	INSERT INTO myTable(myfield) Values(@intValue);
	SET @Pos=@Pos+1
END


这篇关于如何在存储过程中将varchar转换为整数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆