In Oracle, string type numbers can be converted to numbers through the CAST or TO_NUMBER function, and then mathematical operations can be performed. When converting, be careful to ensure that all strings have been converted to numbers to avoid errors. Oracle also provides other functions, such as SUBSTR and INSTR, to operate on string-type numbers.
How to calculate string type numbers in Oracle
The string type in Oracle database can Stores a numeric value. However, when doing math operations, these strings need to be converted to numeric types.
Convert string to number
There are two ways to convert a string to number:
CAST('123' AS NUMBER)
Converts the string "123" to the number 123. TO_NUMBER('123')
can also convert the string "123" to the number 123. Performing Mathematical Operations
Once strings are converted to numbers, you can perform mathematical operations on them just like you would with ordinary numbers. For example:
SELECT 10 '123' FROM DUAL;
will return 133. SELECT 10 * TO_NUMBER('123') FROM DUAL;
will also return 133. Note:
SUBSTR
and INSTR
. The above is the detailed content of How to calculate string type numbers in oracle. For more information, please follow other related articles on the PHP Chinese website!