12.Oracle数据库SQL开发之 比较值
欢迎转载,转载请标明出处:http://blog.csdn.net/notbaron/article/details/49106969
比较符号如下图1所示:
例如不等于
SQL>select * from customers where customer_id <> 2;
CUSTOMER_ID FIRST_NAME LAST_NAME DOB PHONE
----------- ---------- ---------- ---------------------
1 John Brown 01-JAN-65 800-555-1211
3 Steve White 16-MAR-71 800-555-1213
4 Gail Black 800-555-1214
5 Doreen Blue 20-MAY-70
使用大于操作符,如下
SQL>select product_id,name from products where product_id > 8;
PRODUCT_ID NAME
---------- ------------------------------
9 Classical Music
10Pop 3
11Creative Yell
12My Front Line
小于等于如下:
SQL>select rownum,product_id,name from products where rownum <= 3;
ROWNUM PRODUCT_ID NAME
---------- ----------------------------------------
1 1 Modern Science
2 2 Chemistry
3 3 Supernova
此外,WHERE子句可以使用ANY操作符将一个值与列表中的任何值进行比较。此时必须在ANY之前添加一个=, <>, <, >,<=或>=操作符。
例如:
SQL>select * from customers where customer_id > any ( 2,3,4);
CUSTOMER_IDFIRST_NAME LAST_NAME DOB PHONE
----------- ---------- ---------- ---------------------
3 Steve White 16-MAR-71 800-555-1213
4 Gail Black 800-555-1214
5 Doreen Blue 20-MAY-70
也可以将一个值与列表中的所有值进行比较,此时必须在ALL之前放上一个=,<>,<,>,<=或>=操作符。
例如:
SQL>select * from customers where customer_id > all ( 2,3,4);
CUSTOMER_IDFIRST_NAME LAST_NAME DOB PHONE
----------- ---------- ---------- ---------------------
5 Doreen Blue 20-MAY-70