Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Oracle Collections

Posted on 2006-07-10
1
Medium Priority
?
462 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Get free NFR key for Veeam Availability Suite 9.5

Veeam is happy to provide a free NFR license (1 year, 2 sockets) to all certified IT Pros. The license allows for the non-production use of Veeam Availability Suite v9.5 in your home lab, without any feature limitations. It works for both VMware and Hyper-V environments

Question has a verified solution.

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

In today's business world, data is more important than ever for informing marketing campaigns. Accessing and using data, however, may not come naturally to some creative marketing professionals. Here are four tips for adapting to wield data for insi…
Instead of error trapping or hard-coding for non-updateable fields when using QODBC, let VBA automatically disable them when forms open. This way, users can view but not change the data. Part 1 explained how to use schema tables to do this. Part 2 h…
This is a high-level webinar that covers the history of enterprise open source database use. It addresses both the advantages companies see in using open source database technologies, as well as the fears and reservations they might have. In this…
In this video, Percona Director of Solution Engineering Jon Tobin discusses the function and features of Percona Server for MongoDB. How Percona can help Percona can help you determine if Percona Server for MongoDB is the right solution for …

664 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