Skip to Main Content

SQL & PL/SQL

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Interested in getting your voice heard by members of the Developer Marketing team at Oracle? Check out this post for AppDev or this post for AI focus group information.

appending a collection with another

RajatJul 19 2020 — edited Jul 20 2020

Hi all,

set serveroutput on;

DECLARE

    --TYPE t_tab IS TABLE OF emp%ROWTYPE INDEX BY BINARY_INTEGER;

    l_tab1   test_api.t_tab;

    l_tab2   test_api.t_tab;

  BEGIN

    SELECT *

    BULK COLLECT INTO l_tab1

    FROM   emp

    WHERE  deptno = 10;

    DBMS_OUTPUT.put_line('Loop Through Collection');

    FOR cur_rec IN (SELECT *

                    FROM   TABLE(l_tab1)

                   )

    LOOP

      DBMS_OUTPUT.put_line(cur_rec.empno || ' : ' || cur_rec.ename|| ' : ' || cur_rec.sal);

    END LOOP;

   DBMS_OUTPUT.put_line('---------------');

    SELECT *

    BULK COLLECT INTO l_tab2

    FROM   emp

    WHERE  deptno = 20;

   

   --l_tab1 := l_tab1 multiset union l_tab2;

   

    FOR cur_rec IN (SELECT *

                    FROM   TABLE(l_tab2)

                    order by sal

                    )

    LOOP

      DBMS_OUTPUT.put_line(cur_rec.empno || ' : ' || cur_rec.ename|| ' : ' || cur_rec.sal);

    END LOOP;

  END;

 

Result of the program is

Loop Through Collection

7782 : CLARK : 2450

7839 : KING : 5000

7934 : MILLER : 1300

---------------

7369 : SMITH : 800

7876 : ADAMS : 1100

7566 : JONES : 2975

PL/SQL procedure successfully completed.

Is there any way i can append l_tab1 with l_tab12. I tried with

quote

_tab1 := l_tab1 multiset union l_tab2;

unquote

but it is giving me below error

Error report -

ORA-06550: line 26, column 14:

PLS-00306: wrong number or types of arguments in call to 'MULTISET_UNION_ALL'

ORA-06550: line 26, column 14:

PLS-00306: wrong number or types of arguments in call to 'MULTISET_UNION_ALL'

ORA-06550: line 26, column 4:

PL/SQL: Statement ignored

06550. 00000 -  "line %s, column %s:\n%s"

*Cause:    Usually a PL/SQL compilation error.

*Action:

Could you please help.

Regards

Rajat

This post has been answered by mathguy on Jul 19 2020
Jump to Answer

Comments

Post Details

Added on Jul 19 2020
15 comments
2,156 views