I am having issues concatenating a string to be called be execute immediate. Anybody have any idea what is wrong with the following statement below.
EXECUTE IMMEDIATE 'ALTER SESSION SET smtp_out_server = ''||SMTPServer||''';
select smtpserver into SMTPServer from mytable;
if(SMTPServer is not null)
then
EXECUTE IMMEDIATE 'ALTER SESSION SET smtp_out_server = ''||SMTPServer||''';
--*****above does not work, below does work****
EXECUTE IMMEDIATE 'ALTER SESSION SET smtp_out_server = ''10.1.1.1''';
From the standpoint of building the string you want, you're missing a couple of single quotes. You'd need 3 single quotes before and four single quotes after the
SMTPServer
local variablePersonally, I'd find it easier to do something like this where you declare a template (using the q quoting syntax since it has embedded single quotes), call
replace
to replace the templated values, and then callEXECUTE IMMEDIATE
. It's a bit more code but it generally makes life easier.Are you sure that the second statement really works, though?
smtp_out_server
isn't supposed to be modifiable without a database restart. I've seen folks say that they've been able to modify it successfully with anALTER SYSTEM
at runtime but haven't seen anyone try to do it with anALTER SESSION
. I'd hesitate to build code that depends on behavior that goes against the documentation. If you need to control the SMTP server you're using at runtime, I'd strongly suggest using theutl_smtp
package rather thanutl_mail
.