Home

Newline and control characters should not be used in string literals

Description

    The rule "Newline and control characters should not be used in string literals" in PL/SQL code means that when writing a string literal, the programmer should avoid using any newline or control characters. This is because these characters can cause unexpected results when the code is executed. For example, if a newline character is used in a string literal, it could cause the string to be split into multiple lines when printed. Similarly, if a control character is used, it could cause unexpected behavior when the code is executed. Therefore, it is important to avoid using newline and control characters in string literals when writing PL/SQL code.

Key Benefits

  • Eliminates potential errors: By avoiding the use of newline and control characters in string literals, potential errors due to unexpected behavior are eliminated.
  • Improves readability: By avoiding the use of newline and control characters in string literals, the code is easier to read and understand.
  • Ensures cross-platform compatibility: By avoiding the use of newline and control characters in string literals, the code will work on different platforms without any issues.

 

Non-compliant Code Example

SELECT
/* 
Customer table is for holding customer data such as Name, Address, etc.
Also it contains some crucial information like Credit limit, amount spent etc.
*/
    NAME,
    ADDRESS,
    CREDIT_LIMIT
FROM
    CUSTOMERS
Where ADDRESS like '%LAKE%      --Non compliant code (Newline and control characters used in string literals)
VIEW%';

Compliant Code Example

SELECT
/* 
Customer table is for holding customer data such as Name, Address, etc.
Also it contains some crucial information like Credit limit, amount spent etc.
*/
    NAME,
    ADDRESS,
    CREDIT_LIMIT
FROM
    CUSTOMERS
Where ADDRESS like '%LAKE%' || chr (10) || 'VIEW%';       -- Compliant code (Newline and control characters used in string literals)
Visual Expert 2024
 VEPLSQLRULE37