Home » SQL & PL/SQL » SQL & PL/SQL » Multi Set operator (MULTISET UNION DISTINCT) in PL/SQL (11g)
Multi Set operator (MULTISET UNION DISTINCT) in PL/SQL [message #649438] Fri, 25 March 2016 13:15 Go to next message
vikram_2050
Messages: 10
Registered: June 2005
Location: bangalore
Junior Member
Hi,

Having an issue with multi set operators in pl/sql.

MULTISET UNION working fine.



set serveroutput on
declare
TYPE rec IS RECORD (
   name varchar2(1000)
      );
TYPE ttbl IS TABLE OF rec;
p ttbl:=ttbl();
t ttbl:=ttbl();
x ttbl:=ttbl();
begin 
for i in 1..10
loop
p.extend;
p(i).name:=i;
end loop;

for j in 1..15
loop
t.extend;
t(j).name:=j;
end loop;

x:= t MULTISET UNION  p;

for k in x.first..x.last
loop
dbms_output.put_line(x(k).name);
end loop;
end;


Output:

PL/SQL procedure successfully completed.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
1
2
3
4
5
6
7
8
9
10



MULTISET UNION DISTINCT throwing an error in below code


set serveroutput on
declare
TYPE rec IS RECORD (
   name varchar2(1000)
      );
TYPE ttbl IS TABLE OF rec;
p ttbl:=ttbl();
t ttbl:=ttbl();
x ttbl:=ttbl();
begin 
for i in 1..10
loop
p.extend;
p(i).name:=i;
end loop;

for j in 1..15
loop
t.extend;
t(j).name:=j;
end loop;

x:= t MULTISET UNION DISTINCT p;

for k in x.first..x.last
loop
dbms_output.put_line(x(k).name);
end loop;
end;

error Message:

Error report -
ORA-06550: line 22, column 5:
PLS-00306: wrong number or types of arguments in call to 'MULTISET_UNION_DISTINCT'
ORA-06550: line 22, column 1:
PL/SQL: Statement ignored
06550. 00000 -  "line %s, column %s:\n%s"
*Cause:    Usually a PL/SQL compilation error.
*Action:




I am not able to understand why it is throwing this error message.

Any help really appreciated.

thanks in advance
Re: Multi Set operator (MULTISET UNION DISTINCT) in PL/SQL [message #649439 is a reply to message #649438] Fri, 25 March 2016 13:39 Go to previous messageGo to next message
BlackSwan
Messages: 26766
Registered: January 2009
Location: SoCal
Senior Member
>(11g)
above is NOT Oracle version.
above is marketing label

what is OS name & version
what is Oracle version to 4 decimal places; like V11.2.0.4.0
Re: Multi Set operator (MULTISET UNION DISTINCT) in PL/SQL [message #649440 is a reply to message #649439] Fri, 25 March 2016 13:50 Go to previous messageGo to next message
vikram_2050
Messages: 10
Registered: June 2005
Location: bangalore
Junior Member
Oracle Version

Oracle Database 11g Enterprise Edition Release 11.2.0.4.0 - 64bit
PL/SQL Release 11.2.0.4.0 -


OS Version

Windows 7 Professional
Service Pack 1
Re: Multi Set operator (MULTISET UNION DISTINCT) in PL/SQL [message #649441 is a reply to message #649438] Fri, 25 March 2016 13:53 Go to previous messageGo to next message
Michel Cadot
Messages: 68645
Registered: March 2007
Location: Nanterre, France, http://...
Senior Member
Account Moderator

And format your code.
This means not only use code tags but also INDENT the code like Barbara showed you in your previous topic.
Also I can notice you didn't feedback and thank her for the help she gave you.
Why a so disdainful behavior?


Re: Multi Set operator (MULTISET UNION DISTINCT) in PL/SQL [message #649443 is a reply to message #649441] Fri, 25 March 2016 13:59 Go to previous messageGo to next message
vikram_2050
Messages: 10
Registered: June 2005
Location: bangalore
Junior Member
Thanks Michel for your advice.

I had a login issues because of that I was not able to thank Barbara.

Just now I have thanked her for the response.

Re: Multi Set operator (MULTISET UNION DISTINCT) in PL/SQL [message #649444 is a reply to message #649440] Fri, 25 March 2016 14:08 Go to previous messageGo to next message
BlackSwan
Messages: 26766
Registered: January 2009
Location: SoCal
Senior Member
It looks like a bug to me.
I reproduced the same results on my DB.
 20  x:= t MULTISET UNION DISTINCT p;
 21  for k in x.first..x.last
 22  loop
 23  dbms_output.put_line(x(k).name);
 24  end loop;
 25* end;
 26  /
x:= t MULTISET UNION DISTINCT p;
    *
ERROR at line 20:
ORA-06550: line 20, column 5:
PLS-00306: wrong number or types of arguments in call to
'MULTISET_UNION_DISTINCT'
ORA-06550: line 20, column 1:
PL/SQL: Statement ignored


SQL> select * from V$Version;

BANNER
--------------------------------------------------------------------------------
Oracle Database 11g Enterprise Edition Release 11.2.0.2.0 - Production
PL/SQL Release 11.2.0.2.0 - Production
CORE    11.2.0.2.0      Production
TNS for Linux: Version 11.2.0.2.0 - Production
NLSRTL Version 11.2.0.2.0 - Production

SQL> 

Re: Multi Set operator (MULTISET UNION DISTINCT) in PL/SQL [message #649445 is a reply to message #649444] Fri, 25 March 2016 14:45 Go to previous messageGo to next message
Barbara Boehmer
Messages: 9090
Registered: November 2002
Location: California, USA
Senior Member
I get the same in 12c. I don't know that I would label this a bug. It might be considered expected behavior. The MULTISET UNION DISTINCT works fine with scalar data types. I believe the issue with non-scalar data types, is that, in order to perform a distinct, a comparison must be made, and in order to compare non-scalar types, there must be a map function, which requires a SQL type, as demonstrated below.

SCOTT@orcl> CREATE OR REPLACE TYPE rec AS OBJECT
  2    (name  VARCHAR2(1000),
  3  	MAP MEMBER FUNCTION sort_key RETURN VARCHAR2);
  4  /

Type created.

SCOTT@orcl> SHOW ERRORS
No errors.
SCOTT@orcl> CREATE OR REPLACE TYPE BODY rec
  2  AS
  3    MAP MEMBER FUNCTION sort_key RETURN VARCHAR2
  4    IS
  5    BEGIN
  6  	 RETURN name;
  7    END;
  8  END;
  9  /

Type body created.

SCOTT@orcl> SHOW ERRORS
No errors.
SCOTT@orcl> CREATE OR REPLACE TYPE ttbl AS TABLE OF rec;
  2  /

Type created.

SCOTT@orcl> SHOW ERRORS
No errors.
SCOTT@orcl> declare
  2    p ttbl:=ttbl();
  3    t ttbl:=ttbl();
  4    x ttbl:=ttbl();
  5  begin
  6    for i in 1..10
  7    loop
  8  	 p.extend;
  9  	 p(i) := rec(i);
 10    end loop;
 11  
 12    for j in 1..15
 13    loop
 14  	 t.extend;
 15  	 t(j) := rec(j);
 16    end loop;
 17  
 18    x:= t MULTISET UNION DISTINCT p;
 19  
 20    for k in x.first..x.last
 21    loop
 22  	 dbms_output.put_line(x(k).name);
 23    end loop;
 24  end;
 25  /
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15

PL/SQL procedure successfully completed.




Re: Multi Set operator (MULTISET UNION DISTINCT) in PL/SQL [message #649446 is a reply to message #649444] Fri, 25 March 2016 14:49 Go to previous messageGo to next message
Solomon Yakobson
Messages: 3273
Registered: January 2010
Location: Connecticut, USA
Senior Member
No, it is not a bug. Type ttbl is nested table of composite type - record. DISTINCT requires comparing two records for equality and Oracle doesn't support record comparison:

SQL> declare
  2      r1 emp%rowtype;
  3      r2 emp%rowtype;
  4  begin
  5      if r1 = r2
  6        then
  7          dbms_output.put_line('Equal');
  8        else
  9          dbms_output.put_line('Not equal or null');
 10      end if;
 11  end;
 12  /
    if r1 = r2
          *
ERROR at line 5:
ORA-06550: line 5, column 11:
PLS-00306: wrong number or types of arguments in call to '='
ORA-06550: line 5, column 5:
PL/SQL: Statement ignored


SQL>


SY.
Re: Multi Set operator (MULTISET UNION DISTINCT) in PL/SQL [message #649447 is a reply to message #649445] Fri, 25 March 2016 16:06 Go to previous message
vikram_2050
Messages: 10
Registered: June 2005
Location: bangalore
Junior Member
Thanks for your response.
Previous Topic: Multi Level Table Type Output
Next Topic: Simplify SQL Interface to Oracle R Enterprise
Goto Forum:
  


Current Time: Thu Apr 25 13:15:05 CDT 2024