Odd password rules as it'd be relatively easy to guess a new user's... but you can do this:
SELECT LPAD(SEQ_PASSWORD.NEXTVAL, 4, '0')
INTO :new.PASSWORD
FROM DUAL;
Or from 11g:
:new.PASSWORD := LPAD(SEQ_PASSWORD.NEXTVAL, 4, '0');
As an alternative to LPAD
you could also use TO_CHAR
:
:new.PASSWORD := TO_CHAR(SEQ_PASSWORD.NEXTVAL, 'FM0000');
Of course, all of these assume your USER.PASSWORD
field is defined as varchar2
, not as number
.
You probably don't want the 'OF PASSWORD' clause though; that means the sequence will only be used to set the password if that field is set by the insert
or update
statement, which doesn't seem very intuitive; and resetting the password on update of anything seems unhelpful too.