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;

你可能感兴趣的:(Oracle plsql 题目)