No, execute immediate
statement will be of no help in this situation. Besides there is really no need to use it - everything(select list, table names) is known at compile time, it only comes down to the string substitution. Use static query, not dynamic. In order to do the substitution(or string formatting) you have at least two choices:
Simply use
replace()
function:set serveroutput on; clear screen; declare l_result varchar2(50); begin select err_message into l_result from error_messages where err_code = 'CN001'; dbms_output.put_line(replace(l_result, ':USERNM', 'new value')); end;
Result:
Invalid Username new value
If it possible, update
err_message
column of yourerror_messages
table by replacing:USERNM
and:PWD
and other similar sub-strings thta denote placeholders with%s
(placeholder for a character literal) or%d
(placeholder for an integer literal if you have any) and use utl_lms package and specificallyformat_message()
function:set serveroutput on; clear screen; declare l_result varchar2(50); begin select err_message into l_result from error_messages where err_code = 'CN001'; dbms_output.put_line( utl_lms.format_message(l_result, 'new_value_goes_here') ); end;
Result:
Invalid Username new_value_goes_here