ORA-01031 Insufficient Privileges Raised From Within Function
When you have permission to perform an action at the command line but not within a definer's rights stored procedure (and I hope you're using a stored procedure here, not a stored function), the problem is almost certainly that the privilege you need has been granted through a role, not directly to the user that owns the procedure.  Inside a definer's rights stored procedure, only privileges that have been granted directly to the owner of the procedure can be used-- privileges granted through a role (such as DBA) cannot be used.

You can verify that the problem is, in fact, that the privilege is granted through a role by disabling roles and then trying to create the user, i.e.

SQL&gt; set role none;
SQL&gt; create user ...


Assuming that fails, as I expect it will, you would need to grant the owner of the function the CREATE USER privilege directly

SQL&gt; grant create user to &lt;&lt;owner of procedure&gt;&gt;


Then, you should be able to create users even with roles disabled and the stored procedure should work.