save-controls.sql
上传用户:wwjj4545
上传日期:2022-07-24
资源大小:2k
文件大小:4k
- ---1./*创建员工表employee包含字段employee_id类型为number,
- 长度为5,employee_name类型为varchar2,长度为20,employee_salary类型为
- number,长度为4。*/
- drop table emp;
- create table emp
- (
- eid number(5),
- ename varchar2(20),
- sal number(4)
- );
- insert into emp values(001,'李静',2000);
- insert into emp values(002,'张熊',1980);
- insert into emp values(003,'梁惠',4500);
- insert into emp values(004,'陈珊',5100);
- insert into emp values(005,'乔麦',2500);
- insert into emp values(006,'余杰',5400);
- insert into emp values(007,'李文',2600);
- ----2./*创建部门表department包含字段department_id类型为number,长度为3,
- department_name类型为varchar2,长度为20,employee_id 类型为
- number,长度为5。*/
- --部门表
- drop table dept;
- create table dept
- (
- did number(3),
- dname varchar2(20),
- eid number(5)
- );
- insert into dept values(178,'SBB',001);
- insert into dept values(159,'HDD',002);
- insert into dept values(123,'GDS',003);
- insert into dept values(111,'PPT',004);
- insert into dept values(108,'FTE',005);
- insert into dept values(135,'PPT',006);
- insert into dept values(136,'SBB',007);
- select * from dept;
- select * from emp;
- ----3./*给employee表添加记录的存储过程*/
- create or replace procedure put_column
- (insertdate1 in number,
- insertdate2 in varchar,
- insertdate3 in number)
- as
- begin
- insert into emp
- values(insertdate1,insertdate2,insertdate3);
- end put_column;
- call put_column(001,'李静',2000);
- call put_column(002,'张熊',1980);
- call put_column(003,'梁惠',4500);
- call put_column(004,'陈珊',5100);
- call put_column(005,'乔麦',2500);
- call put_column(006,'余杰',5400);
- call put_column(007,'李文',2600);
- select * from emp;
-
-
-
-
-
- create or replace procedure put_column
- (insertdate1 in number,
- insertdate2 in varchar,
- insertdate3 in number)
- as
- begin
- insert into emp
- values(insertdate1,insertdate2,insertdate3);
- COMMIT;
- END IF;
- EXCEPTION
- WHEN OTHERS THEN
- ROLLBACK;
- END put_colunm;
- ----4./*给department表添加记录的存储过程*/
- create or replace procedure put_column
- (insertdate1 in number,
- insertdate2 in varchar,
- insertdate3 in number)
- as
- begin
- insert into dept
- values(insertdate1,insertdate2,insertdate3);
- end put_column;
- call put_column(178,'SBB',001);
- call put_column(159,'HDD',002);
- call put_column(123,'GDS',003);
- call put_column(111,'PPT',004);
- call put_column(108,'FTE',005);
- call put_column(135,'PPT',006);
- call put_column(136,'SBB',007);
- select * from dept;
-
- ----5./*调用相应的存储过程实现记录添加*/
- execute insert_emp(009,'李强',5000);
- execute insert_detp(110,'SBB'1000);
- /*--要求2:给指定部门的员工加薪,这实际上是一个复合查询,首先需要把所有
- 该部门的员工塞选出来,然后对这些员工的薪水进行相应的改动
- (需要注意的是:将要加薪的部门作为参数,这样的存储过程更有灵活性。)*/
- select emp.ename from emp,dept group by emp.ename;
- CREATE or
- 7./*--要求3:建立日志对薪水的变动情况形成一个追踪,也就是说,
- 如果对某个职员的薪水进行变更就应该将其相应的变更记录全部记下来。
- 如果对employee表的salary字段创建一个触发器,来监视对salary的更改,
- 把每次更改进行记录,这样就达到了要求3的目的了。*/
- drop table sal_adjust_log;
- select * from sal_adjust_log;
- create table sal_adjust_log
- (
- enm_id number(5),
- old_salary number(4),
- new_salary number(4),
- changedate date
- );
- insert into sal_adjust_log values(001,2300,2000,sysdate);
- create or replace trigger update_emp_sal
- after update on emp
- for each row
- begin
- insert into sal_adjust_log
- values
- (:new.emp_id,
- :old.emp_salary,
- :new_emp_salary,
- sysdate);
- end;
-
- select * from jobs;
- drop table jobs1;
- create table jobs1 as select * from jobs;
- select * from jobs1;
- savepoint insert_jobs5;
- insert into jobs1 values('jj','hu');
- savepoint insert_jobs1;
- update jobs1 set name = 'hjj';
- savepoint insert_jobs2;
- insert into jobs1 values('kk','yan');
- savepoint insert_jobs3;
- update jobs1 set name = 'yankk';
- savepoint update_jobs4;
- rollback to insert_jobs5;
- select * from jobs1;
- rollback to insert_jobs1;
- select * from jobs1;
- rollback to insert_jobs2;
- select * from jobs1;
- rollback to insert_jobs3;
- rollback to update_jobs4;