Oracle第五章
本次主要内容:
1 oracle中的注释
2 oracle中的命名规范
3 oracle中定义变量
4 oracle中的块结构
5 oracle中的条件语句
6 oracle中的循环语句
7 oracle中的游标
1 oracle中的注释
--单行注释
/*多行注释*/
2 oracle中的命名规范
变量:v_变量名
常量:c_常量名
过程:pro_过程名
函数:fun_函数名
视图:view_视图名
索引:i_索引名
序列:seq_表名
3 oracle中定义变量
定义:
变量名 [constant] 数据类型 [not null] [:=值];
如:
name varchar2(20) not null:='小黑';
num number(5,2) := 3.14;
注意:定义布尔类型变量时,必须指定默认值
flag boolean not null default true/false;
4 oracle中的块结构
三大组成:定义结构、执行结构、异常结构
declare
定义部分
begin
执行部分
exception
异常部分
end;
注意:其中的declare和exception可以省略
完成:使用块结构完成,根据输入的编号查询员工的姓名和工资
5 oracle中的条件语句
if——then——end if;
if——then——else——end if;
if——then——elsif——then.......end if;
完成:使用存储过程,根据用户名查询工资,如果工资小于2000则增加500
练习:使用存储过程,根据用户名查询提成,如果提成大于0则提成增加100,否则增加500
练习:使用存储过程,根据编号查询所在职位,如果职位为CLERK,则工资增加2,如果职位为SALESMAN,则工资增加5,其它职位增加9
case 变量
when 值 then
when 值 then
when 值 then
........
else
end case;
6 oracle中的循环语句
loop循环:
loop
循环体;
exit when 结束条件;
end loop;
while循环:
while 条件 loop
循环体;
end loop;
完成:向userinfo表循环添加10条数据

浙公网安备 33010602011771号