Хранимая процедура mysql несколько раз выбрасывала ошибку 1064 и несколько раз выполнялась хорошо. Может ли какое-нибудь тело, пожалуйста, помочь мне найти ошибку...
Это хранимая процедура, которая у меня есть
DELIMITER $$ USE `hadoopdb_other`$$ DROP PROCEDURE IF EXISTS `StatisticalData`$$ CREATE DEFINER=`root`@`%` PROCEDURE `StatisticalData`( IN keywords VARCHAR(100), IN tablename VARCHAR(100) ) BEGIN SET @keyword= keywords; SET @tablename=tablename; SET @v1 := REPLACE(@keyword , ' ',''); SET @v2 := REPLACE(@tablename , ' ',''); SET @v3 := CONCAT(@v1,'_info'); SET @v4 := CONCAT(@v2,'_Populatefilteroptions'); SET @sdate= CONCAT('select Min(DATE_FORMAT(date_time,''%Y-%m-%d'')) into @var1 from ',tablename); SET @edate= CONCAT('select max(DATE_FORMAT(date_time,''%Y-%m-%d'')) into @var2 from ',tablename); SET @startdate= @var1; SET @enddate= @var2; SET @drop = CONCAT ('drop table if exists ',@v3); SET @createtable = CONCAT('create table ',@v3,' (CreatedDate varchar(200),KeyCount bigint,Source varchar(200), Keyword VARCHAR(200),Positive bigint,Negative BIGINT,Neutral BIGINT,PositiveScore double, NegativeScore DOUBLE, NeutralScore DOUBLE,PosStrength DOUBLE,NegStrength DOUBLE,NeuStrength DOUBLE,Total bigint)'); SET @drop1 = CONCAT ('drop table if exists ',@v4); SET @createtable1 = CONCAT('create table ',@v4,'(gender varchar(200),country varchar(200),product_name varchar(200), source VARCHAR(200),date_time VARCHAR(200))'); SET @isKeywordsExists=""; SET @keyCnt=0; SET @keyAt=""; SET @tempKeyStr=""; IF keywords <> "" THEN SET @tempKeyStr=keywords; SET @keyCnt=ROUND ( ( LENGTH(@tempKeyStr) - LENGTH( REPLACE ( @tempKeyStr, ",", "") ) ) / LENGTH(","))+1; WHILE @keyCnt>0 DO SET @keyAt = REPLACE(SUBSTRING(SUBSTRING_INDEX(keywords, ',', @keyCnt), LENGTH(SUBSTRING_INDEX(keywords, ',', @keyCnt-1)) + 1), ',', ''); SET @isKeywordsExists=CONCAT(@isKeywordsExists,",SUM(IF (product_name='",@keyAt,"',1,0)) AS `",@keyAt,"`"); SET @keyCnt=@keyCnt-1; END WHILE; END IF; SET@tr=CONCAT('TRUNCATE ', @v3); SET @t1 = CONCAT("insert into ",@v3," (CreatedDate,KeyCount,Source,Keyword,Positive,Negative,Neutral, PositiveScore,NegativeScore,NeutralScore,PosStrength,NegStrength,NeuStrength,Total) select * from ( SELECT DATE_FORMAT( STR_TO_DATE(date_time,'%Y-%m-%d %T'),'%Y-%m-%d') AS createdDate ",@isKeywordsExists,",source,product_name AS keyword, SUM(IF (sentiment_score>0,1,0)) AS Positive, SUM(IF (sentiment_score<0,1,0)) AS Negative, SUM(IF (sentiment_score=0,1,0)) AS Neutral, ROUND(SUM(IF (sentiment_score>0,positive,0)),2) as PositiveScore, ROUND(SUM(IF (sentiment_score<0,negative,0)),2) as NegativeScore, ROUND(SUM(IF (sentiment_score=0,neutral,0)),2) as NeutralScore, COALESCE(ROUND(SUM(IF (sentiment_score>0,positive,0))*100/SUM(IF (sentiment_score>0,1,0)),2),0) AS PosStrength, COALESCE(ROUND(SUM(IF (sentiment_score<0,negative,0))*100/SUM(IF (sentiment_score<0,1,0)),2),0) AS NegStrength, COALESCE(ROUND(SUM(IF (sentiment_score=0,neutral,0))*100/SUM(IF (sentiment_score=0,1,0)),2),0) AS NeuStrength, COUNT(*) AS total FROM ",tablename," WHERE (DATE_FORMAT( STR_TO_DATE(date_time,'%Y-%m-%d %T'),'%Y-%m-%d') between '",@startdate,"' AND '",@enddate,"') GROUP BY createdDate,source order by createdDate desc )sub order by createdDate asc"); SET@tr1=CONCAT('TRUNCATE ', @v4); SET @t2= CONCAT( ' INSERT INTO ',@v4,'(gender,country,product_name,source,date_time) SELECT DISTINCT gender,country,product_name,source,DATE_FORMAT(date_time,\'%Y-%m-%d\') as date_time FROM ',tablename); PREPARE stmt FROM @sdate; EXECUTE stmt; DEALLOCATE PREPARE stmt; PREPARE stmts FROM @edate; EXECUTE stmts; DEALLOCATE PREPARE stmts; PREPARE stmt0 FROM @drop; EXECUTE stmt0; DEALLOCATE PREPARE stmt0; PREPARE stmt1 FROM @createtable; EXECUTE stmt1; DEALLOCATE PREPARE stmt1; PREPARE stmt01 FROM @drop1; EXECUTE stmt01; DEALLOCATE PREPARE stmt01; PREPARE stmt11 FROM @createtable1; EXECUTE stmt11; DEALLOCATE PREPARE stmt11; PREPARE stmttr FROM @tr; EXECUTE stmttr; DEALLOCATE PREPARE stmttr; PREPARE stmt2 FROM @t1; EXECUTE stmt2; DEALLOCATE PREPARE stmt2; PREPARE stmttr1 FROM @tr1; EXECUTE stmttr1; DEALLOCATE PREPARE stmttr1; PREPARE stmt3 FROM @t2; EXECUTE stmt3; DEALLOCATE PREPARE stmt3; END$$ DELIMITER ;
Что я уже пробовал:
выбрасывание null в строке 1 ошибка 1064
CHill60
Если он работает иногда, а не другие, то он должен быть связан с данными - для каких входных значений он терпит неудачу?