Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Oracle Collections

Posted on 2006-07-10
1
Medium Priority
?
475 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 500 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

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

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

Your data is at risk. Probably more today that at any other time in history. There are simply more people with more access to the Web with bad intentions.
In this article, we’ll look at how to deploy ProxySQL.
This lesson discusses how to use a Mainform + Subforms in Microsoft Access to find and enter data for payments on orders. The sample data comes from a custom shop that builds and sells movable storage structures that are delivered to your property. …
Despite its rising prevalence in the business world, "the cloud" is still misunderstood. Some companies still believe common misconceptions about lack of security in cloud solutions and many misuses of cloud storage options still occur every day. …
Suggested Courses

877 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