Home> Database> Oracle> body text

Tonumber usage in oracle

下次还敢
Release: 2024-05-08 19:18:17
Original
531 people have browsed it

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:

TO_NUMBER(string, [format_mask])
Copy after login

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:

SELECT TO_NUMBER('123.45') FROM DUAL;
Copy after login

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

SELECT TO_NUMBER('1,234.56', '9G999G999') FROM DUAL;
Copy after login

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

SELECT TO_NUMBER(column_name) FROM table_name;
Copy after login

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!

Related labels:
source:php.cn
Statement of this Website
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
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!