plsql习题 下载本文

内容发布更新时间 : 2024/6/13 9:45:04星期一 下面是文章的全部内容请认真阅读。

使用pl/sql块编程实现,注意必要的异常处理。

1.输入一个员工号,输出该员工的姓名、薪金和工作时间(按年月日显示)。

Set serveroutput on Declare

V_ename scott.emp.ename%type; V_sal scott.emp.sal%type;

V_hiredate scott.emp. hiredate %type; Begin

Select ename, sal, hiredate into v_ename, v_sal, v_hiredate from scott.emp where empno=&empno;

Dbms_output.put_line('姓名:'|| v_ename||' 工资:'|| v_sal||' 工资日期:'||to_char(v_hiredate,'yyyy-mm-dd')); EXCEPTION

When no_data_found then

Dbms_output.put_line('输入编号有误!'); End; /

2.接收一个员工号,输出该员工所在部门的名称。

Set serveroutput on Declare

V_dname scott.dept.dname%type; Begin

select dname into v_dname from scott.dept a,scott.emp b where a.deptno=b.deptno and

1

b.empno=&empno;

Dbms_output.put_line('部门名称:'|| v_dname); EXCEPTION

When no_data_found then

Dbms_output.put_line('输入编号有误!'); End; /

3.接收一个部门号,如果该部门中员工职位是MANAGER,并且在DALLAS工作,那么就给他薪金加15%;如果该部门员工职位是CLERK,并且在NEW YORK工作,那么就给他薪金扣除5%;其他情况不作处理。

2

declare

v_deptno scott.emp.deptno%type:=&deptno; cursor emp_cursor is

select job,loc,sal from scott.emp,scott.dept where scott.emp.deptno in

(select scott.emp.deptno from scott.dept,scott.emp where scott.emp.deptno=scott.dept.deptno and scott.dept.deptno=v_deptno)for update of scott.emp.sal; begin

for emp_record in emp_cursor loop

if emp_record.job='CLERK' and emp_record.loc='NEW YORK'then

update scott.emp set sal=emp_record.sal*0.95 where current of emp_cursor;end if; if emp_record.job='MANAGER' and emp_record.loc='DALLAS'then

update scott.emp set sal=emp_record.sal*1.15 where current of emp_cursor; exit when emp_cursor%NOTFOUND; end if; end loop; end; /

4.接收一个员工号,输出这个员工所在部门的平均工资。

Set serveroutput on

3