PLS-00103: Encountered the symbol "IF" when expecting one of the following in oracle function -
i writing below function in getting error pls-00103: encountered symbol "if" when expecting 1 of following: ( - + case mod new null <an identifier>
. know error coming @ line trying append if condition threshold_min_alert
string . want append string minimum threshold
if condition , value. example minimum threshold
should come if v_threshold_min_alert = y
then
threshold_min_alert(alert configured) 100
if v_threshold_min_alert = n
then
threshold_min_alert 100
if remove if condition function runs fine.i dont know syntax of how append if codition.here function:
function build_alert_email_body ( in_alert_logs_timestamp in timestamp ) return varchar2 body varchar2(4000) := ''; v_kpi_def_id number := ''; v_kpi_type_id number := ''; v_kpi_threshold_min_vale number := ''; v_kpi_threshold_max_vale number := ''; v_threshold_min_alert number; begin select kpi_def_id v_kpi_def_id kpi_logs kpi_log_id = in_kpi_log_id; select kt.kpi_type_id v_kpi_type_id kpi_definition kd join kpi_type kt on kd.kpi_type = kt.kpi_type_id kd.kpi_def_id = v_kpi_def_id; select threshold_max_val v_kpi_threshold_max_vale kpi_definition kpi_def_id = v_kpi_def_id; select threshold_min_val v_kpi_threshold_min_vale kpi_definition kpi_def_id = v_kpi_def_id; select threshold_min_alert v_threshold_min_alert kpi_definition kpi_def_id = v_kpi_def_id; select threshold_max_alert v_threshold_max_alert kpi_definition kpi_def_id = v_kpi_def_id; body := 'alert timestamp : ' || to_char(in_alert_logs_timestamp,'dd.mm.yyyy hh24:mi') || chr(13) || chr(10); if ((v_kpi_type_id = 18) or (v_kpi_type_id = 19)) body := body || 'minimum threshold' || if (v_threshold_min_alert = y) '(alert configured)' end if; || v_kpi_threshold_min_vale || chr(13); end if; return body; end build_alert_email_body;
the problem in below if-end if block:
if (v_threshold_min_alert = y) '(alert configured)' end if; || v_kpi_threshold_min_vale || chr(13); end if;
- you need assign value variable.
- "y" string, , not boolean value. must enclose within single-quotation marks.
for example,
if (v_threshold_min_alert = 'y') body := body||'(alert configured)'; else body := body|| v_kpi_threshold_min_vale || chr(13); end if;
alternatively, use case expression:
for example,
body := body || 'minimum threshold' || case when v_threshold_min_alert = 'y' 'alert configured' end || v_kpi_threshold_min_vale || chr(13);
also,
body varchar2(4000) := '';
body oracle keyword. better use different name.
for example,
v_body varchar2(4000) := '';
Comments
Post a Comment