Reputation: 21
I'm trying to to display the list of unique customer_IDs in the sales table.
after several attempts I reached to this code but there is no output and I'm not sure if its the write structure. any help please?
declare
c_id int;
begin
select max(unique(customer_ID)) into c_id from sales;
LOOP
DBMS_OUTPUT.PUT_LINE ('Employee Nnumber: ' || c_id);
end loop ;
end;
/
Upvotes: 0
Views: 745
Reputation: 231791
Based on the text of your question, my guess is that you are looking for something like
BEGIN
FOR c IN (SELECT DISTINCT customer_id FROM sales)
LOOP
dbms_output.put_line( 'Customer ID: ' || c.customer_id );
END LOOP;
END;
Of course, you'd need to enable dbms_output
in whatever tool you are using to see the output (set serveroutput on;
in SQL*Plus
).
Upvotes: 1