实验五 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;

posted @   地球修者  阅读(242)  评论(0编辑  收藏  举报
编辑推荐:
· 10年+ .NET Coder 心语,封装的思维:从隐藏、稳定开始理解其本质意义
· .NET Core 中如何实现缓存的预热?
· 从 HTTP 原因短语缺失研究 HTTP/2 和 HTTP/3 的设计差异
· AI与.NET技术实操系列:向量存储与相似性搜索在 .NET 中的实现
· 基于Microsoft.Extensions.AI核心库实现RAG应用
阅读排行:
· TypeScript + Deepseek 打造卜卦网站:技术与玄学的结合
· 阿里巴巴 QwQ-32B真的超越了 DeepSeek R-1吗?
· 【译】Visual Studio 中新的强大生产力特性
· 10年+ .NET Coder 心语 ── 封装的思维:从隐藏、稳定开始理解其本质意义
· 【设计模式】告别冗长if-else语句:使用策略模式优化代码结构
点击右上角即可分享
微信分享提示