Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/variables/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何在mysql中将sql模式变量设置为局部变量_Mysql_Variables_Set - Fatal编程技术网

如何在mysql中将sql模式变量设置为局部变量

如何在mysql中将sql模式变量设置为局部变量,mysql,variables,set,Mysql,Variables,Set,我想要的是,我想要将sql_模式变量设置为局部变量,而不是会话或全局变量。这样做的原因是,我想在执行一个查询后取消sql模式变量的更改。下面的会议和全球都很好地工作,但这不是我想要的。全局模式永远保持sql模式为空模式。会话1在连接关闭之前保持sql模式为空。我想要的是,保持sql模式,直到只执行一个命令 mysql> set global sql_mode=''; mysql> set session sql_mode=''; mysql查询:- SELECT tc_exe_gr

我想要的是,我想要将sql_模式变量设置为局部变量,而不是会话或全局变量。这样做的原因是,我想在执行一个查询后取消sql模式变量的更改。下面的会议和全球都很好地工作,但这不是我想要的。全局模式永远保持sql模式为空模式。会话1在连接关闭之前保持sql模式为空。我想要的是,保持sql模式,直到只执行一个命令

mysql> set global sql_mode='';
mysql> set session sql_mode='';
mysql查询:-

SELECT tc_exe_grp_num,tcs.tc_tc_id,tcs.tcs_id  
FROM tc_exe_res tcer 
INNER JOIN tcs tcs 
ON tcs.tcs_id = tcer.tcs_tcs_id  
WHERE tcs.tc_tc_id='1' 
AND tcs.tc_tc_id='1' 
GROUP BY tc_exe_grp_num 
ORDER BY tc_exe_grp_num ;


请帮帮我。

我找不到直接的答案,但有一个解决方案

首先将“sql模式”设置为空模式,然后在执行CURRY后,将“sql模式”设置为以前具有的值,按照以下方式进行尝试

    set session sql_mode='';

    SELECT tc_exe_grp_num,tcs.tc_tc_id,tcs.tcs_id FROM tc_exe_res tcer INNER JOIN tcs tcs ON tcs.tcs_id = tcer.tcs_tcs_id WHERE tcs.tc_tc_id='1' AND tcs.tc_tc_id='1' group by tc_exe_grp_num ORDER BY tc_exe_grp_num ;

    set session sql_mode='ONLY_FULL_GROUP_BY,STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION';

@@sql\u模式
是会话变量,而不是局部变量

可以检索sql_模式的当前设置,并将其保存在用户定义的变量中,然后稍后将sql_模式设置回原始设置

例如:

 -- save current setting of sql_mode in user defined variable
 -- change sql_mode to desired setting
 SET @SAVE_sql_mode = @@sql_mode ;
 SET @@sql_mode = 'NO_ENGINE_SUBSTITUTION' ; 

 -- subsequent operations run under new setting of sql_mode
 SELECT '...';


 -- set sql_mode back to saved setting
 SET @@sql_mode = @SAVE_sql_mode ;  

您只需使用
SET@@SESSION.SQL\u MODE=@@GLOBAL.SQL\u MODE将其放回。技术上
SET@@SQL\u MODE=@@GLOBAL.SQL\u MODE
做了完全相同的事情,但我喜欢前一个版本,因为它对下一个阅读代码的可怜虫来说是明确的,你在做什么。或者,在之前将当前值存储在用户定义的变量中,然后在之后将其放回<代码>设置@_SQL_模式=@@SQL_模式
before和
SET@@SQL\u MODE=@\u SQL\u MODE
after将临时将当前值存储在名为
\u SQL\u MODE
的变量中(其中单个
@
是用户定义变量的符号,不需要声明)。