oracle游标循环定义变量赋值,PL/SQL  循环 数组 游标的使用

本文详细介绍了Oracle PL/SQL中如何使用存储过程、变量赋值、判断语句、For循环、While循环以及游标和数组。通过实例展示了如何遍历游标和数组,以及如何在游标操作中处理数据。此外,还提供了一个综合示例,说明如何结合游标和数组计算学生总成绩和平均成绩。
摘要由CSDN通过智能技术生成

1、创建存储过程

create or replace procedure

test(var_name_1 in type,var_name_2 out type) as

--声明变量(变量名 变量类型)

begin

--存储过程的执行体

end test;

打印出输入的时间信息

E.g:

create or replace procedure

test(workDate in Date) is

begin

dbms_output.putline('The

input date

is:'||to_date(workDate,'yyyy-mm-dd'));

end test;

2、变量赋值

变量名 := 值;

E.g:

create or replace procedure

test(workDate in Date) is

x number(4,2);

begin

x :=

1;

end test;

3、判断语句:

if 比较式 then begin end; end

if;

E.g

create or replace procedure test(x

in number) is

begin

if

x >0 then

begin

x

:= 0 - x;

end;

end

if;

if

x = 0 then

begin

x:

= 1;

end;

end

if;

end test;

4、For

循环

For ... in ... LOOP

--执行语句

end LOOP;

(1)循环遍历游标

create or replace procedure test()

as

Cursor cursor is select name from

student; name varchar(20);

begin

for name in cursor LOOP

begin

dbms_output.putline(name);

end;

end LOOP;

end test;

(2)循环遍历数组

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值