set operators UNION, UNION ALL, INTERSECT, and MINUS
这三个操作符优先级相同,从左至右,除非有括号
单库单表操作,单库多表操作,多库多表操作(用到dblink)
transcendental function 超越函数,如:sin,cos,tan等
函数相似于操作符,它们都维护数据项并返回结果,在参数格式上又不同于操作符
没有任何参数的函数与伪列相似
伪列每行返回不同的值
没有任何参数的函数每行返回一样的值
二者相互转换
select nls_charset_name(2) from dual
select nls_charset_id('we8dec') from dual
以下三个的列名是不一样的
select length('canada') from dual length('canada')作为列名并且大写
select length('canada') woshi from dual woshi作为列名并且大字 单字节字符集返回6,如果是双字节数据库字符集返回12
select length('canada') “woshi” from dual woshi作为列名原样输出(引号里是什么就是什么) 单字节字符集返回6,如果是双字节数据库字符集返回12
SELECT CONCAT(CONCAT(last_name, '''s job category is '), job_id) "Job"
FROM employees
WHERE employee_id = 152;
concat This function is equivalent to the concatenation operator (||).
比较函数
SELECT GREATEST('HARRY', 'HARRIOT', 'HAROLD') "Greatest" FROM DUAL;
SELECT GREATEST (1, '3.925', '2.4') "Greatest" FROM DUAL;
环境与标识函数
select userenv('terminal') from dual
select userenv('sid') from dual
select user,uid from dual
先查询某个字段并排序
select org_id from user_orgop_relation order by org_id desc;
根据上面结果,去一下重
select distinct org_id from user_orgop_relation order by org_id desc;
应用一下聚合函数,查看某个字段重复出现的次数
select org_id,count(org_id) from user_orgop_relation group by org_id order by org_id desc;
应用一下数学函数,其实min,max通过order by 中的第一个与最后一个可以看出来
select min(org_id) from user_orgop_relation;
数学函数可以嵌套,但是必须有group by子句
select avg(min(org_id)) from user_orgop_relation group by user_id;
数字函数
select abs(-20) "absolute" from dual;
字段去重查询
select distinct style from music
批量修改某字段
update music set style = "ost" where style like "%影视剧%"
先查询,再添加或修改数据字段
select * from music where language is null
update music set language = "外国" where language is null