oracle11g - how to prevent duplicate values while using inner for loop in oracle plsql? -


i passing c1 value param c2,c3 cursor's , getting duplicate values , how write better code using plsql code?

declare       cursor cur1;       cursor  cur2             select *        param=c1.param;        cursor  cur3             select *        param=c1.param;     begin        c1 loop          c2(c1.param)            dbms_output(deptno||' '||dname);           c3(c1.param)            dbms_output(deptno||' '||dname);           end loop;         end loop;        end loop;     end;      , getting duplicate values       deptno  dname     10           20       b     30       c     10           20       b     30       c expected output     deptno  dname     10           20       b     30       c 

can please me?

sounds may want union:

declare   cursor cur1;    cursor  cur2      select * x      param=c1.param      union      select * y      param=c1.param; begin    c1 loop      c2(c1.param)        dbms_output(deptno||' '||dname);       end loop;    end loop; end; 

(i haven't fixed invalid code above - presumably real code correct or wouldn't have run @ all.)

you don't need 2 cursors, like:

declare   cursor  cur      select * x      param in (select ...)      union      select * y      param in (select ...) begin    c2 in cur loop       dbms_output(deptno||' '||dname);    end loop; end; 

Comments

Popular posts from this blog

angularjs - ADAL JS Angular- WebAPI add a new role claim to the token -

php - CakePHP HttpSockets send array of paramms -

node.js - Using Node without global install -