sql中执行存储过程参数如何取表中查询值
展开全部
没懂你要问什么。
如果你你要给存储过程传递参数,用IN 关键字,例如:
CREATE DEFINER=`vemdm`@`%` PROCEDURE `pr_insert_softlogday`(IN ins_DNname VARCHAR(20),IN sel_DNname VARCHAR(20),IN starttime VARCHAR(20),IN endtime VARCHAR(20))
BEGIN
SET @sqlcmd = CONCAT("INSERT INTO ",ins_DNname,"(softname,softversion,citycode,s_work,usetimes,s_day)
SELECT softname,softversion,citycode,workcustom s_work,SUM(usetimes) usetimes,create_time s_day FROM (
SELECT a.mac,a.citycode,a.workcustom,b.softname,b.softversion,b.usetimes,b.create_time FROM
(SELECT * FROM ",sel_DNname," a WHERE create_time BETWEEN '",starttime,"' AND '",endtime,"')b JOIN
(SELECT mac,citycode,workcustom FROM `terminal_unit`) a ON
a.mac = b.mac)c GROUP BY softname,softversion,citycode,workcustom");
PREPARE temp FROM @sqlcmd;
EXECUTE temp;
END$$
DELIMITER ;
这个我传递了3个参数。
如果你你要用存储过程查结果,建议改为用视图或者函数,存储过程默认是没有返回值的。所以你拿不到结果
如果你你要给存储过程传递参数,用IN 关键字,例如:
CREATE DEFINER=`vemdm`@`%` PROCEDURE `pr_insert_softlogday`(IN ins_DNname VARCHAR(20),IN sel_DNname VARCHAR(20),IN starttime VARCHAR(20),IN endtime VARCHAR(20))
BEGIN
SET @sqlcmd = CONCAT("INSERT INTO ",ins_DNname,"(softname,softversion,citycode,s_work,usetimes,s_day)
SELECT softname,softversion,citycode,workcustom s_work,SUM(usetimes) usetimes,create_time s_day FROM (
SELECT a.mac,a.citycode,a.workcustom,b.softname,b.softversion,b.usetimes,b.create_time FROM
(SELECT * FROM ",sel_DNname," a WHERE create_time BETWEEN '",starttime,"' AND '",endtime,"')b JOIN
(SELECT mac,citycode,workcustom FROM `terminal_unit`) a ON
a.mac = b.mac)c GROUP BY softname,softversion,citycode,workcustom");
PREPARE temp FROM @sqlcmd;
EXECUTE temp;
END$$
DELIMITER ;
这个我传递了3个参数。
如果你你要用存储过程查结果,建议改为用视图或者函数,存储过程默认是没有返回值的。所以你拿不到结果
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询