在mysql中使用和时转义单引号

在mysql中使用和时转义单引号,mysql,Mysql,我有这个触发程序 BEGIN declare last_inserted_number VARCHAR(100) DEFAULT '0800100200'; declare last_inserted_message VARCHAR(100) DEFAULT 'Lorem Ipsum'; declare le_keyword VARCHAR(100) DEFAULT 'loan'; set last_inserted_number = NEW.dest_msisdn; set last_ins

我有这个触发程序

BEGIN
declare last_inserted_number VARCHAR(100) DEFAULT '0800100200';
declare last_inserted_message VARCHAR(100) DEFAULT 'Lorem Ipsum';
declare le_keyword VARCHAR(100) DEFAULT 'loan';

set last_inserted_number = NEW.dest_msisdn;
set last_inserted_message = NEW.text_message;
set le_keyword = 'loan';

if ( not exists(select id from transactions where tel = last_inserted_number) && last_inserted_message = le_keyword)  then
我想知道mysql是如何解释的

如果不存在,则从事务中选择id,其中tel=last\u inserted\u number&&last\u inserted\u message=le\u关键字,然后

mysql在执行程序时是否会为您放弃贷款?。其次,如果我将变量le_关键字替换为一个数字,比如说1,那么程序将按照我的预期执行逻辑


当le_关键字=loan时,逻辑不会像我预期的那样执行。我得出结论,单引号和双引号是问题所在,因为没有语法错误。

值中不包括包含字符串文字的单引号。如果希望在字符串文字中包含一个单引号,则需要使用额外的单引号对其进行转义。e、 字符串文字“its”的值长度为四个字符,第三个字符为单引号。现在还不清楚为什么需要前两个变量,为什么不在需要的地方引用NEW.dest_msisdn和NEW.text_消息。程序有点长,我需要将变量保存在一个变量中。