plsql测试—参考答案

更新时间:2023-06-08 09:22:05 阅读: 评论:0

1、创建一个emp1表,其结构和数据与emp表完全一致。用游标完成操作:显示工资低于1500的职员信息,并显示如果给他们涨30%工资后的工资。
create table emp1 as lect * from emp;
t rveroutput on
declare
cursor cur is lect * from emp  where sal<1500;
begin
for v_counter in cur loop
dbms_output.put_line(pno||' '||ame||' '||'' ||v_counter.hiredate||' '||' '||v_counter.sal||' '||v_counter.sal*1.3);
end loop;
end;
2、编写一个pl/sql块,输出所有员工的员工名、员工号、工资和部门号。
declare
  cursor c_emp is lect * from emp;
begin
  for v_emp in c_emp loop
  dbms_output.put_line(ame||'' ||pno||' '||v_emp.deptno||' '||v_emp.sal);
  end loop; 
end;
3、查询名为“smith”的员工信息,并输出其员工号、工资、部门号。如果该员工不存在,
则插入一条新记录,员工号为2007,员工名为“smith”,工资为1500,部门号为10。如果存在多个名为“smith”的员工,则输出所有名为“smith”的员工号、工资和部门号。
Declare  v_emp emp%rowtype;
begin
lect * into v_emp from emp where ename='smith';
dbms_output.put_line(pno||'' ||v_emp.sal||' '||v_emp.deptno);
exception
when no_data_found then
  inrt into emp(empno,ename,sal,deptno) values(2007,'smith',1500,10);
when too_many_rows then
  for v in (lect * from emp where ename='smith') loop
    dbms_output.put_pno||'  '||v.sal||' '||v.deptno);
  end loop;
end;
4、创建一个存储过程,以员工号为参数,输出该员工的工资。
create or replace procedure showsal(p_pno%type)
as  v_sal emp.sal%type;
begin
lect sal into v_sal from emp where empno=p_empno;
dbms_output.put_line(v_sal);
end;
去日本留学的条件和要求begin
狐狸和乌鸦续写 showsal(7844);
end;
5、创建一个函数,以部门号为参数,返回该部门的平均工资;
create or replace function fun_avgsal(p_deptno emp.deptno%type)
return emp.sal%type
as普通话怎么练    化妆品过敏图片v_sal emp.sal%type;
begin
lect avg(sal) into v_sal from emp where deptno=p_deptno;
return v_sal;
end;
begin
dbms_output.put_line (fun_avgsal(10));
end;
6、创建一个函数,以员工号为参数,返回该员工所在部门的平均工资。
create or replace function fun_sal(p_pno%type)
return emp.sal%type
as  v_sal emp.sal%type;
begin
lect avg(sal) into v_sal from emp where deptno=
(lect deptno from emp where empno=p_empno);
return v_sal;
end;
begin
dbms_output.put_line (fun_sal (7844));
end;
7、在emp表上创建一个触发器,当插入、删除或修改员工信息时,统计各个部门的人数及平均工资,并输出。
create or replace trigger trg_emp
after inrt or update or delete
面筋凉皮on emp
declare
v_sal emp.sal%type;
v_count number;
begin
lect avg(sal),count(*) into v_sal,v_count from emp;
dbms_output.put_line(v_sal||' '||v_count);
end;
update emp t sal=500 where empno=7844;
8、创建一个包,包含一个过程和一个游标。游标返回所有员工的信息,过程实现每次输出游标中的5条记录。
create or replace package pkg_persistcursor
as
  cursor c_emp is lect * from emp;
  procedure displayemp;
end;
create or replace package body pkg_persistcursor
As  procedure displayemp
  As  v_emp emp%rowtype;
  begin
    if not c_emp%isopen then
    open c_emp;
end if;
for i in 1..5 loop
    fetch c_emp into v_emp;
    dbms_output.put_line(pno||' '|| ame); 
溶化的意思
end loop;
end;
end;//
begin
  pkg_persistcursor.displayemp;怎样养龟
end;
9、创建一个存储过程,以2个整数为参数,输出工资在两者间的员工信息。
create or replace procedure salbetween(min  binary_integer,max binary_integer)
as
begin
      for v_emp in (lect * from emp where sal between min and max) loop
      dbms_output.put_line(pno||' '|| ame||' '|| v_emp.job||' '|| ' '|| v_emp.hiredate||' '|| v_emp.sal||' '|| ' '|| v_emp.deptno);
      end loop;
end;
begin
salbetween(1000,3000);
end;
10、在emp表上创建一个触发器,保证修改员工工资时,改后的工资低于同部门的最高工资,同时高于同部门的最低工资。
create or replace package pkg_deptno
as  v_deptno emp.deptno%type;
    v_sal  emp.sal%type;
end;//
create or replace trigger trg_updateemp
before update on emp
for each row
begin
  pkg_deptno.v_sal:=:new.sal;
巴黎协议  pkg_deptno.v_deptno:=:new.deptno;
end;//
create or replace trigger trg_statement
after update on emp
declare
v_highsal emp.sal%type;
v_lowsal  emp.sal%type;
begin
  lect max(sal),min(sal) into v_highsal,v_lowsal
      from emp where deptno= pkg_deptno.v_deptno;
  if  pkg_deptno.v_sal>v_highsal or pkg_deptno.v_sal<v_lowsal  then
  rai_application_error(-20001,'the sal is beyond!');
  end if;
end;
update emp t sal=500 where empno=7844;
11、在emp表上创建一个触发器,当插入、删除或修改员工信息时,统计各个部门的人数及平均工资并输出。
12、创建一个包,包含一个过程和一个函数。过程以部门号为参数输出该部门中工资最高的员工名和员工号,函数以部门号为参数返回该部门员工的最高工资。
create or replace package pkg_emp
as
function func_highsal(p_deptno emp.deptno%type) return emp.sal%type;

本文发布于:2023-06-08 09:22:05,感谢您对本站的认可!

本文链接:https://www.wtabcd.cn/fanwen/fan/89/1021966.html

版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。

标签:员工   部门   工资   输出   信息   参数
相关文章
留言与评论(共有 0 条评论)
   
验证码:
推荐文章
排行榜
Copyright ©2019-2022 Comsenz Inc.Powered by © 专利检索| 网站地图