"<>"、"!="、"not in"、"exsits"和"not exists"的使用规范
来源:互联网 发布:软件项目成本多少钱 编辑:程序博客网 时间:2024/05/29 15:25
错误的写法:
select a.id,a.subject,a.create_type
from product
where status <> 'new'
and owner_member_id = :1
正确的写法:
select a.id,a.subject,a.create_type
from product
where status in ('auditing','modified','service-delete','tbd','user-delete','wait-for-audit')
and owner_member_id = :1
错误的写法:
select a.id,a.subject,a.create_type
from product
where create_type not in ('new_order','vip_add')
and owner_member_id = :1
正确的写法:
select a.id,a.subject,a.create_type
from product
where create_type = 'cust_add'
and owner_member_id = :1
2、原则上不允许使用"exsits"和"not exists"查询,应转换成相应的"等连接"和外连接来查询
错误的写法:
select a.id
from company a
where not exsits (select 1
from av_info_new b
where a.id = b.company_id
)
正确的写法:
select a.id
from company a,av_info_draft b
where a.id = b.company_id(+)
and b.company_id is null
错误的写法:
select count
from company a
where exsits (select 1
from av_info_new b
where a.id = b.company_id
)
正确的写法:
select count
from company a,av_info_draft b
where a.id = b.company_id
注:在通过等连接替换exsits的时候有一点需要注意,只有在一对一的时候两者才能较容易替换,如果是一对多的关系,直接替换后两者的结果会出现不一致情况。因为exsits是实现是否存在,他不care存在一条还是多条,而等连接时返回所关联上的所有数据。
3、如有特殊需要无法完成相应的转换,必须在DBA允许的情况下使用"<>"、"!="、"not in"、"exsits"和"not exists"
- "<>"、"!="、"not in"、"exsits"和"not exists"的使用规范
- not in 和not exists的使用
- NOT In和NOT EXISTS使用的区别
- not in和not exists的区别
- IN,NOT IN,EXISTS,NOT EXISTS的用法和差别
- exists,in 和 not in ,not exists
- SQL里的EXISTS与in、not exists与not in 效率比较和使用
- SQL里的EXISTS与in、not exists与not in 效率比较和使用
- SQL的EXISTS与in、not exists与not in 效率比较和使用
- SQL里的EXISTS与in、not exists与not in 效率比较和使用
- sql Exists in 文章1:SQL里的EXISTS与in、not exists与not in 效率比较和使用
- not exists 和not in
- not in 和 not exists
- exists和not exists的使用
- oracle exists和not exists的使用
- SQL里的EXISTS与in、not exists与not in 效率比较和使用(转)
- Oracle中not exists 与not in 的使用情况
- oracle中的exists 和not exists、in的 用法详解
- mac版本cornerstone的无限期破解方法
- R12 查询EBS用户相关SQL
- 网络连接类型判断
- 关掉机器上的firewall
- 学写块设备驱动(一)----了解gendisk及request处理函数
- "<>"、"!="、"not in"、"exsits"和"not exists"的使用规范
- ScannerTimeoutException 问题分析与解决方法
- 申请签证时工作单位证明英文摸版
- vi编辑器命令总结
- 一个能够递归执行的makefile小例子
- Indy IdTcpserver
- oracle插入日期时间
- 创业需要些什么
- JOS环境搭建