zoukankan      html  css  js  c++  java
  • Oracle学习之数组

    Oracle数组一般可以分为固定数组和可变数组 
    固定数组
    declare  
    type v_ar is varray(10) of varchar2(30);   
    my_ar v_ar:=v_ar('g','m','d','龚','帅');   
    begin  
          for i in 1..my_ar.count  
          loop   
              dbms_output.put_line(my_ar(i));   
          end loop;   
    end; 
    可变数组 
    一维数组 
    declare  
    type v_table is table of varchar2(30) index by binary_integer;   
    --类型可以是前面的类型定义,index by binary_integer子句代表以符号整数为索引,   
    --这样访问表类型变量中的数据方法就是“表变量名(索引符号整数)”。   
    my_table v_table;   
    begin  
          for i in 1..20   
         loop   
              my_table(i):=i;   
              dbms_output.put_line(my_table(i));   
          end loop;   
    end; 
    多维数组--多条记录
    declare  
    type v_table is table of liutest%rowtype index by binary_integer;   
    my_table v_table;   
    begin  
          select * bulk collect into my_table from liutest;   
          for i in 1..my_table.count/10 --my_table.count/10取到的值为四舍五入值   
          loop   
              dbms_output.put_line('name--'||my_table(i).name);   
              dbms_output.put_line('address---'||my_table(i).address);   
              dbms_output.put_line('age----'||my_table(i).age);  
          end loop;   
    end; 
    多维数组--单条记录
    declare  
    type v_table is table of liutest%rowtype index by binary_integer;   
    my_table v_table;   
    begin  
          select * into my_table(1) from liutest where id=1;   
          --my_table(i) i可以为任意整数,但取值时必须保持以i一致;   
          dbms_output.put_line('--name--'||my_table(1).name||'--address--'||my_table(1).address);    
    end; 
    自定义数组 
    create or replace type varray_list as varray(30) of varchar2(50);   
    --使用自定义数组   
    create or replace procedure show_list(p_varlist in varray_list)   
    is  
    v_str varchar2(50);   
    begin  
          for i in 1..p_varlist.count    
          loop   
              v_str:=p_varlist(i);   
              dbms_output.put_line('v_str='||v_str);   
              dbms_output.put_line('p_varlist('||i||')='||p_varlist(i));   
         end loop;   
    end;   
      
    declare  
    my_var varray_list:=varray_list('g','m','d','龚','帅');   
    begin  
         show_list(my_var);    
    end; 

    http://www.cnblogs.com/lll3344/archive/2011/03/09/1978366.html

  • 相关阅读:
    Python在程序中进行多任务操作-协程
    Python-异常处理
    Python多任务-协程
    【每日一具4】TikTok 抖音国际版(网站)使用起来非常简单,无需FQ随便看
    【每日一具3】优美APP一款好用的短视频软件,优美APP专注于各种小姐姐短视频
    Python在程序中进行多任务操作-线程
    Python在程序中进行多任务操作-进程
    Python多任务-线程
    Python多任务-进程
    【每日一具3】优美APP一款好用的短视频软件,优美APP专注于各种小姐姐短视频
  • 原文地址:https://www.cnblogs.com/datang/p/2506774.html
Copyright © 2011-2022 走看看