javascript和执行步骤中的范围(scope in javascript and execution steps)
(function() { var a = 'g'; function foo() { console.log(a); a = 7; // } console.log(foo(), a); }());
任何人都可以解释这个代码示例的逐步执行和输出。 我得到了'g undefined 7'
(function() { var a = 'g'; function foo() { console.log(a); a = 7; // } console.log(foo(), a); }());
Can anybody explain the step by step execution and out put of this code sample. I got the out put as 'g undefined 7'
原文:https://stackoverflow.com/questions/32352419
更新时间:2021-09-05 10:09
最满意答案
这里有几件事情错了。
- 分隔符。 当您创建MySQL过程或触发器时,您需要非常明确地定义分隔符,以便查询解释器可以区分过程中行的末尾和声明的结尾。
- BEGIN声明的位置。 应该在FOR EACH ROW之后直接进行。
- 使用WHEN而不是IF。
- 使用PRINT代替SIGNAL SQLSTATE'...'SET MESSAGE_TEXT ='...'。 这就是你在MySQL 5.5+中引发异常的方法。
这是应该工作的代码!
DELIMITER $$ CREATE TRIGGER testa_trig BEFORE INSERT ON testa FOR EACH ROW BEGIN IF (NEW.c > 100) THEN SIGNAL SQLSTATE '02000' SET MESSAGE_TEXT = 'Warning: c > 100!'; END IF; END$$ DELIMITER ;
Couple of things wrong here.
- Delimiters. When you make a MySQL procedure or trigger, you need to be very explicit about delimiters so the query interpreter can distinguish between ends of lines in your procedure and the end of your declaration.
- Location of the BEGIN statement. It should be directly after FOR EACH ROW.
- Use of WHEN instead of IF.
- Use of PRINT instead to SIGNAL SQLSTATE '...' SET MESSAGE_TEXT = '...'. This is how you raise exceptions in MySQL 5.5+.
Here is code that should work!
DELIMITER $$ CREATE TRIGGER testa_trig BEFORE INSERT ON testa FOR EACH ROW BEGIN IF (NEW.c > 100) THEN SIGNAL SQLSTATE '02000' SET MESSAGE_TEXT = 'Warning: c > 100!'; END IF; END$$ DELIMITER ;
相关问答
更多-
TCP/IP模型是一个________。[2023-05-19]
a -
根据评论:) 您需要BEFORE INSERT触发器。 在该触发器中,您可以在记录到达永久存储之前更改记录。 使用您的示例,此触发器将定义如下: DELIMITER $$ CREATE TRIGGER moodle.update_lang BEFORE INSERT ON moodle.mdl_user FOR EACH ROW BEGIN SET NEW.lang='hu'; END$$ DELIMITER ; 你不能在触发引用的同一个表上使用UPDATE的原因是因为它可能(并且会)导致无限循环。 ...
-
下列中不属于面向对象的编程语言的是?[2022-05-30]
a -
你可以使用OLD。 或者新的。 因为在插入两个值相同之后触发此触发器。 您可以使用以下命令访问interred行的所有属性(如果它是行级触发器): NEW.orderItemID NEW.rate 等等 You could use OLD. or NEW. since this trigger is fired after the insert both values are the same. You can access all properties of the interred row (if i ...
-
MYSQL在插入订单时触发插入另一个表的通知(MYSQL Trigger when a order is inserted a notification inserted into another table)[2023-03-27]
尝试: DELIMITER $$ CREATE TRIGGER `productTrigger` AFTER INSERT ON `Order` FOR EACH ROW BEGIN /*DECLARE ui,pn VARCHAR(50); SELECT productName INTO pn FROM Order; SELECT userID INTO ui FROM Product; INSERT INTO Notifications(userID,Message) VALUES(u ... -
就在这里。 您可以调用不存在的存储过程。 例如 - ... BEGIN IF NEW.Journey_Day < CURDATE() THEN CALL proc_error_date(); END IF; END ... Yes, there is. You can call nonexistent stored procedure. For example - ... BEGIN IF NEW.Journey_Day < CURDATE() THEN CALL proc_e ...
-
为什么INSTEAD OF UPDATE触发器的INSERTED表空?(Why is the INSERTED table of an INSTEAD OF UPDATE trigger empty?)[2022-09-30]
当然,当您更新表中不存在的行时,INSERTED伪表中不存在行:您在TradePending行上为Trade发出UPDATE语句! 此外,你的INSTEAD OF INSERT触发器被破坏了。 它仅适用于单行插入,即使对于那些在并发下也会失败的插入。 使用基于集合的MERGE。 最终,您正在设计一个与应用程序的连接断开的数据模型。 创建INSTEAD OF触发器以完全改变遗留代码使用的表的形状仅适用于目前为止,您遇到的这个问题只是未来的许多问题之一。 最终,您的客户端代码必须插入/更新/删除正确的表。 作为 ... -
这里有几件事情错了。 分隔符。 当您创建MySQL过程或触发器时,您需要非常明确地定义分隔符,以便查询解释器可以区分过程中行的末尾和声明的结尾。 BEGIN声明的位置。 应该在FOR EACH ROW之后直接进行。 使用WHEN而不是IF。 使用PRINT代替SIGNAL SQLSTATE'...'SET MESSAGE_TEXT ='...'。 这就是你在MySQL 5.5+中引发异常的方法。 这是应该工作的代码! DELIMITER $$ CREATE TRIGGER testa_trig BEF ...
-
对于TSQL插入/更新触发器,可以插入和删除都为空吗?(For a TSQL insert/update trigger, can inserted and deleted both be empty?)[2022-03-03]
回答我自己的问题。 当触发表上的更新语句不更新任何行时,会发生这种情况。 触发器仍然会触发,但插入和删除表空。 例如: UPDATE Test Set somefield=0 WHERE id='Values does not exist' Answering my own question. This occurs when an update statement on the triggered table doesn't update any rows. The trigger still fire ... -
SQL Server触发器:INSERTED和DELETED不存在。(SQL Server Trigger: INSERTED and DELETED does not exist. What is it?)[2021-11-08]
仅当UPDATE语句未修改任何行时,该条件才为真。 The condition will be true only when no rows were modified by the UPDATE statement.