请问一下下面的两条sql语句在性能上有区别吗?
select * from t where name = 'Bob' and salary > 20000
select * from t where 1=1 and name = 'Bob' and salary > 20000 第二条语句加了where1=1会对性能有影响吗?
select * from t where name = 'Bob' and salary > 20000
select * from t where 1=1 and name = 'Bob' and salary > 20000 第二条语句加了where1=1会对性能有影响吗?
上次我写一个过程..里面...一条SQL就写了...1=1...
结果运行.很慢....
例如用PLSQL Developer工具如何分析这条语句的性能。有什么好的工具分析吗?
string sql;sql='select 1 from dual where 1=1 '定义一个string a;
a=' and 2=2 and 3=3 'excute immediate sql+a;
select * from table(dbms_xplan.display)总能用吧
请将一下为什么动态拼接SQL的时候会用这样的方式??学习!
为什么拼凑where 1=1呢,当然是为了sql更简单地拼凑了啊,比如一个界面有n个选项,这些选项都是可选的,那么程序如何根据前台填写的选项来拼凑sql呢??当然是不好拼凑的,比如:
姓名
年龄
职业select ... where ...
where后面怎么拼凑??比如我现在只选“年龄”,ok,where age=...,我现在选“年龄”和“职业”,where age=.. and career=...,。当然用if...else...什么的也拼凑,大不了全部用and condition拼凑完了之后将where后的第1个and 去掉,用where 1=1先顶死,然后全部用and condition拼凑就简洁多了,而且CBO会过滤1=1,当他是不存在的,多好。其他的数据库可能不一定优化器会过滤。
1<> 1 or是类似的