I am pretty new to this, so please be nice ;)
I have created a function in PL/SQL where I feed the function a UserNo and it gives me an email-address.
What I would like to be able to do, is to add a column 'EMAIL' to 'My_table' that inserts the email based on the UserNo_column.
Something like this:
Alter table My_Table add EMAIL value {USERNO2EMAIL-function(USERNO_column)} not null;
This is my function:
create or replace function userno2email
(userno in number)
return
varchar2 is email varchar2(64);
begin
select O_EMAIL into email from USERS where O_USERNO = USERNO;
return email;
end;
Thank you..

Shortly: looks like you'll have to use a trigger for that purpose.
Here's a demo.
userstable and initial row:Function; I modified it a little bit so that it is kind of safer to use - compare it to your version (you'd rather inherit datatypes involved than hardcode them; what to do if nothing has being found? Include other exception handlers, if you think you need them; use prefix for parameter name):
This is the target table:
This is what you tried to do. Syntax is now correct, but outcome is, sadly, wrong:
You could have used default value with
alter tablestatement - no problem with that, but - it has to be valid. For example:OK, let's add
emailcolumn in allowed manner:This is the trigger I mentioned at the beginning - upon insert into
my_table, it'll fetch someone's e-mail address and put it into appropriate column:OK, let's test it:
As you can see, although I inserted
IDvalue only, trigger fetched e-mail address, whiledefaultclause oninsert_datetook care about that.