MySQL dynamic search query procedure
The MySQL query should return
1) TRUE along with Comma(,) separated list of STATION_NAME from a table STATION WHERE STATION_NAME is LIKE the INPUT specified buy the user.
FOR Ex:
INPUT = A, OUTPUT= (Agra,Ajmer,Amritsar,Ambala).
INPUT = AM, OUTPUT= (Amritsar, Ambala)
2) FALSE, when no such station exists
3) ERROR.
Detailed PROCEDURE will be appreciated, as I am new to MySQL.
Tha开发者_如何转开发nks in advance.. :)
You don't need a procedure, just a select that returns one row on success or no rows on failure:
select group_concat(station_name) from station where station_name like ?
where ? is a placeholder for the user entered search.
group_concat is a mysql-specific feature.
If you must use a procedure, it would be something like this:
create procedure stationsearch (in likewhat varchar(255), out rslt text)
begin
select group_concat(distinct station_name order by station_name) into rslt from station where station_name like likewhat;
end
Used like this:
call stationsearch('Am%',@rslt);
select @rslt;
SELECT station_name
FROM station
WHERE SUBSTRING(station_name, 1, LENGTH( ? )) = ?;
加载中,请稍侯......
精彩评论