简体   繁体   English

在数组中选择位置的存储过程

[英]Stored procedure with select where in array

I need Stored procedure for my select query. 我的选择查询需要存储过程

My problem is i have String array it's contain multiple mobile numbers to compare db table if available or not.if available return row values. 我的问题是我有String数组,它包含多个移动电话号码以比较db表(如果可用)。如果可用,则返回行值。

I am using mysql 5.1.It's not supported for comparing array values in select query. 我正在使用mysql 5.1,不支持在选择查询中比较数组值。

I got error Mysql feature not supported exception .so i will change my code using String builder. 我收到错误的Mysql功能不支持的异常。因此,我将使用String builder更改代码。 I already asked. 我已经问过了

My question:[ Mysql Stored procedure with java String Array 我的问题:[ 使用Java字符串数组的Mysql存储过程

So if any possible to compare array values using Store procedure. 因此,如果有可能使用存储过程比较数组值。 My select query is : 我的选择查询是:

SELECT USER_ID, USER_NAME, REGISTRATION_ID, IMEI_CODE, MOBILE_NUMBER FROM USER WHERE MOBILE_NUMBER IN (String_array);

In this query return if 在此查询中返回

`String_array = "one_string_values"; `String_array =“ one_string_values”;

It return single rows.[ Using java jdbc queryforObject ] 它返回单行。[ 使用java jdbc queryforObject ]

If string_array = "array_of_values"` 如果string_array =“ array_of_values”`

It return nothing i got exception Mysql feature not supported exception 它什么也没有返回我得到了异常Mysql功能不支持的异常

Any possibilities available for using Stored procedure in my scenario. 在我的方案中可以使用存储过程的任何可能性。

You basically want to pass multiple values to a Stored Procedure in MySQL. 您基本上想将多个值传递给MySQL中的存储过程。 In SQL Server you can pass an XML chunk (as string) down to the SP, and then easily parse that XML extracting the multiple values from it in the SP body. 在SQL Server中,您可以将XML块(作为字符串)传递给SP,然后轻松地解析该XML,从而在SP主体中从中提取多个值。 In MySQL, I don't think this is easily possible. 在MySQL中,我认为这不可能轻易实现。 The best things you can do: 您可以做的最好的事情:

1) pass a comma-delimited string to the SP and parse that string it inside the SP; 1)将逗号分隔的字符串传递给SP,并在SP中解析该字符串;

2) generate the SQL dynamically: 2)动态生成SQL:
MySQL stored procedure that accepts string with multiple parameters MySQL存储过程接受带有多个参数的字符串

3) you can also look at the FIND_IN_SET function; 3)您还可以查看FIND_IN_SET函数;

4) you can also check the XML functions: 4)您还可以检查XML函数:
http://dev.mysql.com/doc/refman/5.1/en/xml-functions.html http://dev.mysql.com/doc/refman/5.1/en/xml-functions.html
and ExtractValue in particular. 尤其是ExtractValue。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM