这是我在accp学习的qa,觉得对初学者很有帮助,贴出。
—-
第一阶段
q.编写一个pl/sql程序块以显示所给出雇员编号的雇员的详细信息。
a.
declare
erec emp%rowtype;
begin
select * into erec from emp where empno=&雇员编号;
dbms_output.put_line(empno || || ename || || job || || manager || || hiredate || || salary || || commision || || deptno);
dbms_output.put_line(erec.ename || || erec.job || || erec.mgr || ||erec.hiredate || || erec.sal || || erec.comm || || erec.deptno);
end;
/
q.编写一个pl/sql程序块以计算某个雇员的年度薪水总额。
a.
declare
esal number;
eename emp.ename%type;
begin
select (nvl(sal,0)+nvl(comm,0))*12,ename into esal,eename from emp where empno=&雇员编号;
dbms_output.put_line(eename || s years salary is || esal);
end;
/
q.按下列加薪比执行:
deptno raise(%age)
10 5%
20 10%
30 15%
40 20%
加薪的百分比是以他们现有的薪水为根据的。写一pl/sql以对指定雇员加薪。
a.
declare
vcounter number:=10;
vraise number;
begin
loop
exit when vcounter>40;
update emp set sal=nvl(sal,0)+nvl(sal,0)*0.05 where deptno=vcounter;
vcounter:=vcounter+10;
end loop;
end;
/
q.编写一pl/sql以向“emp”表添加10个新雇员编号。
(提示:如果当前最大的雇员编号为7900,则新雇员编号将为7901到7910)
a.
declare
vcounter number;
begin
select max(empno) into vcounter from emp;
for i in 1..10
loop
vcounter:=vcounter+1;
insert into emp(empno) values(vcounter);
end loop;
end;
/
q.只使用一个变量来解决实验课作业4。
a
declare
erec emp%rowtype;
— vraise number;
begin
select * into erec
from emp
where ename=&ename;
if erec.job=clerk then
update emp set sal=sal+500 where empno=erec.empno;
elsif erec.job=salesman then
update emp set sal=sal+1000 where empno=erec.empno;
elsif erec.job=analyst then
update emp set sal=sal+1500 where empno=erec.empno;
else
update emp set sal=sal+2000 where empno=erec.empno;
end if;
— update emp set sal=sal+vraise where empno=erec.empno;
— dbms_output.put_line(vraise);
end;
/
q.接受两个数相除并且显示结果。如果第二个数为0,则显示消息“divide by zero”。
a.
declare
num1 number;
num2 number;
begin
num1:=#
num2:=#
dbms_output.put_line(num1 || / || num2 || is || num1/num2);
exception
when zero_divide then
dbms_output.put_line(didnt your teacher tell you not to divide by zero?);
end;
/
