oracle 數組,oracle

來源:互聯網
上載者:User

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 ,得到你需要的資料集合
}
 

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.