Oracle PL/SQL之處理index不連續的table類型變數

來源:互聯網
上載者:User

測試代碼:

DECLARE<br /> TYPE list_of_names_t IS TABLE OF VARCHAR2(100) INDEX BY PLS_INTEGER;<br /> happyfamily list_of_names_t;<br /> l_row PLS_INTEGER;<br />BEGIN<br /> --build table data which index is not consecutive.<br /> happyfamily(2020202020) := 'Eli';<br /> happyfamily(-15070) := 'Steven';<br /> happyfamily(-90900) := 'Chris';<br /> happyfamily(-90899) := 'Chris90899';<br /> happyfamily(88) := 'Veva';</p><p> <<err1>><br /> BEGIN<br /> dbms_output.put_line('=======err1========');<br /> --i is starting from 1 and increase one by one.<br /> FOR i IN 1 .. happyfamily.COUNT<br /> LOOP<br /> dbms_output.put_line(i);<br /> dbms_output.put_line(happyfamily(i));<br /> END LOOP;<br /> EXCEPTION<br /> WHEN OTHERS THEN<br /> dbms_output.put_line('err1=>' || SQLERRM);<br /> END;</p><p> <<err2>><br /> BEGIN<br /> dbms_output.put_line('=======err2========');<br /> --i is starting from -90900 and increase one by one.<br /> FOR i IN happyfamily.FIRST .. happyfamily.LAST<br /> LOOP<br /> dbms_output.put_line(i);<br /> dbms_output.put_line(happyfamily(i));<br /> END LOOP;<br /> EXCEPTION<br /> WHEN OTHERS THEN<br /> dbms_output.put_line('err2=>' || SQLERRM);<br /> END;</p><p> <<pass>><br /> BEGIN<br /> dbms_output.put_line('=======pass========');<br /> --i is starting from -90900 and increase discrete<br /> l_row := happyfamily.FIRST;<br /> WHILE (l_row IS NOT NULL)<br /> LOOP<br /> dbms_output.put_line(l_row);<br /> dbms_output.put_line(happyfamily(l_row));<br /> l_row := happyfamily.NEXT(l_row);<br /> END LOOP;<br /> EXCEPTION<br /> WHEN OTHERS THEN<br /> dbms_output.put_line('err3=>' || SQLERRM);<br /> END;<br />END;<br />

 

輸出:

=======err1========<br />1<br />err1=>ORA-01403: no data found<br />=======err2========<br />-90900<br />Chris<br />-90899<br />Chris90899<br />-90898<br />err2=>ORA-01403: no data found<br />=======pass========<br />-90900<br />Chris<br />-90899<br />Chris90899<br />-15070<br />Steven<br />88<br />Veva<br />2020202020<br />Eli<br />

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.