我有这个sql过程语句,但由于变量而失败:
CREATE PROCEDURE iskanje(@iskani_niz)
BEGIN
SELECT A.ime, A.opis, B.kategorija
FROM file as A, cathegory as B
WHERE A.ime LIKE '%'+@iskani_niz+'%'
OR A.opis LIKE '%'+@iskani_niz+'%'
OR B.kategorija LIKE '%'+@iskani_niz+'%';
END
答案 0 :(得分:1)
我很抱歉这个迟到的答案......我发现sql和mysql中的程序有不同的语法......所以真正的语法应该是这样的:
set delimiter //
create procedure iskanje(in naziv varchar(10))
BEGIN
SELECT A.ime, A.opis, B.kategorija
FROM file as A, cathegory as B
WHERE A.ime LIKE concat('%',naziv,'%')
OR A.opis LIKE concat('%',naziv,'%')
OR B.kategorija LIKE concat('%',naziv,'%');
END//
set delimiter ;
答案 1 :(得分:0)
请尝试将此参数声明为过程:
CREATE PROCEDURE iskanje
@iskani_niz nvarchar(max)
AS BEGIN
SELECT A.ime, A.opis, B.kategorija
FROM file as A, cathegory as B
WHERE A.ime LIKE '%'+@iskani_niz+'%'
OR A.opis LIKE '%'+@iskani_niz+'%'
OR B.kategorija LIKE '%'+@iskani_niz+'%';
END
请注意,您应该指定一个比nvarchar(max)
更好的类型,我根据您在SELECT
语句中的用法假设它。