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||';員工獎(jiǎng)金'||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('沒(méi)有該員工');
when others then
dbms_output.put_line('員工工資'||V_emp_REC.salary||';員工獎(jiǎng)金'||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):='&請(qǐng)輸入要查看的表名';
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('員工編號(hào):'||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('部門編號(hào):'||v_dept.department_id||'部門名:'||v_dept.department_name||'部門locationid:'||v_dept.location_id);
end loop;
end if;
end;