设为首页 加入收藏

TOP

OraclePL/SQL编程基础实例2
2015-07-24 12:19:31 来源: 作者: 【 】 浏览:62
Tags:OraclePL/SQL 编程 基础 实例
if 循环 控制语句

if--then endif

if----then ----else endif

if-----then --elsif then ----else endif

--编写一个过程,可以 输入一个雇员名,如果该雇员的工资低于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;
--======####案例s33 编写一个过程,可以 输入一个雇员名,如果该雇员的补助不是0就在原基础上增加100,如果是0就加200
create or replace procedure sp_pro7(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;

----========循环 loop end loop
-----案例 编写一个过程 可输入用户名 并添加10个用户到users表中 用户编号从1来时增加
--建个表
create table users1(uid1 number,uname varchar2(40));

create or replace procedure sp_pro8(spName varchar2) is
--定义变量
v_num number :=1;
begin
loop
insert into users1 values(v_num,spName);
--判断是否退出循环
exit when v_num =10;
--自增
v_num:=v_num+1;
end loop;
end;

----------------===while ...loop end loop

----===案例 从11 开始 添加10个用户
create or replace procedure sp_pro8(spName varchar2) is
--定义变量
v_num number :=11;
begin
while v_num<=20
loop
--执行
insert into users1 values(v_num,spName);
--自增
v_num:=v_num+1;
end loop;
end;
---------------------for
begin for i in reverse 1.. 10 loop
insert into users1 values(v_num,spName);
end loop;
end;

-----------------顺序控制语句 goto null
goto label

<
】【打印繁体】【投稿】【收藏】 【推荐】【举报】【评论】 【关闭】 【返回顶部
分享到: 
上一篇ORA-19809:超出了恢复文件数的限制 下一篇Oracle使用并行建索引需要注意的..

评论

帐  号: 密码: (新用户注册)
验 证 码:
表  情:
内  容: