Oracle update

Greeting,

I have a table contains a password field( VARCHAR2(32)) in oracle. How to update it to a system auto generate data?

Thanks.
mrongAsked:
Who is Participating?
 
slightwv (䄆 Netminder)Connect With a Mentor Commented:
>>can I update the existing records in that field?

update mytable set password=dbms_random.string('a',10);
0
 
slightwv (䄆 Netminder) Commented:
What do you want the autogenerted data to look like?

You can create a trigger that will generate a password for that column whenever a new row is inserted.
0
 
mrongAuthor Commented:
just auto generate password.

by the way, I have existing records in the table already. can I update the existing records in that field?

thanks.
0
 
slightwv (䄆 Netminder) Commented:
>>just auto generate password.

For alphanumeric, 10 characters long:
dbms_random.string('a',10)

dbms_random has many other options if you want more complex:
http://docs.oracle.com/cd/E11882_01/appdev.112/e40758/d_random.htm#i996825

then you just need a simple trigger to set the column value.

untested but something like:
create or replace trigger mytrigger
before insert on my_table
referencing new as n
for each row
begin
:n.password := dbms_random.string('a',10);
end;
/
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.