1.在语句中找到和消除空值
select first_name,last_name from hr.employees where commission_pct is null
is null 和 is not null ,null值不跟任何值相等 ,任何值不和null相等,null不等于null。
2.排序
Oracle 支持区分大小写和不区分大小写两种排序方式。有一个环境变量 NLS_SORT 可以控制排序是否区分大小写。
默认是区分大小写的,即 NLS_SORT = BINARY ,大写的值会排在前面。
如果希望排序不区分大小写则将变量值设置为 BINARY_CI。
alter session set NLS_SORT = 'BINARY_CI'
当然我们也可不改变变量值,使用UPPER和LOWER函数把需要比较和排序的字段都转为大写或小写后进行排序。
当我们进行“=”比较时,我们可以在比较时不区分大小写,只需要将会话中的变量NLS_COMP由BINARY改为 LINGUISTIC。
查看session中这些变量的sql如下:
select * from nls_session_parameters
3.MERGE语句的使用
功能:将新数据插入到表中。
记录是否存在,由主键进行判断,如果主键不存在该表,则插入该行。如果主键信息存在,则通过匹配键的其他详细信息更新该行。
egg: 将NEW_COUNTRIES表中的一些国家信息添加到HR.COUNTIES表中。
merge into hr.countries c using ( select country_id,country_name from hr.new_countries) nc on (c.country_id = nc.country_id) when matched then update set c.country_name = nc.country_name when not matched then insert (c.country_id,c.country_name) values(nc.country_id,nc.country_name)