oracle中plsql块的结构,oracle plsql的结构

变量声明部分(没有变量可以不写declare)

begin

执行部分

exception

异常处理部分

end

*:declare 和 exception部分是可选的

(1)PL/sql中变量的定义

格式1

变量名 变量类型 【约束】 default 默认值

格式2

变量名 变量类型 【约束】【:=初始值】

(2)一个简单的PL/sql块

declare

i number :=99;

begin

i:=i+10;

dbms_output.put_line(i);

end;

/

PL/sql块中流程控制

一。if语句

if 条件 then

。。。

end if;

if 条件 then

。。。

else

。。。

end if;

declare

zhangsan numberdefault 24;

lisi number :=28;

beginif zhangsan

dbms_output.put_line(‘zhangsan younger than lisi‘);

endif;

end;/

if 条件 then

...

elsif 条件 then

...

end if;

declare

age numberdefault 90;

height number :=175;

genderchar(2):=‘男‘;

beginif gender=‘男‘then

dbms_output.put_line(‘你可以和女性结婚‘);

endif;if height>170then

dbms_output.put_line(‘可以打篮球‘);elsedbms_output.put_line(‘可以踢足球‘);

endif;if age<20then

dbms_output.put_line(‘年轻小伙‘);

elsif age<= 50then

dbms_output.put_line(‘年轻有为‘);

elsif age<=70then

dbms_output.put_line(‘安享天伦‘);elsedbms_output.put_line(‘佩服佩服‘);

endif;

end;

二。While循环语句:

while 条件 loop

循环体

end loop;

declare

age numberdefault 1;

beginwhile age <=10loop

dbms_output.put_line(‘age is‘||age);

age:=age+1;

end loop;

end;

三。For循环结构:

for 循环变量 in [reverse] 起始值..终止值 loop

循环体

end loop;

beginfor i in 1..9loop

dbms_output.put_line(i);

end loop;for i in reverse 1..9loop

dbms_output.put_line(i);

end loop;

end;

四。Loop循环语句:

loop

循环体

exit when 条件;

end loop;

//计算1-100的和

declare

i number:=0;

total number:=0;

begin

loop

i:=i+1;

total:=total+i;if i=100then

exit;

endif;

end loop;

dbms_output.put_line(‘总和‘||total);

end;

跳出loop的方法

declare

i number :=0;

total number :=0;

begin

loop

i := i+1;

total := total +i;

exit when i>=100;

end loop;

dbms_output.put_line(‘总和‘||total);

end;

存储过程创建语法:

create or replace procedure 名称[(参数)]

authid current_user|definer --以定义者还是调用者的身份运行is[不要加declare]

变量声明部分

begin

主体部分

exception

异常部分

end;

create procedure a1isbegin

dbms_output.put_line(‘hello‘);

end;/

调用

Call a1();

create procedure a2(width int,height int)isareaint:=0;

begin

area:=width*height;

dbms_output.put_line(‘area is‘||area);

end;/

调用

Call a2(20,3);

oracle plsql的结构

标签:efi   exit   rev   int   条件   变量   部分   number   user

本条技术文章来源于互联网,如果无意侵犯您的权益请点击此处反馈版权投诉 本文系统来源:https://www.cnblogs.com/111wdh/p/13634608.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值