建一个存储过程
定义一个一维数组 Test{A,B,C,D,E,F,G,H,J,K,L}
怎么样用循环遍历数组,然后输出
新手求解
------解决方案--------------------
- SQL code
create or replace procedure p_test astype t_Test is table of varchar2(10);test t_test:=t_test('A','B','C','D','E','F','G','H','J','K','L');beginfor i in test.first .. test.last loopdbms_output.put_line(test(i));end loop;end;/set serverout onexec p_test;---------------------ABCDEFGHJKLPL/SQL procedure successfully completed.
------解决方案--------------------
------解决方案--------------------
- SQL code
DECLARE -- Define a varray of twelve strings. TYPE months_varray IS VARRAY(12) OF STRING(9 CHAR); -- Define an associative array of strings. TYPE calendar_table IS TABLE OF VARCHAR2(9 CHAR) INDEX BY BINARY_INTEGER; -- Declare and construct a varray. month MONTHS_VARRAY := months_varray('January','February','March' ,'April','May','June' ,'July','August','September' ,'October','November','December'); -- Declare an associative array variable. calendar CALENDAR_TABLE;BEGIN -- Check if calendar has no elements. IF calendar.COUNT = 0 THEN -- Print a title DBMS_OUTPUT.PUT_LINE('Assignment loop:'); DBMS_OUTPUT.PUT_LINE('----------------'); -- Loop through all the varray elements. FOR i IN month.FIRST..month.LAST LOOP -- Initialize a null associative array element. calendar(i) := ''; -- Print an indexed element from the associative array. DBMS_OUTPUT.PUT_LINE( 'Index ['||i||'] is ['||calendar(i)||']'); -- Assign the numeric index valued varray element -- to an equal index valued associative array element. calendar(i) := month(i); END LOOP; -- Print a title DBMS_OUTPUT.PUT(CHR(10)); DBMS_OUTPUT.PUT_LINE('Post-assignment loop:'); DBMS_OUTPUT.PUT_LINE('---------------------'); -- Loop through all the associative array elements. FOR i IN calendar.FIRST..calendar.LAST LOOP -- Print an indexed element from the associative array. DBMS_OUTPUT.PUT_LINE( 'Index ['||i||'] is ['||calendar(i)||']'); END LOOP; END IF;END;
代码迷推荐解决方案:oracle存储过程,http://www.daimami.com/search?q=177537