Home  >  Article  >  Database  >  Tonumber usage in oracle

Tonumber usage in oracle

下次还敢
下次还敢Original
2024-05-08 19:18:17586browse

The TO_NUMBER function in Oracle converts a string into a numeric value. It takes a string argument, with the optional format_mask specifying the number format in the string. It returns a value of type NUMBER, or NULL if the conversion fails.

Tonumber usage in oracle

TO_NUMBER function usage in Oracle

TO_NUMBER function is used to convert a string or text value into a numeric value. It is a built-in function widely used in data conversion and calculations.

Syntax:

<code>TO_NUMBER(string, [format_mask])</code>

Parameters:

  • string: Characters to be converted String or text value.
  • format_mask (optional): Specifies the mask for the format of numbers in the string. It follows SQL standard format notation.

Example:

Convert the string "123.45" to the number 123.45:

<code class="sql">SELECT TO_NUMBER('123.45') FROM DUAL;</code>

Parse the string "1,234.56" into a number 1234.56, mask "9G999G999" Specify thousands separator and two decimal points:

<code class="sql">SELECT TO_NUMBER('1,234.56', '9G999G999') FROM DUAL;</code>

Get a string value from the table and convert it to a number:

<code class="sql">SELECT TO_NUMBER(column_name) FROM table_name;</code>

Return type :

TO_NUMBER function returns a numeric value of NUMBER data type. If the conversion fails, it returns NULL.

Note:

  • If the string contains non-numeric characters, the conversion will fail.
  • The conversion will also fail if the format specified by format_mask does not match the number format in the string.
  • TO_NUMBER function can be used to convert a string represented in scientific notation to a number.

The above is the detailed content of Tonumber usage in oracle. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn