MySQL过程语法错误“缺少结束”

时间:2015-11-17 13:27:00

标签: mysql stored-procedures

我必须按照程序尝试动态创建视图。

createVariation

我收到错误“Missing END”,我不明白为什么。

语法检查器在Line

的末尾加下semikolon
function createVariation(source) {
    var v = Object.create(source);
    v.options = Object.create(source.options);
    return v;
}

var variation = createVariation(original);
var firstDiv = createVariation(variation);
var secondDiv = createVariation(variation);

当我将dealloc移动到最后时,syntac检查器高亮显示之前的行中的semikolon。

CREATE DEFINER=`root`@`%` PROCEDURE `uspCreateViewFromTable`(IN ViewName varchar(255), IN TableName varchar(255))
BEGIN
#View Droppen falls sie schon erstellt wurde
SET @s = CONCAT('DROP VIEW IF EXISTS ',ViewName);
PREPARE stmt FROM @s;
EXECUTE stmt;
DEALLOCATE PREPARE stmt;


# Verwendete Spalten filtern und Statement bauen
#SET @columns = CAST('SELECT ' AS VARCHAR(10));

DECLARE column varchar(500);
DECLARE column_cursor FOR SELECT column_name FROM INFORMATION_SCHEMA.COLUMNS WHERE table_name = Tablename;
DECLARE CONTINUE HANDLER FOR NOT FOUND SET done = TRUE;
OPEN column_cursor

read_loop: LOOP
    FETCH column_cursor INTO column
    # do something
    SELECT column;
    IF done THEN
      LEAVE read_loop;
    END IF;
END LOOP;
CLOSE column_cursor;

END

如果我在dealloc之后删除了everthing它可以工作。

1 个答案:

答案 0 :(得分:4)

一些问题:

  • DECLARE只允许在BEGIN ... END复合语句中使用,并且必须在其开始之前,在任何其他语句之前。见13.6.3 DECLARE Syntax
  • ERROR 1193(HY000):未知的系统变量'done'。
  • 检查游标的语法。见13.6.6.2 Cursor DECLARE Syntax
  • @media screen and (min-width: 992px) { .col-md-1.col-new{ width: ... } } 是关键字和保留字。见9.3 Keywords and Reserved Words
  • 遗漏了一些column
;