您的位置:首页 > 数据库 > Oracle

Oracle中奇怪的【不等于号】

2014-03-07 13:13 260 查看
  在Oracle中,不等号有三种:<>,!=,^=

  例如:

  select * from test where name<>'xn'。返回的结果是name不为xn,且name不空的记录。但是这与我们想要得到的结果有出入,因为我们的目的是得到name为xn的全部记录,当然这也包括name为空的记录,所以这些写SQL语句是有问题的。为了解决这个问题,我们可以采用以下两种方案:

select * from test where instr(concat(name,'xx'),'xn') = 0 ;

select * from test where nvl(name,'xx')<>'xn' ;


  备注:null只能通过is null或者is not null来判断,其它操作符与null操作都是false。

  各数据库中的字符串连接方法

  1)MySQL:CONCAT()

  2)Oracle:CONCAT(),||

  3)SQL Server: +

例如:

SELECT 'this is '+'a test';                         返回值this a test

SELECT CONCAT('this is ','a test') from dual;   返回值this a test

SELECT 'this is '||'a test' from dual;           返回值this a test
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: