-2

我有这个 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
4

2 回答 2

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 ;
于 2013-03-28T10:33:55.827 回答
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语句中的用法假设的。

于 2013-03-25T15:23:01.193 回答