当我尝试使用“search_string”作为存储过程的参数运行此查询时,我的 MySQL 数据库在“字段列表”错误消息中为我提供了“未知列”“search_string” :
DROP PROCEDURE IF EXISTS select_title_from_book_table_like;
CREATE PROCEDURE select_title_from_book_table_like(IN IN_TITLE VARCHAR(255))
BEGIN
PREPARE stmt FROM
"SELECT b.book_id,
LEFT(b.title, 36) AS title,
b.edition,
GROUP_CONCAT(CONCAT_WS(' ', a.last_name,
a.first_name,
a.patronymic)
ORDER BY a.last_name
SEPARATOR ', ') AS authors,
YEAR(b.published) AS published,
LEFT(b.pages, 8) AS pages,
b.isbn,
s.subject,
l.language,
p.publisher
FROM (SELECT * FROM book WHERE title LIKE '%?%') AS b
LEFT JOIN book_author AS ba
ON b.book_id = ba.book_id
LEFT JOIN author AS a
ON ba.author_id = a.author_id
LEFT JOIN language AS l
ON b.language_id = l.language_id
LEFT JOIN subject AS s
ON b.subject_id = s.subject_id
LEFT JOIN publisher AS p
ON b.publisher_id = p.publisher_id
GROUP BY b.book_id
ORDER BY b.title ASC";
SET @param1 = IN_TITLE;
EXECUTE stmt USING @param1;
DEALLOCATE PREPARE stmt;
END$$
这是调用该过程的代码:
ShowStringGrid(StringGrid,
'CALL select_title_from_book_table_like(' + Trim(SearchBox.Text) + ')');