Wednesday, 15 June 2011

oracle - Concatenating text in PL/SQL in a more concise way -



oracle - Concatenating text in PL/SQL in a more concise way -

i'm trying find efficient way concatenate text in pl/sql. scheme scans 5 variables, , along these lines:

return_value := '' if variable_a null return_value := 'error: variable null'; end if; if variable_b null if return_value = '' return_value := 'error: variable b null'; else return_value := return_value || ', variable b null'; end if; if variable_c null if return_value = '' return_value := 'error: variable c null'; else return_value := return_value || ', variable c null'; end if; etc.

hopefully logic of i'm trying clear - determine if of 5 variables null , concatenate text of each error message homecoming value, end of bunch of if/else statements homecoming value either null (good) or contains error phone call (bad).

is there improve way though? seems rather lengthy , feel, pl/sql newbie, i'm missing obvious way of doing in much more efficient, shorter manner.

there plenty of ways i'm sure. 1 possibility concatenate errors in same way, 'variable ? null, ', if necessary prefix 'error: ' , remove redundant comma , space @ end.

return_value := ''; if variable_a null return_value := 'variable null, '; end if; if variable_b null return_value := return_value||'variable b null, '; end if; if variable_c null return_value := return_value||'variable c null, '; end if; if variable_d null return_value := return_value||'variable d null, '; end if; if variable_e null return_value := return_value||'variable e null, '; end if; if return_value <> '' return_value := 'error: '||return_value; return_value := rtrim(return_value, ', '); end if;

sql oracle plsql concatenation

No comments:

Post a Comment