Home » SQL & PL/SQL » SQL & PL/SQL » whats wrong with this associative array (Oracle 11g)
whats wrong with this associative array [message #421923] Fri, 11 September 2009 18:21 Go to next message
rockstar01
Messages: 2
Registered: September 2009
Junior Member
I am trying out some associative arrays examples of PL/SQL from the book PL/SQL by Example and the following code is not showing the output as it should. When I run it all it prints is 21 and then when i hit enter it prints 22..23 and so on. The student table is puplated and has rows that match the query in the cursor. Also i am connecting to correct schema in sql plus to run this.

DECLARE
CURSOR name_cur IS
SELECT last_name FROM student WHERE rownum <= 10;


TYPE last_name_type IS TABLE OF student.last_name%TYPE
INDEX BY BINARY_INTEGER;
last_name_tab last_name_type;

v_counter INTEGER := 0;

BEGIN
FOR name_rec IN name_cur LOOP
v_counter := v_counter + 1;
last_name_tab(v_counter) := name_rec.last_name;
DBMS_OUTPUT.PUT_LINE ('last_name('||v_counter||'): ' || last_name_tab(v_counter));
DBMS_OUTPUT.PUT_LINE ('output test');
END LOOP;
END;
Re: whats wrong with this associative array [message #421924 is a reply to message #421923] Fri, 11 September 2009 20:06 Go to previous messageGo to next message
BlackSwan
Messages: 24912
Registered: January 2009
Senior Member
DECLARE 
  CURSOR name_cur IS 
    SELECT last_name 
    FROM   student 
    WHERE  ROWNUM <= 10; 
   TYPE last_name_type IS TABLE OF student.last_name%TYPE INDEX BY BINARY_INTEGER ; 
   last_name_tab  LAST_NAME_TYPE; 
   v_counter      INTEGER := 0; 
BEGIN 
  FOR name_rec IN name_cur LOOP 
    v_counter := v_counter + 1; 
     
    Last_name_tab(v_counter) := name_rec.last_name; 
     
    dbms_output.Put_line('last_name(' 
                         ||v_counter 
                         ||'): ' 
                         ||Last_name_tab(v_counter)); 
     
    dbms_output.Put_line('output test'); 
  END LOOP; 
END;
/


It is one thing to compile the code.
It is another to actually execute it.

In sqlplus, the code is actually invoked by "/", as shown above.


You need to help us by following the Posting Guidelines as stated below.
http://www.orafaq.com/forum/t/88153/0/
Go to the URL above click the link "Posting Guidelines"
Go to the section labeled "Practice" & do as directed.

Re: whats wrong with this associative array [message #421941 is a reply to message #421923] Sat, 12 September 2009 00:37 Go to previous messageGo to next message
Michel Cadot
Messages: 63810
Registered: March 2007
Location: Nanterre, France, http://...
Senior Member
Account Moderator
Please read OraFAQ Forum Guide, especially "How to format your post?" section.
Make sure that lines of code do not exceed 80 characters when you format.
Indent the code (See SQL Formatter), use code tags and align the columns in result.
Use the "Preview Message" button to verify.
Also always post your Oracle version with 4 decimals.

Use SQL*Plus and copy and paste your session.

Regards
Michel
Re: whats wrong with this associative array [message #421948 is a reply to message #421941] Sat, 12 September 2009 01:59 Go to previous messageGo to next message
rockstar01
Messages: 2
Registered: September 2009
Junior Member
Sorry about that. I am new to this. I will read the instructions and post appropriately hereafter.

Thanks,
Re: whats wrong with this associative array [message #421949 is a reply to message #421948] Sat, 12 September 2009 02:29 Go to previous message
Michel Cadot
Messages: 63810
Registered: March 2007
Location: Nanterre, France, http://...
Senior Member
Account Moderator
So we will answer to your next question.

If you want an answer to this one:
Quote:
Use SQL*Plus and copy and paste your session.

Regards
Michel
Previous Topic: Get name list files in folder
Next Topic: How to avoid nulls with greatest function?
Goto Forum:
  


Current Time: Thu Sep 29 15:59:01 CDT 2016

Total time taken to generate the page: 0.11892 seconds