Home > Database > Mysql Tutorial > MYSQL where 1=1判定中的作用说明_MySQL

MYSQL where 1=1判定中的作用说明_MySQL

WBOY
Release: 2016-06-01 13:22:20
Original
1116 people have browsed it

bitsCN.com 于是在网上

查了查,在这里就浅谈一下:
1=1 永真, 11 永假。

11 的用处:
用于只取结构不取数据的场合
例如:
create table table_temp tablespace tbs_temp as
select * from table_ori where 11
建成一个与table_ori 结构相同的表table_temp,但是不要table_ori 里的数据。(除了表结构,其它结

构也同理)

1=1的用处
用于动态SQL
例如 lv_string := ‘select tbl_name,tbl_desc from tbl_test where 1=1 ‘||l_condition;
当用户选择了查询的名称'abc'时l_condition :='and tbl_name = ”abc””;但是当用户没有

选择名称查询时l_condition就为空 这样 lv_string = ‘select tbl_name,tbl_desc from tbl_test

where 1=1 ‘ ,运行也不会出错,相当于没有限制名称条件。但是如果没有1=1的条件,则lv_string =

‘select tbl_name,tbl_desc from tbl_test where ‘;这样就会报错。

除了1=1 或11之外的其它永真永假的条件同理。bitsCN.com

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template