Home » SQL & PL/SQL » SQL & PL/SQL » PLS-00497:cannot mix between single row and multi-row (BULK) in INTO LIST (Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 - 64bit Production)
icon4.gif  PLS-00497:cannot mix between single row and multi-row (BULK) in INTO LIST [message #625756] Mon, 13 October 2014 23:48 Go to next message
jhonnappier2007
Messages: 4
Registered: October 2014
Location: UAE
Junior Member
Hello,

I am trying to fetch some records from a table into a record. say rec1 ( col1 , col2)

after that i need to copy the distinct values of rec1.col1 into an array.

But I am getting this ERROR PLS-00497:cannot mix between single row and multi-row (BULK) in INTO LIST.


Here is the piece of code im working with.

CREATE OR REPLACE TYPE userobj1 AS OBJECT
(
  col1 NUMBER(13),
  col2 NUMBER(13)
);

CREATE OR REPLACE TYPE userobj2 AS TABLE OF userobj1;

CREATE OR REPLACE TYPE num_array AS TABLE OF NUMBER(20);

DECLARE

       rec1 userobj1;

       rec2 userobj2 := userobj2();

       v_arr num_array;

       CURSOR cur IS
          SELECT LEVEL col1, LEVEL*10 col2 FROM dual CONNECT BY LEVEL < 10;  --there is no duplicate values here , this is for test only.

BEGIN

          OPEN cur;

          FETCH cur 
      	    BULK COLLECT 
		INTO rec1; --Error "ORA-06550: line 17, column 29: PLS-00497: cannot mix between single row and multi-row (BULK) in INTO LIST"

          SELECT col1 BULK COLLECT INTO v_arr FROM TABLE(CAST(rec1 AS userobj2 --or rec2 ?  have some doubts here please help on that too.
          ));

          FOR i IN 1 .. v_arr.COUNT 
              LOOP 
		dbms_output.put_line(v_arr(i)); 
	      END LOOP;

          CLOSE cur;

EXCEPTION 
          WHEN 
              OTHERS 
		 THEN 
		     IF cur%ISOPEN 
			  THEN 
			      CLOSE cur; 
		     END IF; 
											
			dbms_output.put_line(SQLERRM); 
											
			RAISE; 
END;



Where Am I wrong??

Please help

Thanks in advance.
Re: PLS-00497:cannot mix between single row and multi-row (BULK) in INTO LIST [message #625757 is a reply to message #625756] Tue, 14 October 2014 00:22 Go to previous messageGo to next message
Michel Cadot
Messages: 68645
Registered: March 2007
Location: Nanterre, France, http://...
Senior Member
Account Moderator

Quote:
FETCH cur 
      	    BULK COLLECT 
		INTO rec1;


BULK COLLECT means you insert into an array; rec1 is a single record variable, so mismatch.
It should be rec2 and cursor should be defined as:
SELECT userobj1 (LEVEL, LEVEL*10) FROM dual CONNECT BY LEVEL < 10; 

Re: PLS-00497:cannot mix between single row and multi-row (BULK) in INTO LIST [message #625760 is a reply to message #625757] Tue, 14 October 2014 00:41 Go to previous messageGo to next message
jhonnappier2007
Messages: 4
Registered: October 2014
Location: UAE
Junior Member
Thank you Michel Cadot.

I had a little confusion there.

Now the code works fine. Could you please point me to some more reading on the same?

PS: Here is the corrected code. for those who may encounter similar problem


CREATE OR REPLACE TYPE userobj1 AS OBJECT
(
  col1 NUMBER(13),
  col2 NUMBER(13)
);

CREATE OR REPLACE TYPE userobj2 AS TABLE OF userobj1;

CREATE OR REPLACE TYPE num_array AS TABLE OF NUMBER(20);


DECLARE

  rec2 userobj2 := userobj2();

  v_arr num_array;

  CURSOR cur IS
    SELECT userobj1(LEVEL, LEVEL) FROM dual CONNECT BY LEVEL < 10;

BEGIN

  OPEN cur;

  FETCH cur BULK COLLECT
    INTO rec2; 

  SELECT col2 BULK COLLECT INTO v_arr FROM TABLE(CAST(rec2 AS userobj2));

  FOR i IN 1 .. v_arr.COUNT
  LOOP
    dbms_output.put_line(v_arr(i));
  END LOOP;

  CLOSE cur;

EXCEPTION
  WHEN OTHERS THEN
    IF cur%ISOPEN
    THEN
      CLOSE cur;
    END IF;
  
    dbms_output.put_line(SQLERRM);
  
    RAISE;
END;

[Updated on: Tue, 14 October 2014 00:56]

Report message to a moderator

Re: PLS-00497:cannot mix between single row and multi-row (BULK) in INTO LIST [message #625766 is a reply to message #625760] Tue, 14 October 2014 02:05 Go to previous messageGo to next message
Michel Cadot
Messages: 68645
Registered: March 2007
Location: Nanterre, France, http://...
Senior Member
Account Moderator

Thanks for the feedback and code.
I only know
Database PL/SQL Language Reference
Chapter 5 PL/SQL Collections and Records

Re: PLS-00497:cannot mix between single row and multi-row (BULK) in INTO LIST [message #625774 is a reply to message #625766] Tue, 14 October 2014 03:15 Go to previous messageGo to next message
jhonnappier2007
Messages: 4
Registered: October 2014
Location: UAE
Junior Member
Thanks once again.

One more question , How can i refer the rec2 in a for loop.
and also how to refer the individual elements from rec2.

for a record
for i in 1..rec.col1.count
loop
dbms_output.put_line(rec.col1(i));


I mean how can i refer elemets in the user defined object table.
Re: PLS-00497:cannot mix between single row and multi-row (BULK) in INTO LIST [message #625777 is a reply to message #625774] Tue, 14 October 2014 03:35 Go to previous messageGo to next message
Michel Cadot
Messages: 68645
Registered: March 2007
Location: Nanterre, France, http://...
Senior Member
Account Moderator

SQL> DECLARE
  2    rec2 userobj2 := userobj2();
  3    CURSOR cur IS
  4      SELECT userobj1(LEVEL, LEVEL) FROM dual CONNECT BY LEVEL < 10;
  5  BEGIN
  6    OPEN cur;
  7    FETCH cur BULK COLLECT INTO rec2;
  8    CLOSE cur;
  9    FOR i IN 1 .. rec2.COUNT
 10    LOOP
 11      dbms_output.put_line(rec2(i).col1||' '||rec2(i).col2);
 12    END LOOP;
 13  EXCEPTION
 14    WHEN OTHERS THEN
 15      IF cur%ISOPEN THEN CLOSE cur; END IF;
 16      RAISE;
 17  END;
 18  /
1 1
2 2
3 3
4 4
5 5
6 6
7 7
8 8
9 9

Re: PLS-00497:cannot mix between single row and multi-row (BULK) in INTO LIST [message #625781 is a reply to message #625777] Tue, 14 October 2014 03:46 Go to previous message
jhonnappier2007
Messages: 4
Registered: October 2014
Location: UAE
Junior Member
Thank you so much for your prompt reply.

You have been very helpful.

Previous Topic: Convert a string to a date using TO_DATE Function in after insert trigger?
Next Topic: dbms_stats and bind variables
Goto Forum:
  


Current Time: Fri Apr 26 00:33:40 CDT 2024