Solved

Oracle Collections

Posted on 2006-07-10
1
414 Views
Last Modified: 2010-08-05
Hi there:

I am using Oracle 10g on windows;

I have a table called books the description of the table is:

SQL> desc books;
 
Name                                       Null?    Type
----------------                           -------   ------------
ISBN                                        NOT NULL VARCHAR2(13)
TITLE                                                      VARCHAR2(200)    
SUMMARY                                               VARCHAR2(2000)
AUTHOR                                                  VARCHAR2(200)
DATE_PUBLISHED                                     DATE
PAGE_COUNT                                           NUMBER


The values of PAGE_COUNT column in books table are as follows:

SQL> select page_count from books;

PAGE_COUNT
----------
       420
       401
       502
        94
       158
       120
       692
       942
       544
       588

10 rows selected.



When I run the following query I bet the following result, I do not why, please help. THANKS!

SQL> Declare
  2    type isbn_list is table of varchar2(13);
  3    my_books isbn_list
  4    := isbn_list(
  5            '1-56592-375-8',
  6            '0-596-00121-5',
  7            '1-56592-849-0',
  8            '1-56592-335-9',
  9            '1-56592-674-9',
 10            '1-56592-675-7',
 11            '0-596-00180-0',
 12            '1-56592-457-6'
 13       );
 14  
 15  type page_numbers is table of books.page_count%type
 16  index by binary_integer;
 17  pnos page_numbers;
 18  
 19  Begin
 20     Forall book_index In
 21            my_books.First..my_books.Last
 22            update books
 23            set page_count = pnos(book_index)
 24            where isbn     = my_books(book_index);
 25     If SQL%ROWCOUNT != 8
 26     Then
 27        DBMS_OUTPUT.PUT_LINE( 'We are missing a book!');
 28     End if;
 29  
 30     If SQL%BULK_ROWCOUNT(4) = 0
 31     Then
 32        DBMS_OUTPUT.PUT_LINE( 'What happened to Oracle PL/SQL Programming?');
 33     End if;
 34  End;
 35  /
Declare
*
ERROR at line 1:
ORA-22160: element at index [1] does not exist
ORA-06512: at line 21


WHEN I hard code the value of  pnos(book_index) and substitue it say 144 the same query works fine as follows:
(SEE LINE NUMBER 23 BELOW)


SQL>  Declare
  2     type isbn_list is table of varchar2(13);
  3     my_books isbn_list
  4     := isbn_list(
  5             '1-56592-375-8',
  6             '0-596-00121-5',
  7             '1-56592-849-0',
  8             '1-56592-335-9',
  9             '1-56592-674-9',
 10             '1-56592-675-7',
 11             '0-596-00180-0',
 12             '1-56592-457-6'
 13        );
 14  
 15   type page_numbers is table of books.page_count%type
 16   index by binary_integer;
 17   pnos page_numbers;
 18  
 19   Begin
 20      Forall book_index In
 21             my_books.First..my_books.Last
 22             update books
 23             set page_count = 144
 24            where isbn     = my_books(book_index);
 25     If SQL%ROWCOUNT != 8
 26     Then
 27        DBMS_OUTPUT.PUT_LINE( 'We are missing a book!');
 28     End if;
 29  
 30     If SQL%BULK_ROWCOUNT(4) = 0
 31     Then
 32        DBMS_OUTPUT.PUT_LINE( 'What happened to Oracle PL/SQL Programming?');
 33     End if;
 34  End;
 35  /

PL/SQL procedure successfully completed.

SQL>



SQL> select page_count from books;

PAGE_COUNT
----------
       420
       144
       502
       144
       158
       120
       692
       942
       544
       144

10 rows selected.


Thanks

Muhammad Riyaz
0
Comment
Question by:blf2vkr
1 Comment
 
LVL 25

Accepted Solution

by:
jrb1 earned 125 total points
ID: 17073686
Hi blf2vkr,

You have created a table in memory called pnos.  However, you are never loading this memory table with data from the books table.  

It should looks like this:

Begin
   select page_count BULK COLLECT into pnos from books;

    Forall book_index In


Regards,
John
0

Featured Post

Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
vcenter 6 u2 install question 1 101
export Oracle diagram from Oracle DB including VIEWS 8 101
Set Warning Thresholds on Database mirroring 4 33
Error when loading the database 16 55
Entering time in Microsoft Access can be difficult. An input mask often bothers users more than helping them and won't catch all typing errors. This article shows how to create a textbox for 24-hour time input with full validation politely catching …
These days, all we hear about hacktivists took down so and so websites and retrieved thousands of user’s data. One of the techniques to get unauthorized access to database is by performing SQL injection. This article is quite lengthy which gives bas…
Video by: Steve
Using examples as well as descriptions, step through each of the common simple join types, explaining differences in syntax, differences in expected outputs and showing how the queries run along with the actual outputs based upon a simple set of dem…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

919 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now