I have a nested table that includes a list of emails, which could be inside several times. The problem is I need to get the distinct list of items, and the number of times it appears on the list.
| emails |
| ------------ |
| [email protected] |
| [email protected] |
| [email protected] |
| [email protected] |
| [email protected] |
| [email protected] |
| [email protected] |
| [email protected] |
| [email protected] |
| [email protected] |
| [email protected] |
Ideally, my result would be a table or an output that tells me the following:
| Email | Number |
| ---------- | - |
| [email protected] | 3 |
| [email protected] | 3 |
| [email protected] | 4 |
| [email protected] | 1 |
To select from a table I would use a select statement, but if I try this in my code I get an error "ORA- 00942: table or view does not exist" same with even a simple select from emails table so I'm just guessing you can't use select on nested tables that way.
The nested table was created like this:
type t_email_type is table of varchar2(100);
t_emails t_email_type := t_email_type();
and then populated under a loop that adds an email for each iteration of the loop:
t_emails.extend;
t_emails(t_emails.LAST) := user_r.email;
I tried to do what you described so far; here you go:
Table that contains e-mail addresses (some of them are duplicates):
Type you created; I think you used type within your PL/SQL procedure. That won't work if it is a function which is supposed to return result of that type because it then must be created at SQL level, so - that's what I'm doing:
Function:
FORloop selects e-mail addresses from the table and puts them intot_emails. What you're interested in is what follows in lines #12-14 as it shows how to return the result:OK, let's test it:
Distinct addresses; that's what you asked for.