如何将整数数组传递给mysql中的存储过程? [英] How to pass an Integer Array to a Stored Procedure in mysql?

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

问题描述




我想将存储过程1,2,3作为整数数组传递,这可能在mysql中吗?



实际上我必须这样做

Hi
I want to pass the Stored Procedure "1,2,3" as a Integer Array, is this possible in mysql?

Actually I have to do

select * FROM User WHERE id IN (1,2,3);



我想将存储过程1,2,3作为整数数组传递



如果我使用varchar,那么有时查询执行正常但是,有时它没有给出记录。





谢谢


I want to pass the Stored Procedure "1,2,3" as a Integer Array

If i use varchar then sometimes the query executes fine But, sometimes it gives no records.


Thanks

推荐答案

这有助于我做IN状态

希望这会对你有所帮助..



This helps for me to do IN condition
Hope this will help you..

CREATE  PROCEDURE `test`(IN Array_String VARCHAR(100))
BEGIN
    SELECT * FROM Table_Name
    WHERE FIND_IN_SET(field_name_to_search, Array_String);

END//;





来电:





Calling:

call test('3,2,1');


关注:

http://vyaskn.tripod.com /passing_arrays_to_stored_procedures.htm [ ^ ]


你的存储过程应该是这样的



your stored procedure should be like this

CREATE procedure procedure_name
(
@CLAIM_NOS varchar(max)
)
as
declare @sql_query varchar(max)
set @sql_query='select * from table_name where CLAIMNO in ('+@CLAIM_NOS+')'
exec (@sql_query)





这里我从gridview中检索id号,





here im retrieving id number from gridview,,,

string S_selected_Claimno = "";
S_selected_Claimno = S_selected_Claimno + "'" + dataGridView1.Rows[i].Cells[1].Value + "',"





最后一个参数字符串应该是这样的(前端参数格式)

'1998102600200003', '2000041900200001','333333333333333'



这会起作用,试试吧

注意:bt确保在检查你的SP工作时或不传递以下格式的参数(在后端)

'''1998102600200003'''''2000041900200001'',''333333333333333'''



AT last ur parameter string should be like this (front end parameter format)
'1998102600200003','2000041900200001','333333333333333'

this will work ,,try it
NOTE : bt make sure while checking ur SP is working or not pass parameters in the below format (IN the back end)
'''1998102600200003'',''2000041900200001'',''333333333333333'''


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

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