MSCCP0004
The statement below has usages of dynamic SQL
This is a deprecated version of the SnowConvert documentation, please visit the official site HERE.
Severity
High
Description
This error is used to indicate that the statement has usages of dynamic SQL. Each specific source language has its own set of statements that can execute dynamic SQL. Dynamic SQL refers to code that is built as text using the string manipulation tools the database engine language provides.
This scenario is considered a complex pattern because dynamic SQL is built and executed in runtime making it more difficult to track and debug errors. This error is meant to be a helper to spot some problems that a static-code analyzer such as Snow Convert cannot.
Code Example
Teradata
REPLACE PROCEDURE teradata_dynamic_sql()
BEGIN
DECLARE str_sql VARCHAR(20);
SET str_sql = 'UPDATE TABLE
SET COLA = 0,
COLB = ''test''';
EXECUTE IMMEDIATE str_sql;
EXECUTE IMMEDIATE 'INSERT INTO TABLE1(COL1) VALUES(1)';
EXECUTE str_sql;
CALL DBC.SysExecSQL('INSERT INTO TABLE1(COL1) VALUES(1)');
END;CREATE OR REPLACE PROCEDURE teradata_dynamic_sql ()
RETURNS VARCHAR
LANGUAGE SQL
EXECUTE AS CALLER
AS
$$
BEGIN
LET str_sql VARCHAR(20);
str_sql := 'UPDATE "TABLE"
SET COLA = 0,
COLB = ''test''';
--** MSC-ERROR - MSCCP0004 - THE STATEMENT BELOW HAS USAGES OF DYNAMIC SQL. **
EXECUTE IMMEDIATE str_sql;
--** MSC-ERROR - MSCCP0004 - THE STATEMENT BELOW HAS USAGES OF DYNAMIC SQL. **
EXECUTE IMMEDIATE 'INSERT INTO TABLE1 (COL1)
VALUES (1);';
--** MSC-ERROR - MSCCP0004 - THE STATEMENT BELOW HAS USAGES OF DYNAMIC SQL. **
EXECUTE IMMEDIATE str_sql;
--** MSC-ERROR - MSCCP0004 - THE STATEMENT BELOW HAS USAGES OF DYNAMIC SQL. **
EXECUTE IMMEDIATE 'INSERT INTO TABLE1 (COL1)
VALUES (1);';
END;
$$;Oracle
SQL Server
Issues Inside of Dynamic SQL
Something important to take into account is that when migrating dynamic SQL code, SnowConvert will not report any type of issue inside of dynamic SQL in the output code or in the assessment reports. This will happen even when the documentation of an issue or the translation specification describes that an issue will always be added to the output code. Here is an example of a migration in Oracle where this situation might be encountered:
In the previous example, the query and the variable assignment inside the procedure will be converted exactly the same, the difference is that in the dynamic SQL code the conversion issues will not be shown in the output code and in the assessment reports.
Recommendations
Use this tag to track every dynamically built statement and review its correctness when troubleshooting.
If you need more support, you can email us at [email protected]
Last updated
