mysql 写个存储过程,把传入的时间转换成字符串,再给表赋值 20
CREATEPROCEDUREtest()BEGINDECLAREtempParamVARCHAR(15);SETtempParam=(selectDATE_FORMAT...
CREATE PROCEDURE test()
BEGIN
DECLARE tempParam VARCHAR(15);
SET tempParam=(select DATE_FORMAT(NOW(),'%Y%m%d%H%i%s'));
/*插入时间节点字段*/
SELECT count(*) INTO count1 FROM test1(表一);
/*给表二指定记录数更新值*/
update test1(表二) set photodate=tempParam ORDER BY id LIMIT count1;
END;
结果:报错
日志:
[Err] 1064 - You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'SELECT count(*) INTO count1 FROM wh_stock_list;
update wh_stock_list_photo s' at line 11 展开
BEGIN
DECLARE tempParam VARCHAR(15);
SET tempParam=(select DATE_FORMAT(NOW(),'%Y%m%d%H%i%s'));
/*插入时间节点字段*/
SELECT count(*) INTO count1 FROM test1(表一);
/*给表二指定记录数更新值*/
update test1(表二) set photodate=tempParam ORDER BY id LIMIT count1;
END;
结果:报错
日志:
[Err] 1064 - You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'SELECT count(*) INTO count1 FROM wh_stock_list;
update wh_stock_list_photo s' at line 11 展开
1个回答
展开全部
--不是练习题吧?
create PROCEDURE test()
BEGIN
DECLARE count1 int default 0;
DECLARE tempParam VARCHAR(15);
SET tempParam=DATE_FORMAT(NOW(),'%Y%m%d%H%i%s');
SELECT count(*) INTO count1 FROM test1;
PREPARE stmt1 FROM 'update test1 set photodate=? ORDER BY id LIMIT ?';
set @p1=tempParam;
set @p2=count1;
EXECUTE stmt1 USING @p1,@p2;
END;
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询