当我尝试使用'search_string'作为存储过程的参数运行此查询时,我的MySQL数据库为我提供了未知列'search_string''字段列表'错误消息: / p>
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) + ')');
答案 0 :(得分:0)
我认为你准备好的陈述在这里出错:
WHERE b.title LIKE '%?%'
您不想在那里设置%
,因为现在您的问号位于'
。更好的选择是使用
WHERE b.title LIKE ?
然后将%添加到您的实际参数中。
从the comment on the answer on this question您也可以发现您可能会在查询中这样做,但我没有相关经验:
WHERE b.title LIKE '%' || ? || '%'