0
我創建了這個存儲功能,建設先進的搜索過程,但我注意到,雖然我嘗試代碼不正確使用存儲在任何它返回結果爲什麼這個存儲一點兒也不返回結果
我認爲它不會返回任何結果參數有問題SearchWord
DELIMITER //
CREATE PROCEDURE AdvancedSearch(IN SearchWord VARCHAR(255))
BEGIN
SELECT * FROM (
SELECT CustomerId AS id,CustomerCompany AS name ,null AS descrip,null AS FileName
FROM tbcustomers
LEFT JOIN tbfiles ON tbcustomers.CustomerId = tbfiles.CatId AND tbfiles.ModuleName = "customers"
WHERE tbcustomers.CustomerCompany LIKE CONCAT('%', @SearchWord , '%')
UNION
SELECT DeviceId AS id,DeviceName AS name,DeviceDesc AS descrip,FileName
FROM tbdevices
LEFT JOIN tbfiles ON tbdevices.DeviceId = tbfiles.CatId AND tbfiles.ModuleName = "devices"
WHERE tbdevices.DeviceName LIKE CONCAT('%', @SearchWord , '%')
OR tbdevices.DeviceDesc LIKE CONCAT('%', @SearchWord , '%')
OR tbdevices.DeviceProperties LIKE CONCAT('%', @SearchWord , '%')
UNION
SELECT HostingId AS id,HostingName AS name,HostingType AS descrip,FileName
FROM tbhosting
LEFT JOIN tbfiles ON tbhosting.HostingId = tbfiles.CatId AND tbfiles.ModuleName = "hosting"
WHERE tbhosting.HostingName LIKE CONCAT('%', @SearchWord , '%')
OR tbhosting.HostingType LIKE CONCAT('%', @SearchWord , '%')
OR tbhosting.HostingSpace LIKE CONCAT('%', @SearchWord , '%')
OR tbhosting.HostingRam LIKE CONCAT('%', @SearchWord , '%')
OR tbhosting.HostingUsage LIKE CONCAT('%', @SearchWord , '%')
OR tbhosting.HostingUsagebases LIKE CONCAT('%', @SearchWord , '%')
UNION
SELECT PageId AS id,PageTitle AS name,PageDesc AS descrip,FileName
FROM tbpages
LEFT JOIN tbfiles ON tbpages.PageId = tbfiles.CatId AND tbfiles.ModuleName = "pages"
WHERE tbpages.PageTitle LIKE CONCAT('%', @SearchWord , '%')
OR tbpages.PageDesc LIKE CONCAT('%', @SearchWord , '%')
OR tbpages.PageSubject LIKE CONCAT('%', @SearchWord , '%')
UNION
SELECT ProductId AS id,ProductName AS name,ProductDesc AS descrip,FileName
FROM tbproducts
LEFT JOIN tbfiles ON tbproducts.ProductId = tbfiles.CatId AND tbfiles.ModuleName = "products"
WHERE tbproducts.ProductName LIKE CONCAT('%', @SearchWord , '%')
OR tbproducts.ProductTitle LIKE CONCAT('%', @SearchWord , '%')
OR tbproducts.ProductDesc LIKE CONCAT('%', @SearchWord , '%')
OR tbproducts.ProductProperties LIKE CONCAT('%', @SearchWord , '%')
OR tbproducts.ProductPrice LIKE CONCAT('%', @SearchWord , '%')
OR tbproducts.ProductNumVersion LIKE CONCAT('%', @SearchWord , '%')
UNION
SELECT ProjectId AS id,ProjectName AS name,ProjectDesc AS descrip,FileName
FROM tbprojects
LEFT JOIN tbfiles ON tbprojects.ProjectId = tbfiles.CatId AND tbfiles.ModuleName = "projects"
WHERE tbprojects.ProjectName LIKE CONCAT('%', @SearchWord , '%')
OR tbprojects.ProjectDesc LIKE CONCAT('%', @SearchWord , '%')
) AS v
WHERE v.name != ''
GROUP BY v.id;
END //
DELIMITER ;
你至少得到一個空的結果集,即i。即你看到列名嗎?任何錯誤消息或警告? –