Oracle plsql 题目

1.编写一个PL/SQL程序块 接收一个雇员名,显示该雇员的所有内容,(用%rowtype实现),当没有这个雇员时,抛异常来显示错误提示;当雇员同名有多个时,抛异常来显示错误提示,如果没有异常,则显示该雇员的工资和奖金,没有奖金的用0替代。(用%type实现); 测试(Vargas,Zlotkey,Gietz,Hello)这几个名字 表用employees ,雇员名指的是last_name字段。
DECLARE
      V_emp_REC employees%ROWTYPE;
      com_pct employees.commission_pct%type;
      my_exception Exception;
BEGIN
      SELECT * INTO V_emp_REC  FROM employees emp
      WHERE emp.last_name=&lastname;
      dbms_output.put_line('员工姓名'||V_emp_REC.last_name||';员工Email'||V_emp_REC.email||';员工话'||V_emp_REC.phone_number||';入职日期'||V_emp_REC.hire_date||';员工工资'||V_emp_REC.salary||';员工奖金'||V_emp_REC.commission_pct);
      if V_emp_REC.commission_pct is null then
             com_pct :=0;
      else
             com_pct :=V_emp_REC.commission_pct;
      end if;
      raise my_exception;
      exception
            when too_many_rows then
                  dbms_output.put_line('员工同名');
            when no_data_found then
                 dbms_output.put_line('没有该员工');
            when others then
                 dbms_output.put_line('员工工资'||V_emp_REC.salary||';员工奖金'||com_pct);
END;
2.编写一个游标,一次性上涨全部雇员的工资。根据它所在的部门涨工资,规则: 10部门上涨10% 20部门上涨20% 30部门上涨30% 其它部门上涨40%。
DECLARE

BEGIN
          for addsal in (select department_id from employees group by department_id) loop
          if addsal.department_id='10' then
               update employees t set t.salary=t.salary*1.1  ;
         elsif  addsal.department_id='20' then
               update employees t set t.salary=t.salary*1.2;
         elsif  addsal.department_id='30' then
               update employees t set t.salary=t.salary*1.3;
         else
               update employees t set t.salary=t.salary*1.4;
         end if;
         end loop;
COMMIT;
END;
3.编写一个REF游标, 提示用户输入要查看哪个表中的记录。如果用户输入‘E’,则显示emp表中的employee_id、last_name、job_id和salary列的值;如果用户输入‘D’,则显示departments表中的department_id、department_name和location_id列的值
declare
           type cur_tab is ref cursor;
           mycursor cur_tab;
           v_table varchar2(30):='&请输入要查看的表名';
           v_emp employees%rowtype;
           v_dept departments%rowtype;
begin
          v_table:=upper(v_table);
          if v_table='E' then
               open mycursor for select * from employees ;
               loop
               fetch mycursor into v_emp;
               exit when mycursor%notfound;
                dbms_output.put_line('员工编号:'||v_emp.employee_id||'员工姓名:'||v_emp.last_name||'员工jobid:'||v_emp.job_id||'员工工资:'||v_emp.salary);
               end loop;
          elsif v_table='D' then
                 open mycursor for select * from departments ;
                 loop
                 fetch mycursor into v_dept;
                 exit when mycursor%notfound;
                 dbms_output.put_line('部门编号:'||v_dept.department_id||'部门名:'||v_dept.department_name||'部门locationid:'||v_dept.location_id);
                 end loop;
          end if;
end;
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

相关阅读更多精彩内容

  • 1、Check规则 Check (Agebetween15and30 )把年龄限制在15~30岁之间 2、新SQL...
    姜海涛阅读 1,011评论 0 4
  • 1. Java基础部分 基础部分的顺序:基本语法,类相关的语法,内部类的语法,继承相关的语法,异常的语法,线程的语...
    子非鱼_t_阅读 34,741评论 18 399
  • 一. Java基础部分.................................................
    wy_sure阅读 4,017评论 0 11
  • 1.1 基本结构 PL/SQL程序由三个块组成,即声明部分、执行部分、异常处理部分。 1.2 命名规则 1.3 记...
    慢清尘阅读 4,070评论 3 14
  • 简悦直播教练恬源阅读 436评论 0 2

友情链接更多精彩内容