G-6010
πWarning
Always use a character variable to execute dynamic SQL.
Reason
Having the executed statement in a variable makes it easier to debug your code (e.g. by logging the statement that failed).
Example
Non-Compliant Example
declare
l_next_val employees.employee_id%type;
begin
execute immediate 'select employees_seq.nextval from dual'
into l_next_val;
end;
/ | Line | Column | Message |
|---|---|---|
| 4 | 22 |
Compliant Solution - β
β
β
β
β
declare
l_next_val employees.employee_id%type;
co_sql constant types_up.big_string_type :=
'select employees_seq.nextval from dual';
begin
execute immediate co_sql into l_next_val;
end;
/ References
- same as Trivadis G-6010
