oracle笔记——第七天:oracle视图、触发器,编写分页存储过程

1.控制结构(条件语句,循环语句,顺序语句)

1.1、条件分支

if-then,if-then-else,if-then-elseif-else
--编写过程,可以输入一个雇员,如果该雇员的工资低于2000,就给该雇员的工资增加10%;
create or replace procedure sp_pro6(spName varchar2) is
--定义
v_sal emp.sal%type;
begin
--执行
select sal into v_sal from emp where ename=spName;
--判断
if v_sal<2000 then
update emp set sal=sal*1.1 where ename=spName;
end if;
end;

--编写一个过程,可以输入一个雇员编号,如果该雇员的补助不是0,就在原来的基础之上加100,如果补助为0,就在原来的基础之上加200

create or replace procedure sp_pro6(spName varchar2) is
v_comm emp.comm%type;
begin
select comm into v_comm from emp where ename=spName;
if v_comm <>0 then
update emp set comm=comm+100 where ename=spName;
else
update emp set comm=comm+200 where ename=spName;
end if;
end;

--编写一个过程,可以输入一个雇员号,如果该雇员的职位是
--president 就给他的工资加1000,如果该雇员的职位是manager
--就给他等工资加500,其他的值为就加200;

create or replace procedure sp_pro6(spNo number) is
--定义
v_job emp.job%type;
begin
--执行
select job into v_job from emp where empno=spNo;
if v_job='PRESIDENT' then
update emp set sal=sal+1000 where empno=spNo;
elseif v_job='MANAGER' then
update emp set sal=sal+500 where empno=spNo;
else
update emp set sal=sal+200 where empno=spNo;
end if;
end;

1.2、循环语句

--loop 一loop开始  一end loop 结尾 至少执行一次
--编写一个过程,可以输入用户名,并循环添加10个用户到users表中,用户编号是从0开始

create or replace procedure sp_pro6(spName varchar2) is
v_num number:=1;--赋值
begin
loop
      insert into user values(v_num,spName);
      --判断退出条件
      exit when v_num=10;
      --自增
      v_num:=v_num+1;
end loop;
end;
--while循环(以while开始 while loop 结尾)
create or replace procedure sp_pro6(spName varchar2) is
v_num number:=1;--赋值
begin
while v_num<=20 loop
--执行
       insert into user values(v_num,spName);
       v_num:=v_num+1;
end if;
end;
--for循环
create or replace procedure sp_pro6 is
begin
       for i in reverse 1..10 loop
            insert 
  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值