OraclePL/SQL
面试题
一、
求
1-100
之间的素数
declare
fag boolean:=true;
begin
for i in 1..100 loop
for j in 2..i-1 loop
if mod(i,j)=0 then
fag:=false;
end if;
end loop;
if fag then
dbms_output.put_line(i);
end if;
fag:=true;
end loop;
end;
二、
对所有员工
,
如果该员工职位是
MANAGER
,并且在
DALLAS
工作那么就给他薪金加
15
%;如果该员工职位是
CLERK
,并且在
NEW YORK
工作那么就给他薪金扣除
5
%
;
其他情况
不作处理
declare
cursor c1 is select * from emp;
c1rec c1%rowtype;
v_loc varchar2(20);
begin
for c1rec in c1 loop
select loc into v_loc from dept where deptno = c1rec.deptno;
if c1rec.job = 'MANAGER' and v_loc = 'DALLAS' then
update emp set sal = sal * 1.15 where empno
= c1rec.empno;
elsif c1rec.job='CLERK' and v_loc = 'NEW YORK' then
update emp set sal = sal * 0.95 where empno
= c1rec.empno;
else
null;
end if;
end loop;
end;
三、对直接上级是
'BLAKE'
的所有员工,按照参加工作的时间加薪:
81
年
6
月以前的加薪
10
%
81
年
6
月以后的加薪
5
%
declare
cursor c1 is select * from emp where mgr = (select
empno from emp where ename='BLAKE'); --
直接上级是
'BLAKE'
的所有员工