day01(附答案)(由于内容太过于简单上传没有被百度文库通过,于是和day04一起上传上来)
1.查询职员表中工资大于1600的员工姓名和工资。
select ename,sal from emp where sal>1600;
2.查询职员表中员工号为7369的员工的姓名和部门号码。
select ename,deptno from emp where empno=7369;
3.选择职员表中工资不在4000到5000的员工的姓名和工资。
select ename,sal from emp where sal not between 4000 and 5000;
4.选择职员表中在20和30号部门工作的员工姓名和部门号。
select ename,deptno from emp where deptno in(20,30);
5.选择职员表中员工姓名的第三个字母是A的员工姓名。
select ename from emp where ename like '__A%';
6.列出部门表中的部门名字和所在城市。
select dname,loc from dept;
7.显示出职员表中的不重复的岗位job。
select distinct job from emp;
8连接职员表中的职员名字、职位、薪水,列之间用逗号连接,列头显示成OUT_PUT(提示:使用连接符||、别名)。
select '姓名:' || ename || ',职位' || job || ',薪水' || sal OUT_PUT from emp
9查询职员表emp中员工号、姓名、工资,以及工资提高百分之20%后的结果。
select empno,ename,sal,sal*1.2 sals from emp;
10列出除了ACCOUNT部门还有哪些部门。
select dname from dept where lower(dname)!='account';
===============================================================================
day04(附答案及多种解法)
1. 创建表employee,字段为:
id number ,
first_Name varchar2(20),
last_Name varchar2(20),
mgrid NUMBER ,
job varchar2(20),
salary number(7,2)
create table employee(id number,first_Name varchar2(20),last_Name varchar2(20),mgrid number,job varchar2(20),salary number(7,2));
2. 向表中插入下列数据,并提交,查询数据;
ID FIRST_NAME LAST_NAME MGRID SALARY
1 Rose Tyler 4 1500
2 Matha Jones 4 2200
3 Donna Noble 4 1300
4 Doctor Who 3500
5 Jack Harkness 1 3000
insert into employee values(1,'Rose','Tyler',4,null,1500);
insert into employee values(2,'Matha','Jones',4,null,2200);
insert into employee values(3,'Donna','Noble',4,null,1300);
insert into employee values(4,'Doctor','Who',null,null,3500);
insert into employee values(5,'Jack','Harkness',1,null,3000);
commit;
select *from employee;
3. 将3号员工的last_name修改为“Tate”,并提交,查询数据;
update employee set last_name='Tate' where id=3;
commit;
select last_name from employee where id=3;
4. 将所有工资少于5000的员工的工资修改为5000 (不提交),并设置保存点,查询数据;
update employee set salary=5000 where salary< 5000;
savepoint a;
select salary from employee;
5. 删除emp