oracle 數組,oracle
定義一個長度為5的字串數組
type str_array is varray(5) of varchar2(30);
v_str_array str_array := expr_key_array('aa','bb','cc','dd','ee');
for i in 1 .. v_str_array .count loop
dbms_output.put_line(v_expr_key);
end loop;
定義個變長字串數組
type str_array is table of varchar2(20) index by binary_integer; v_str_array str_array ;
v_str_array(1) :='aa';
v_str_array(2) :='bb';
v_str_array(3) :='cc';
oracle 數組長度
declare
type array_type is array(5) of number(2);
a array_type := array_type(5,5,5,5,5);
begin
for i in 1..a.count loop
DBMS_OUTPUT.PUT_LINE(a(i));
end loop;
end;
/
記住,你的數組最大長度是5,我給你初始化了5個資料。如果我給你初始3個資料,那麼你的數組實際長度就是3,如果你a(4)就會數組越界,下面是一種擴充數組的方法:
declare type array_type is array(5) of number(2);
a array_type := array_type();
begin
for i in 1..5 loop
a.extend;
a(i) := i;
end loop;
for i in 1..a.count loop DBMS_OUTPUT.PUT_LINE(a(i));
end loop;
end;
/
當然你也可以用 a.extend(5) 直接擴充5個(這個擴充長度不能大於5哦)
你有個地方理解錯了type a is array(5) of number(2);這句只是聲明了一個資料類型(數群組類型)
此時你的a和number(2)是一個意思
a array_type := array_type(5,5,5,5,5);這個才是定義一個陣列變數a
ORACLE 數組問題
給你個思路,把數組寫在程式裡(也就是你用的VB.NET),在程式裡拼sql語句,然後使用ADO.NET,拿到合格資料集合。
下面是虛擬碼
string[] Conditions=new stringp[]{"aa","bb","cc"};//存放where條件到數組
for(int i=0;i<Conditions.Length;i++)//遍曆你的條件數組
{
string sql="select * from 表名 where 條件="+Conditions[i];//拼sql語句
OracelDataReader reader=cmd.ExecuteQuery(sql); //藉助ADO.NET ,得到你需要的資料集合
}