Pass the input to the PL / SQL block binding variable and concatenate inside PL / SQL after use DBMS_ASSERT.ENQUOTE_NAMEto validate the input.
(The original poster understands the dangers of this approach, but it is worth repeating it: this is usually not a good idea. Always avoid building SQL queries with concatenation when possible. 99.9% of the time this can be done using old old variables bindings There are many hidden ways to do SQL injection when strings are combined.)
declare
v_quoted_string varchar2(100);
begin
v_quoted_string := dbms_assert.enquote_name(:v_new_password, capitalize => false);
execute immediate 'alter user myusername identified by '||v_quoted_string;
end;
/
If the user tries to break out of the name, using a double quotation mark, an exception will be raised: ORA-44003: invalid SQL name.
source
share