plsql习题

2019-01-19 15:40

使用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

Declare

V_deptno scott.dept.deptno%type; V_avg_salar scott.emp.sal%type; Begin

Dbms_output.put_line('请输入员工号:');

select scott.emp.deptno into v_deptno from scott.emp where scott.emp.empno = &empno; select avg(scott.emp.sal) into V_avg_salar from scott.emp where scott.emp.deptno = v_deptno;

Dbms_output.put_line('该员工所在的部门编号为:'|| V_deptno);

Dbms_output.put_line('该员工所在部门的平均工资为:'|| V_avg_salar); EXCEPTION

When no_data_found then

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

5.以交互的方式给部门表插入一条记录,如果出现主键冲突的异常,请显示“部门号已被占用”的字样。

select scott.dept.deptno ,scott.dept.dname, scott.dept.loc from scott.dept;

4

Set serveroutput on Begin

insert into scott.dept(scott.dept.deptno,scott.dept.dname,scott.dept.loc) values(&deptno,&dname,&loc); EXCEPTION

When DUP_VAL_ON_INDEX then

Dbms_output.put_line('部门号已被占用!'); End; /

5


plsql习题.doc 将本文的Word文档下载到电脑 下载失败或者文档不完整,请联系客服人员解决!

下一篇:《归园田居(其三)》说课稿

相关阅读
本类排行
× 注册会员免费下载(下载后可以自由复制和排版)

马上注册会员

注:下载文档有可能“只有目录或者内容不全”等情况,请下载之前注意辨别,如果您已付费且无法下载或内容有问题,请联系我们协助你处理。
微信: QQ: