首页 / ORACLE / oracle plsql的结构
oracle plsql的结构
内容导读
互联网集市收集整理的这篇技术教程文章主要介绍了oracle plsql的结构,小编现在分享给大家,供广大互联网技能从业者学习和参考。文章包含2506字,纯文字阅读大概需要4分钟。
内容图文
![oracle plsql的结构](/upload/InfoBanner/zyjiaocheng/527/2197f5bc79f14e798868a8c977cd22f7.jpg)
变量声明部分(没有变量可以不写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 number default 24; lisi number :=28; begin if zhangsan<lisi then dbms_output.put_line(‘zhangsan younger than lisi‘); end if; end; /
if 条件 then
...
elsif 条件 then
...
end if;
declare age number default 90; height number :=175; gender char(2):=‘男‘; begin if gender=‘男‘ then dbms_output.put_line(‘你可以和女性结婚‘); end if; if height>170 then dbms_output.put_line(‘可以打篮球‘); else dbms_output.put_line(‘可以踢足球‘); end if; if age<20 then dbms_output.put_line(‘年轻小伙‘); elsif age <= 50 then dbms_output.put_line(‘年轻有为‘); elsif age <=70 then dbms_output.put_line(‘安享天伦‘); else dbms_output.put_line(‘佩服佩服‘); end if; end;
二。While循环语句:
while 条件 loop
循环体
end loop;
declare age number default 1; begin while age <=10 loop dbms_output.put_line(‘age is‘||age); age:=age+1; end loop; end;
三。For循环结构:
for 循环变量 in [reverse] 起始值..终止值 loop
循环体
end loop;
begin for i in 1..9 loop dbms_output.put_line(i); end loop; for i in reverse 1..9 loop 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=100 then exit; end if; 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 a1 is begin dbms_output.put_line(‘hello‘); end; /
调用
Call a1();
create procedure a2(width int,height int) is area int:=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
内容总结
以上是互联网集市为您收集整理的oracle plsql的结构全部内容,希望文章能够帮你解决oracle plsql的结构所遇到的程序开发问题。 如果觉得互联网集市技术教程内容还不错,欢迎将互联网集市网站推荐给程序员好友。
内容备注
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 gblab@vip.qq.com 举报,一经查实,本站将立刻删除。
内容手机端
扫描二维码推送至手机访问。