1.字符串连接运算符||
--检索顾客信息,输出时将first_name和last_name连接为一个字符串
select customers.*, first_name||' '||last_name name
from customers;
2.空值
--检索出生日期为空的顾客的信息
select * from customers
where dob is null;
可在select子句中使用NVL(表达式,value)函数,当表达式为空值时,返回value值。
--检索顾客的信息,如果出生日期为NULL,则输出’ 1900-01-01’
select customers.*, nvl(dob,date'1900-1-1') from customers;
3.使用DISTINCT禁止显示重复行
--从订单表(purchases)中查询购买过商品的用户的编号
select distinct customer_id, product_id
from purchases;
4. 比较操作符: =, <>, !=, < , > , <= , >=, ANY, SOME, ALL
使用ANY将一个值和列表中的值进行比较,只要有一个值满足条件,则输出该条记录;
使用ALL将一个值和列表中的值进行比较,在所有值都满足条件后才输出该条记录。
ANY和SOME具有相同的功能,但ANY更容易理解,语义更明确,应该使用ANY代替SOME。
--检索编号为1、 3、 4的员工信息
select * from employees where employee_id = any(1, 3, 4);
--以下方式也可以实现
select * from employees where employee_id in (1, 3, 4);
5. oracle列名不区分大小写