实验五 plsql基础

. 简单PL/SQL块程序编写与运行,要求:接收某一姓名信息“小可爱”,并输出显示“Hello小可爱,今天是:当前日期”。
2.使用临时变量(&e_no)要求用户输入雇员号,利用IF语句判断该雇员的岗位是否为’CLERK’,如果是则将该雇员的工资提高1%。
3.使用临时变量(&d_no)要求用户输入部门号,根据输入的部门号,利用使用选择器的case判断:若是10号部门,则将该部门雇员的补助(对应EMP表中的字段COMM)改为100;若是20号部门,则将该部门雇员的补助改为80;若是30号部门,则将该部门雇员的补助改为50。
4. 使用临时变量(&e_no)要求用户输入雇员号,根据输入的雇员号,利用不使用选择器的case判断:若雇员工资小于1000,则将该雇员的补助(对应EMP表中的字段COMM)改为100;若雇员工资在1000到2000,则将该雇员的补助改为80;若雇员工资大于2000,则将该雇员的补助改为50。
5. 利用WHILE循环打印出50以内所有能被3整除的整数,以及该整数的个数(运行结果:16)。
6. 利用FOR循环计算并输出S=1!+2!+…+10! (运行结果:4037913)

三、实验答案

declare
cname varchar2(23):='小可爱';
c_sysdate date;
begin
select sysdate into c_sysdate from dual;
dbms_output.put_line('Hello ');
dbms_output.put_line(cname);
dbms_output.put_line(',今天是:');
dbms_output.put_line(c_sysdate);
end;

2
set serveroutput on
declare
veno number:=&e_no;
vjob emp.job%type;
begin
select job into vjob from emp where empno=veno;
if vjob ='CLERK' then
update emp set sal=sal*1.01 where empno=veno;
end if;
end;

3
set serveroutput on
declare
vdno number:=&d_no;
begin
case vdno
when 10 then
update emp set comm=100 where deptno=vdno;
when 20 then
update emp set comm=80 where deptno=vdno;
when 30 then
update emp set comm=50 where deptno=vdno;
else
dbms_output.put_line('no e');
end case;
end;

4

set serveroutput on
declare
veno number:=&e_no;
vsal emp.sal%type;
begin
select sal into vsal from emp where empno=veno;
case
when vsal<1000 then
update emp set comm=100 where empno=veno;
when vsal>=1000 and vsal<=2000 then
update emp set comm=80 where empno=veno;
when vsal>2000 then
update emp set comm=50 where empno=veno;
end case;
end;

5
set serveroutput on
declare
num number:=0;
shu number:=1;
begin
while shu<=50 loop
if mod(shu,3)=0 then
num:=num+1;
dbms_output.put_line(shu);
end if;
shu:=shu+1;
end loop;
dbms_output.put_line(num);
end;

6
set serveroutput on
declare
num number:=0;
shu number:=1;
begin
for i in 1..10 loop
shu:=1;
for j in 1..i loop
shu:=shu*j;
end loop;
num:=shu+num;
end loop;
dbms_output.put_line(num);
end;

原文地址:https://www.cnblogs.com/leefree/p/14263867.html