ORACLE 数组初体验

1.固定数组

DECLARE
       TYPE V1 IS VARRAY(20) OF VARCHAR2(20);
       MY_V V1 :=V1('A','B','C','D','E');
BEGIN
       FOR I IN 1..MY_V.COUNT LOOP
           DBMS_OUTPUT.PUT_LINE(MY_V(I));    
       END LOOP;
END;

2.可变长数组

DECLARE
       TYPE V1 IS TABLE OF NUMBER(3) index by binary_integer;
       V V1;
BEGIN
       FOR I IN 1..20 LOOP
             V(I):=I;
             DBMS_OUTPUT.PUT_LINE(V(I));    
       END LOOP;
END;

3.二维数组

DECLARE
       TYPE V1 IS TABLE OF NUMBER index by binary_integer;
       TYPE V2 IS TABLE OF V1 index by binary_integer;
       V V2;
BEGIN
       FOR I IN 1..20 LOOP
           FOR N IN 1..20 LOOP
                 V(I)(N):=N;
                 DBMS_OUTPUT.PUT_LINE(V(I)(N));    
           END LOOP;

       END LOOP;
END;

使用数组输出以下格式的数列:
在这里插入图片描述

DECLARE
       TYPE V1 IS TABLE OF NUMBER index by binary_integer;
       TYPE V2 IS TABLE OF V1 index by binary_integer;
       V V2;
BEGIN
       FOR I IN 1..10 LOOP
           FOR N IN 1..10 LOOP
                 V(I)(N):=0;
           END LOOP;
       END LOOP;
       V(1)(1):=1;
       DBMS_OUTPUT.PUT_LINE(V(1)(1));
       FOR I IN 2..10 LOOP
           V(I)(1):=1;
           DBMS_OUTPUT.PUT(V(I)(1)||'    ');
           FOR N IN 2..I LOOP
                 V(I)(N):=(V(I-1)(N-1)+V(I-1)(N));
                 DBMS_OUTPUT.PUT(V(I)(N)||'    ');    
           END LOOP;
           DBMS_OUTPUT.PUT_LINE('');
       END LOOP;
END;
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值