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!

Fetching distinct records from a cursor at runtime

3573980Feb 7 2018 — edited Feb 8 2018

Hello,

I have a cursor which is fetching records from some tables. Below is the sample code. In my code, i have to reuse the cursor multiples and while doing that, I also might have to use few fields in the cursor and do a distinct as those columns have duplicates.

My question is, after the LOOP, while fetching the records, can we remove duplicates?

Thanks
Kumar

DECLARE
  c_id customers
.id%type;
  c_name customerS
.No.ame%type;
  c_addr customers
.address%type;
  CURSOR c_customers
is
  SELECT id
, name, address FROM customers;
BEGIN
  OPEN c_customers
;
  LOOP
  FETCH c_customers
into c_id, c_name, c_addr;
  EXIT WHEN c_customers
%notfound;
  dbms_output
.put_line(c_id || ' ' || c_name || ' ' || c_addr);
  
END LOOP;
  CLOSE c_customers
;
END;

Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Mar 8 2018
Added on Feb 7 2018
7 comments
2,223 views