Article Directory
The database data used in this lesson has been written in the basic operations of Oracle database tables and the solution of the null value problem , just paste and copy it yourself!
1. Alias
You can alias fields, expressions, tables, etc., and try to use meaningful English words
2. Deduplicate distinct
- Can only follow the select, distinct must be followed by the keyword that needs to be deduplicated
- When multiple fields are added after distinct, it means that multiple fields are jointly uniquely deduplicated
--例如:查询该公司有哪些职位?
select distinct job from emp_jinli;
--例如:查询员工分布在哪些部门?
select distinct deptno from emp_jinli;
--例如:每个部门有哪些职位?
select distinct deptno,job from emp_jinli;
3.where filter
Single-line comparison operators <,>,> =, <=,! =, =
--例如:查询哪些员工的薪资大于5000?
select ename,salary from emp_jinli where salary>5000;
4.between…and/not between…and
Represents a closed interval, including critical values at both ends
--例如:查询哪些员工的薪资大于5000,小于10000?
select ename,salary from emp_jinli where salary between 5000 and 10000;
5.in (parameter list) / not in (parameter list)
--例如:查询哪些员工的薪资是5000,8000,10000?
select ename,salary from emp_jinli where salary in(5000,8000,10000);
select ename,salary from emp_jinli where salary=5000 or salary = 8000 or salary=10000;
6. Fuzzy query
- like keyword: used with the following three symbols
- %: Indicates 0 or more characters
- _: Indicates a character
- /: Escape escape character, indicating a special symbol
--例如:查询员工的职位中包含‘sale’的员工信息?
select * from emp_jinli where job like '%sale%';
--例如:查询哪些员工的职位中第二个字符是‘a’的员工信息?
select * from emp_jinli where job like '_a%';
--例如:查询该用户下,有多少张表的表名是以‘T_’开头?
select count(*) from user_tables where table_name like 'T\_%' ESCAPE '\'; //"_"是特殊符号
7. Character processing function:
- lower (): uppercase to lowercase
- upper (): lowercase to uppercase
- initcap (): capitalize the first letter
--例如:查询该用户下,有多少张表的表名是以‘T_’开头?
select count(*) from user_tables where initcap(table_name) like 'T\_%' ESCAPE '\';
select upper('ABbvcvCDEFG') from dual;
8、is null/is not null
--例如:查询哪些员工没有奖金?
select ename,bonus from emp_jinli where bonus is null;
--例如:哪些员工有奖金?
select ename,bonus from emp_jinli where bonus is not null;
9. Numeric functions
- round (value, the number of digits after the decimal point): rounded
- trunc (value, number of digits after decimal point): intercept
select round(3.1415926,3) from dual; //结果是3.141
select trunc(3.1415926,3) from dual; //结果是3.141
10. Date function
- Date addition and subtraction operations, in days
- If it is less than one day, it is expressed as a decimal and can be processed with round ()
--例如:计算员工入职多少天?
select ename,round(sysdate-hiredate) days from emp_jinli;//别名表示也可以不加as
--例如:查询本月最后一天?
select last_day(sysdate) from dual;