4、使用case语句更新工资,10部门提高100,20部门提高200,30部门提高300,40部门提高400。
set serveroutput on
declare v_dpt emp.dpt%type;
begin
select dpt into v_dpt from emp where name='zhangsan'
case
when v_dpt='10' then
update emp set sal=sal+100 where name='zhangsan';
when v_dpt='20' then
update emp set sal=sal+200 where name='zhangsan';
when v_dpt='30' then
update emp set sal=sal+300 where name='zhangsan';
when v_dpt='40' then
update emp set sal=sal+400 where name='zhangsan';
else
dbms_output.put_line('无法更新!');
end case;
end;
5、分别使用3种循环计算10的阶乘
简单(loop)循环
declare i number(2) :=1;s number(10):=1;
begin
loops:=s*i;
i:=i+1;
dbms_output.put_line(s);
exit when i>10;
end loop;
end;
for循环
declare i number(2) :=1; s number(10):=1;
begin
loop
s:=s*i;
i:=i+1;
dbms_output.put_line(s);
exit when i>10;
end loop;
end;
while循环
declare i number(2) :=1; s number(10):=1;
begin
while i<=10 loop
s:=s*i;
i:=i+1;
dbms_output.put_line(s);
end loop;
end;
6、使用for循环输出一个实心三角形,底边长由用户输入。
核心代码:
begin
for i in 1..5 loop
dbms_output.put_line(rpad(i,8-i,' ')||rpad('*',2*i-1,'*'));
end loop;
end;