如何在存储过程中使用类似语法

时间:2015-12-08 06:06:59

标签: mysql stored-procedures find sql-like

我初学者使用php语言和mysql用于数据库。 此命令不是错误,但变量无法调用

抱歉,我不会说一口流利的英语

DELIMITER $$

CREATE DEFINER=`root`@`localhost` PROCEDURE `allBarang`($barang varchar(50))

BEGIN

SELECT nm_barang, harga,diskon,deskripsi,image,barang.id_kategori,jenis 
FROM barang    
INNER JOIN kategori on kategori.id_kategori = barang.id_kategori
Where nm_barang LIKE '%$barang%';

END

1 个答案:

答案 0 :(得分:0)

尝试:

DELIMITER $$

DROP PROCEDURE IF EXISTS `allBarang`$$

CREATE DEFINER=`root`@`localhost` PROCEDURE `allBarang`(`$barang` VARCHAR(50))
BEGIN    
  SELECT
    `nm_barang`,
    `harga`,
    `diskon`,
    `deskripsi`,
    `image`,
    `barang`.`id_kategori`,
    `jenis` 
  FROM `barang`
    INNER JOIN `kategori` ON `kategori`.`id_kategori` = `barang`.`id_kategori`
  WHERE `nm_barang` LIKE CONCAT('%', `$barang`, '%');
END$$

DELIMITER ;

SQL Fiddle demo