如何在mysql存储过程phpmyadmin中设置全局变量?

时间:2015-07-31 12:04:44

标签: sql stored-procedures

这是mysql phpmyadmin的程序代码 **程序代码:**

CREATE DEFINER=`root`@`localhost` PROCEDURE `product_listing`(IN `pro_name` VARCHAR(265), IN `cat_id` VARCHAR(11), IN `status` VARCHAR(11))
    DETERMINISTIC
BEGIN 
    DECLARE name VARCHAR(265);
    DECLARE main VARCHAR(265);      
    DECLARE pnmconcat VARCHAR(265);
    DECLARE pnmquery VARCHAR(265);    
    DECLARE respname VARCHAR(265);    
    set @pname := pro_name;
    set @cat_id := cat_id;
    set @status := status; 

    IF @pname IS NOT NULL THEN 

        SET pnmconcat = CONCAT("'%",@pname,"%'");
        SET pnmquery = ' and p_name like ';
        SET name = CONCAT(pnmquery, pnmconcat); 

    END IF;

    IF @cat_id IS NOT NULL THEN 

        SET name = CONCAT(' and cat_id=',@cat_id);  

    END IF;
    IF @status IS NOT NULL THEN 

        SET name = CONCAT(' and status=',@status);

    END IF;

    set @query := CONCAT("SELECT * from product WHERE p_id != ''", name, " ORDER BY p_id desc");

    PREPARE fquery FROM @query;

    EXECUTE fquery;

END

在上面,

我想将name变量设置为全局varibal。但我无法设置它。我如何在全球范围内存储名称变量?

0 个答案:

没有答案