当前位置: 代码迷 >> SQL >> 一些sql语句的异常记录
  详细解决方案

一些sql语句的异常记录

热度:67   发布时间:2016-05-05 10:02:12.0
一些sql语句的错误记录

1、update语句

错误:
update words w set w.Cid = 1 and w.Sid = 1
and w.WhiteRule = '院士|院长|工程院'
and w.Work_Status = 'wait'
and w.Last_Completed_Time = NOW()
and w.Is_Deleted = 0
and w.CreateTime = NOW()
where w.Sid NOT IN (0);
正确:
UPDATE words? w
set w.Cid = 1
, w.Sid = 1-- 需要变动的地方
, w.WhiteRule = '院士|院长|工程院'
, w.Work_Status = 'wait'
, w.Last_Completed_Time = SYSDATE()
, Is_Deleted = 0
, w.CreateTime = SYSDATE()
WHERE w.Sid is NULl;

2、存储过程中的格式

错误版:
DELIMITER $$
DROP PROCEDURE IF EXISTS insertSql $$
CREATE PROCEDURE insertSql()
BEGIN
declare indexSidOut int;-- 内层循环索引936次 -- 5486--6421
declare indexSidIn int;-- 外层循环索引31次
DECLARE fidC int;-- 院士id
DECLARE nameC VARCHAR(200); -- 院士姓名

SET indexSidIn = 1;
set indexSidOut = 5486;

REPEAT
??select fid INTO fidC , nameC INTO nameC from words where Id = indexSidOut;
????REPEAT-- 内层循环31次
?????insert into words(Sid , Fid , Word) VALUES(indexSidIn , fidC , nameC);
????? indexSidIn = indexSidIn + 1;
????UNTIL indexSidIn > 31;-- 此处不该有分号
??indexSidOut? = indexSidOut + 1;
UNTIL indexSidOut > 6421;-- 此处不该有分号

END REPEAT;
END $$
DELIMITER ;

  相关解决方案