本文介绍了错误 #1109 - 由触发器引起的字段列表中的未知表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是我的触发器.

我想在 1 张桌子 (pelayanan) 上制作触发器.

I want to make trigger on 1 table (pelayanan).

CREATE DEFINER=`root`@`localhost` TRIGGER `before_insert_pelayanan` 
BEFORE INSERT ON `pelayanan` FOR EACH ROW 
IF NEW.`ESTIMASI` IS NULL OR NEW.`ESTIMASI` = 0 AND
    `dbhpl`.`pelayanan`.`DAYA` <= 5500 
    THEN SET NEW.ESTIMASI = 4; 
ELSEIF NEW.ESTIMASI IS NULL OR NEW.ESTIMASI = 0 AND
    `dbhpl`.`pelayanan`.`DAYA` <= 33000 AND 
    `dbhpl`.`pelayanan`.`DAYA` >= 6600 
    THEN SET NEW.ESTIMASI = 15; 
ELSEIF NEW.ESTIMASI IS NULL OR NEW.ESTIMASI = 0 AND
   `dbhpl`.`pelayanan`.`DAYA` <= 197000 AND 
   `dbhpl`.`pelayanan`.`DAYA` >= 41500 
    THEN SET NEW.ESTIMASI = 40; 
ELSE SET NEW.ESTIMASI = 100; 
END IF

当我执行触发器时,它已被创建.但是,当我将数据插入表 pelayanan 时,它变成了

When I execute the trigger, it has been created. But, when I insert data into table pelayanan, It become

#1109 - 字段列表中的未知表 'pelayanan'.

我该如何解决这个问题?

How can I resolve this?

我必须删除dbhpl.pelayanan.DAYA 成为pelayanan.DAYADAYA.但是,它不起作用.

I have to remove dbhpl.pelayanan.DAYA become pelayanan.DAYA and DAYA. But, It doesn't work.

推荐答案

在列名前使用 NEW.这是正确的代码-

use NEW before column name. This is the right code-

mysql>
    CREATE DEFINER=`root`@`localhost` TRIGGER `before_insert_pelayanan`
    BEFORE INSERT ON `pelayanan` FOR EACH ROW 
        IF NEW.`ESTIMASI` IS NULL OR NEW.`ESTIMASI` = 0 AND
            `NEW`.`DAYA` <= 5500 
            THEN SET NEW.ESTIMASI = 4; 
        ELSEIF NEW.ESTIMASI IS NULL OR NEW.ESTIMASI = 0 AND
            `NEW`.`DAYA` <= 33000 AND 
            `NEW`.`DAYA` >= 6600 
            THEN SET NEW.ESTIMASI = 15; 
        ELSEIF NEW.ESTIMASI IS NULL OR NEW.ESTIMASI = 0 AND
           `NEW`.`DAYA` <= 197000 AND 
           `NEW`.`DAYA` >= 41500 
            THEN SET NEW.ESTIMASI = 40; 
        ELSE SET NEW.ESTIMASI = 100; 
    END IF

Query OK, 0 rows affected (0.11 sec)

mysql> insert into pelayanan values ();
Query OK, 1 row affected (0.08 sec)

mysql> select * from pelayanan ;
+----------+------+
| ESTIMASI | daya |
+----------+------+
| 4        | NULL |
+----------+------+
1 row in set (0.00 sec)

这篇关于错误 #1109 - 由触发器引起的字段列表中的未知表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-27 04:00