1、显示当前所在用户;

show user;

2、查询用户语言环境,借助dual伪表;

select userenv('language') from dual;

3、查看emp表结构;

desc emp;

4、查询emp表所有信息;

select * from emp;

5、使用全列名查询emp表所有信息;

select empno,ename,job,mgr,hiredate,sal,comm,deptno from emp;

6、使用列别名查询emp表所有信息;

select empno 员工编号,ename 员工姓名,job 职位,mgr 上级,hiredate 雇佣日期,sal 工资,comm 奖金,deptno 部门编号 from emp;

7、查询emp表员工编号为7876的所有信息;

select * from emp where empno=7876;

8、查询emp表消除重复职位信息;

select distinct job from emp;

9、查询emp表每个雇员的工资;

select ename 员工姓名,sal 工资 from emp;

10、查询emp表每个雇员的年薪;

select ename 员工姓名,sal * 12 年薪 from emp;

11、查询emp表员工编号、员工姓名、职位信息,使用字符串连接;

select '员工编号:' || empno || ',员工姓名:' || ename || ',职位:' || job || ' ' from emp;

12、查询emp表每月能得到奖金的雇员;

select * from emp where comm is not null;

13、查询emp表每月得不到奖金的雇员;

select * from emp where comm is null;

14、查询emp表工资大于1500并且有奖金领取的雇员;

select * from emp where comm is not null and sal > 1500;

15、查询emp表工资大于1500或者有奖金领取的雇员;

select * from emp where comm is not null or sal > 1500;

16、查询emp表工资不大于1500和没有奖金领取的雇员;

– 使用逻辑运算符 not

select * from emp where comm is null and not(sal > 1500);

– 不使用逻辑运算符 not

select * from emp where comm is null and sal <= 1500;

17、查询emp表工资大于1500但小于3000的全部雇员;

– 方式一

select * from emp where sal > 1500 and sal < 3000;

– 方式二 使用 between and 闭区间

select * from emp where sal between 1500 and 3000 and (sal <> 1500 and sal != 3000);

18、查询emp表1981-1-1到1981-12-31号入职的雇员;

select * from emp where hiredate between '1-1月-1981' and '31-12月-1981';

19、查看系统日期,借助dual伪表;

select sysdate from dual;

20、日期类型转换成字符串函数TO_CHAR()

select to_char(sysdate) from dual;
select to_char(sysdate,'yy-mm-dd') from dual;
select to_char(sysdate,'dd-mm-yyyy') from dual;
select to_char(sysdate,'yyyy-mm-dd') from dual;
select to_char(sysdate,'yyyy-mm-dd hh24:mi:ss') 日期 from dual;

21、字符串类型转换为日期函数TO_DATE()

select to_date('2020-10-05 23:59:56','yyyy-mm-dd hh24:mi:ss') from dual;
select to_char(to_date('2020-10-06 23:34:45','yyyy-mm-dd hh24:mi:ss'),'yyyy-mm-dd hh24:mi:ss')日期 from dual;

22、查询雇员名字叫 smith 的雇员,注意查询条件的值是区分大小写的

select * from emp where ename = 'smith';

23、查询雇员名字叫 SMITH 的雇员,注意查询条件的值是区分大小写的

select * from emp where ename = 'SMITH';

24、查询雇员编号是7369,7499,7521的雇员编号的具体信息

(1)使用逻辑运算符 and 无效 无效 无效

select * from emp where (empno = 7369) and (empno = 7499) and (empno = 7521);

(2)使用逻辑运算符 or 可以,加上括号更好一些

select * from emp where (empno = 7369) or (empno = 7499) or (empno = 7521);
select * from emp where empno = 7369 or empno = 7499 or empno = 7521;

(3)使用 IN 关键字

select * from emp where empno in (7369,7499,7521);

25、查询雇员姓名是 ‘SMITH’,‘ALLEN’,'WARD’的雇员具体信息

select * from emp where ename in ('SMITH','ALLEN','WARD');
select * from emp where (ename = 'SMITH') or (ename = 'ALLEN') or (ename = 'WARD');

–模糊查询 LIKE ‘%’:任意长度, _’:一个长度

26、查询所有雇员姓名中第二个字符包含“ M ”的雇员

select * from emp where ename like '_M%';

在LIKE中如果没有关键字表示查询全部

select * from emp where ename like '%';

27、查询所有雇员姓名中包含“ M ”的雇员

select * from emp where ename like '%M%';

28、查询雇员编号不是7369的雇员信息

select * from emp where empno <> 7369;
select * from emp where empno != 7369;

–使用 order by 对结果排序,升序ASC 默认,降序DESC

29、查询emp表雇员的工资,从低到高

select * from emp order by sal;

30、查询雇员的工资,从高到低

select * from emp order by sal desc;

31、如果存在多个排序字段可以用逗号分隔

select * from emp order by sal asc, hiredate desc;

–排序中的空值问题,可以使用nulls first, nulls last来指定null值显示的位置

32、查询雇员的工资从低到高

select * from emp order by sal nulls first;

33、查询雇员的工资从高到低(使用nulls last)

select * from emp order by sal desc nulls last;

都看到最后了啦,如果觉得写得好的话呐

记得 ​一键三连​ 哦!​点赞​ 也行呐!