Oracle数组使用以及PLSQL操作记录

----------------------------固定长度数组
declare
type intarray is varray(30) of varchar2(100);
var_arr intarray := intarray('a','b','c','d');
begin
for i in 1..var_arr.count
loop
dbms_output.put_line(var_arr(i));
end loop;
end;
---------------------------未知长度数组
declare
type vararray is table of varchar2(50) index by binary_integer;
var_arr vararray;
begin
for i in 1..15 loop
var_arr(i) := i+10;
end loop;
dbms_output.put_line('Count: '|| var_arr.count);
dbms_output.put_line(var_arr(11));
end;

------------------------自定义1
declare
var_phone varchar2(100);
idex int;
nextIdex int;
iphone varchar2(100);
begin
var_phone := '10000,10001,10002,10003,10004';
dbms_output.put_line(var_phone);
idex := 0;
nextIdex := 1;
while nextIdex > 0 loop
nextIdex := instr(var_phone, ',', idex+1);
dbms_output.put_line(idex || ' --- ' || nextIdex);
if nextIdex > 0 then
iphone := substr(var_phone, idex+1, nextIdex-idex-1);
else
iphone := substr(var_phone, idex+1);
end if;
idex := nextIdex;
dbms_output.put_line(iphone);
end loop;
end;

------------------- 自定义2 使用数组
declare
var_phone varchar2(100) := '1000';--'10000,10001,10002,10003,10004';
idex int;
nextIdex int;
type charArray is table of varchar2(100) index by binary_integer;
phone_arr charArray;
arrCount int := 1;
begin
dbms_output.put_line(var_phone);
idex := 0;
nextIdex := 1;
while nextIdex > 0 loop
nextIdex := instr(var_phone, ',', idex+1);
dbms_output.put_line(idex || ' --- ' || nextIdex);
if nextIdex > 0 then
phone_arr(arrCount) := substr(var_phone, idex+1, nextIdex-idex-1);
arrCount := arrCount + 1;
else
phone_arr(arrCount) := substr(var_phone, idex+1);
end if;
idex := nextIdex;
--dbms_output.put_line();
end loop;
for i in 1..phone_arr.count loop
dbms_output.put_line(phone_arr(i));
end loop;
end;
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值