发布时间 : 星期日 文章plSql面试题更新完毕开始阅读5b9e8a566edb6f1aff001ff5
PL/SQL面试题 2010-04-29 14:25
一、 求1-100之间的素数
as i number; j number; is_prim boolean; begin
dbms_output.new_line;
dbms_output.put(to_char(2)||' '); for i in 3..inp loop begin
is_prim:=true;
for j in 2..trunc(sqrt(i)) loop if mod(i,j)=0 then begin
is_prim:=false; exit; end; end if; end loop;
if is_prim then dbms_output.put(to_char(i)||' '); end if; end; end loop;
dbms_output.new_line; end; /
exec is_prime(100)
set serverout on
create or replace procedure is_prime(inp number)
二、 对所有员工,如果该员工职位是MANAGER,并且在DALLAS工作那么就给他薪金加15%;如果该员工职位是CLERK,并且在NEW YORK工作那么就给他薪金扣除5%;其他情况不作处理
三、对直接上级是'BLAKE'的所有员工,按照参加工作的时间加薪: 81年6月以前的加薪10% 81年6月以后的加薪5%
三、 根据员工在各自部门中的工资高低排出在部门中的名次(允许并列).
四、编写一个触发器实现如下功能: 对修改职工薪金的操作进行合法性检查:
四、 编写一个PL/SQL程序块,对名字以\或\开始的所有雇员按他们的基本薪水的10%加薪。
五、编写一PL/SQL,对所有的\销售员\增加佣金500.
六、编写一PL/SQL,以提升两个资格最老的\职员\为\高级职员\。(工作时间越长,优先级越高) 七、编写一PL/SQL,对所有雇员按他们基本薪水的10%加薪,如果所增加的薪水大于5000,则取消加薪。
八、显示EMP中的第四条记录。
九、.编写一个给特殊雇员加薪10%的过程,这之后,检查如果已经雇佣该雇员超过60个月,则给他额外加薪3000.
十、编写一个函数以检查所指定雇员的薪水是否有效范围内。不同职位的薪水范围为:
十二、有如下MyTable: 日期 日产 1 3.3333 2 4.2222 3 1.5555 4 9.8888 5 ………
要求用SQL语句生成如下查询 日期日产 累计日产 1 3.3333 3.3333 2 4.2222 7.5555 3 1.5555 9.0000 4 9.8888 18.8888 5………
十三、创建一个序列,第一次从5循环到10,以后再从0开始循环
一、 求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'的所有员工 c1rec c1%rowtype; begin
for c1rec in c1 loop
if c1rec.hiredate < '01-6月-81' then
update emp set sal = sal * 1.1 where empno = c1rec.empno; else
update emp set sal = sal * 1.05 where empno = c1rec.empno; end if; end loop; end;
三、 根据员工在各自部门中的工资高低排出在部门中的名次(允许并列). <1> 一条SQL语句
select deptno,ename,sal,(select count(*) + 1 from emp where deptno = a.deptno and sal > a.sal) as ord from emp a
order by deptno,sal desc;
<2> PL/SQL块 declare cursor cc is
select * from dept; ccrec cc%rowtype;
cursor ck(no number) is
select * from emp where deptno = no order by sal desc;
ckrec ck%rowtype;
i number;