数据库
首页 > 数据库> > mysql-操作数应包含1列

mysql-操作数应包含1列

作者:互联网

每当我尝试插入表集中时,获取Operand都应包含1列mysql错误.

我在Google上搜索并发现了很多类似的问题,但是它们始终是解决当前问题的关键.我有mysql 5.6.我可以使用多个TIMESTAMPS.

这是我的代码:

INSERT INTO `sets` (`tabler_name`) VALUES ("leads_auto");

这是我的桌子:

CREATE TABLE IF NOT EXISTS `lms`.`sets` (
    `set_id` BIGINT NOT NULL AUTO_INCREMENT,
    `on_off` SMALLINT NOT NULL DEFAULT 0,
    `tabler_name` VARCHAR(45) NULL,
    `origin_date` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
    `last_modified_date` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
    `original_count` INT NULL,
    `current_count` INT NULL,
    `source_type` VARCHAR(45) NULL,
    `source` VARCHAR(45) NULL,
    `method` VARCHAR(45) NULL,
    `agent` VARCHAR(45) NULL,
    `dupes` INT NULL,
    `bads` INT NULL,
    `aged` INT NULL COMMENT 'This table keeps track of the record sets that enter the system.        Example: a set of leads imported into the database.',
    PRIMARY KEY (`set_id`)
) ENGINE = InnoDB;

存储过程:

DELIMITER //

CREATE PROCEDURE `lms`.`leads_to_bak` ()
BEGIN
SET @table1 = (SELECT `tabler_name` FROM sets WHERE on_off=0 LIMIT 1);
SET @table2 = CONCAT(@table1, '_bak');
SET @SQL1 = CONCAT('INSERT INTO ',@table2, '(', (SELECT
REPLACE(GROUP_CONCAT(COLUMN_NAME), 'lead_id,', '') FROM INFORMATION_SCHEMA.COLUMNS
WHERE TABLE_NAME = @table2), ')', ' SELECT ', (SELECT                                                                   REPLACE(GROUP_CONCAT(COLUMN_NAME), 'lead_id,', '') FROM INFORMATION_SCHEMA.COLUMNS WHERE       TABLE_NAME = @table1), ' FROM ', @table1);
PREPARE stmt FROM @sql1;
EXECUTE stmt;
END//

DELIMITER ;
USE `lms`;

触发

DELIMITER $$

USE `lms`$$

CREATE TRIGGER `lms`.`after_insert_into_leads`
AFTER INSERT ON `sets` FOR EACH ROW
BEGIN
IF (SELECT * FROM sets WHERE on_off=0 LIMIT 1) THEN
CALL lms.leads_to_bak();
END IF;
END$$

DELIMITER ;
USE `lms`;

我的例程没有发现任何问题.删除例程和触发器似乎可以解决问题.

解决方法:

触发时,您是要把EXISTS放在IF之后吗?像这样:

CREATE TRIGGER `lms`.`after_insert_into_leads`
AFTER INSERT ON `sets` FOR EACH ROW
BEGIN
IF EXISTS (SELECT * FROM sets WHERE on_off=0 LIMIT 1) THEN
CALL lms.leads_to_bak();
END IF;
END$$

标签:mysql-error-1064,sql,mysql
来源: https://codeday.me/bug/20191127/2075455.html