Oracle—不等于的表示
测试:
create table TB_SCORE (id NUMBER not null, tb_student_id NUMBER not null, c_name VARCHAR2(20), grade NUMBER) insert into TB_SCORE (ID, TB_STUDENT_ID, C_NAME, GRADE) values (2, 901, '英语', 80); insert into TB_SCORE (ID, TB_STUDENT_ID, C_NAME, GRADE) values (3, 902, '计算机', 65); insert into TB_SCORE (ID, TB_STUDENT_ID, C_NAME, GRADE) values (4, 902, null, 88); insert into TB_SCORE (ID, TB_STUDENT_ID, C_NAME, GRADE) values (5, 903, '中文', null); insert into TB_SCORE (ID, TB_STUDENT_ID, C_NAME, GRADE) values (6, 904, '计算机', 70); insert into TB_SCORE (ID, TB_STUDENT_ID, C_NAME, GRADE) values (7, 904, '英语', 92); insert into TB_SCORE (ID, TB_STUDENT_ID, C_NAME, GRADE) values (8, 905, '英语', 94); insert into TB_SCORE (ID, TB_STUDENT_ID, C_NAME, GRADE) values (9, 906, '计算机', 90); insert into TB_SCORE (ID, TB_STUDENT_ID, C_NAME, GRADE) values (10, 906, '英语', 85);如图:
例1:查询grade不等于80的数据
select * from tb_score where grade <> 80;
例2:查询c_name不等于中文的数据
select * from tb_score where c_name != '中文';
例3:查询c_name为null的数据
select * from tb_score where c_name is null;
总结:例1、例2中没有把null值查询出来,null只能通过is null或is not null判断;
例4:查询grade不等于80的数据
select * from tb_score where instr(concat(grade, 00), 80) = 0;
或者
select * from tb_score where nvl(grade, 00) <> 80;
例5:查询c_name不等于中文的数据
select * from tb_score where instr(concat(c_name, 'xx'), '中文') = 0;
或者
select * from tb_score where nvl(c_name, 'xx') <> '中文';