Oracle中奇怪的【不等于号】

  在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
原文地址:https://www.cnblogs.com/ningvsban/p/3586223.html