年轻人不谈论武术,到底1 = 1在哪里?
OF:San来源:cloud.tencent.com/developer/article/1475146由程序代码生成(例如Java),如果条件1 = 1之后的条件是动态变化,则条件1 = 1之后的条件。例如:String& nbsp; sql =” select& nbsp; *& nbsp; from& nbsp; table_name& nbsp; where& nbsp; 1 = 1''; if(& conditon& nbsp; 1)& nbsp; {& nbsp;& nbsp;& nbsp;& nbsp;& nbsp;& nbsp; sql = sql +“ & nbsp;& nbsp;& nbsp; var2 = value2“;& nbsp;& nbsp;& nbsp;} if(conditon& nbsp; 2) {& nbsp;& nbsp;& nbsp;& nbsp;& nbsp; sql = sql +“& nbsp;& nbsp; and& nbsp; var3 = value3”其中1 = 1是为了避免语法错误,因为where关键字之后的第一个单词是直接“和”的。
在动态SQL中,将1 = 1的AND条件连接起来,以避免语法错误,作为where关键字直接为“ and”之后的第一个单词。在where之后必须始终有一条语句,并在加上1 = 1之后,可以确保语法不会出错! select * from table,其中1 = 1,因为表中没有名为1的字段,因此该SQL等效于select * From table,此SQL语句显然是全表扫描,需要大量的IO操作。
数据量越大,速度越慢。建议在查询时添加强制项,即在1 = 1处添加一些常用的强制条件,并添加这些必需条件以创建适当的索引,这样可以大大提高“复制表”的效率。
从& nbsp; Source_table& nbsp;其中& nbsp; 1 = 1;中选择& nbsp; *& nbsp;创建表table_name& nbsp; “复制表结构”从& nbsp; Source_table& nbsp;其中& nbsp; 1& lt;>中创建表table_name& nbsp;作为& nbsp;选择& nbsp; *& nbsp; 1;免责声明:本文内容经21ic授权后发布,版权归原作者所有。该平台仅提供信息存储服务。
本文仅代表作者的个人观点,并不代表该平台的立场。如有任何疑问,请与我们联系,谢谢!。