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;
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;
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;