Home

TO_NUMBER should be used with a format model

Description

    The TO_NUMBER function should be used with a format model when converting a character string to a number. The format model is a template that specifies how the character string should be parsed and converted into a number. It consists of one or more format elements, which are separated by commas. Each format element specifies how a portion of the character string should be converted into a number.

Key Benefits

  • Accuracy: TO_NUMBER should be used with a format model rule to ensure accuracy in data conversion.
  • Consistency: TO_NUMBER should be used with a format model rule to ensure consistency in data conversion.
  • Efficiency: TO_NUMBER should be used with a format model rule to ensure efficient data conversion.

 

Non-compliant Code Example

UPDATE CUSTOMERS
		SET City=city, 
			CREDIT_LIMIT1 = TO_NUMBER('1800.00'),           --Non compliant code (TO_NUMBER used without format)
			ModificationDate = TO_TIMESTAMP(date_string)
		WHERE Id = customerId;

Compliant Code Example

UPDATE CUSTOMERS
		SET City=city, 
			CREDIT_LIMIT = TO_NUMBER('1800.00', '9G999D99'),        --Compliant code (TO_NUMBER used with format)
			ModificationDate = TO_TIMESTAMP(date_string,'YYYY-MM-DD HH24:MI:SS')
		WHERE Id = customerId;
Visual Expert 2024
 VEPLSQLRULE67