dbalearner
Technical User
I am new to associative arrays.
Here I am trying to do the equivalent of the folowing:
create table mytable as select n1,padding from T1 where rownum <=5;
Table created.
And join this table with T1 and the get the first 10 matching records
1 SELECT * FROM
2 (
3 SELECT
4 T1.n1
5 , T1.small_vc
6 , mytable.padding
7 FROM
8 mytable
9 , T1
10 WHERE
11 mytable.n1 = T1.n1
12 )
13* WHERE ROWNUM <= 10;
Now with assicative arrays I do
1 DECLARE
2 type array is table of T1%rowtype index by binary_integer;
3 l_data array;
4 l_rec T1%rowtype;
5 BEGIN
6 SELECT
7 *
8 BULK COLLECT INTO
9 l_data
10 FROM T1
11 WHERE ROWNUM <=5; -- the top 5 records
12 FOR i IN 1..l_data.count
13 LOOP
14 BEGIN
15 --
16 SELECT
17 *
18 INTO
19 l_rec
20 FROM
21 T1
22 WHERE
23 T1.n1 = l_data(i).n1;
24 EXCEPTION
25 WHEN OTHERS THEN
26 DBMS_OUTPUT.PUT_LINE(to_char(SQLCODE) || ' - ' || substr(SQLERRM,1,200));
27 END;
28 END LOOP;
29* END;
/
-1422 - ORA-01422: exact fetch returns more than requested number of rows
-1422 - ORA-01422: exact fetch returns more than requested number of rows
-1422 - ORA-01422: exact fetch returns more than requested number of rows
-1422 - ORA-01422: exact fetch returns more than requested number of rows
-1422 - ORA-01422: exact fetch returns more than requested number of rows
Obviously the coding is not right. Also I want to display the first 10 result set.
Thanks,
Learner
Here I am trying to do the equivalent of the folowing:
create table mytable as select n1,padding from T1 where rownum <=5;
Table created.
And join this table with T1 and the get the first 10 matching records
1 SELECT * FROM
2 (
3 SELECT
4 T1.n1
5 , T1.small_vc
6 , mytable.padding
7 FROM
8 mytable
9 , T1
10 WHERE
11 mytable.n1 = T1.n1
12 )
13* WHERE ROWNUM <= 10;
Now with assicative arrays I do
1 DECLARE
2 type array is table of T1%rowtype index by binary_integer;
3 l_data array;
4 l_rec T1%rowtype;
5 BEGIN
6 SELECT
7 *
8 BULK COLLECT INTO
9 l_data
10 FROM T1
11 WHERE ROWNUM <=5; -- the top 5 records
12 FOR i IN 1..l_data.count
13 LOOP
14 BEGIN
15 --
16 SELECT
17 *
18 INTO
19 l_rec
20 FROM
21 T1
22 WHERE
23 T1.n1 = l_data(i).n1;
24 EXCEPTION
25 WHEN OTHERS THEN
26 DBMS_OUTPUT.PUT_LINE(to_char(SQLCODE) || ' - ' || substr(SQLERRM,1,200));
27 END;
28 END LOOP;
29* END;
/
-1422 - ORA-01422: exact fetch returns more than requested number of rows
-1422 - ORA-01422: exact fetch returns more than requested number of rows
-1422 - ORA-01422: exact fetch returns more than requested number of rows
-1422 - ORA-01422: exact fetch returns more than requested number of rows
-1422 - ORA-01422: exact fetch returns more than requested number of rows
Obviously the coding is not right. Also I want to display the first 10 result set.
Thanks,
Learner