Home> Database> Oracle> body text

How to convert string to number in oracle

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

Oracle provides multiple methods to convert strings to numbers: TO_NUMBER function: Convert strings to numeric types using the specified format model. NUMTOSTR function: Converts a string to a numeric type and back to a string. VAL function: directly converts a string to a numeric type without checking the format.

How to convert string to number in oracle

How to convert a string to a number

Convert a string to a number in Oracle

Oracle provides a variety of methods to convert strings to numbers:

1. TO_NUMBER function

TO_NUMBER function converts strings to numeric types . It has the following syntax:

TO_NUMBER(string, format_model)
Copy after login

Where:

  • string: The string to convert.
  • format_model(optional): Specifies the format model for string number format.

For example:

SELECT TO_NUMBER('12345') FROM dual;
Copy after login

Output:

12345
Copy after login
Copy after login
Copy after login

2. NUMTOSTR function

NUMTOSTR The function converts a string to a numeric type and converts the result to a string. It has the following syntax:

NUMTOSTR(string)
Copy after login

Where:

  • string: The string to convert.

For example:

SELECT NUMTOSTR('12345') FROM dual;
Copy after login

Output:

12345
Copy after login
Copy after login
Copy after login

3. VAL function

VAL The function converts a string to a numeric type, but unlike the TO_NUMBER function, it does not perform any format checking. It has the following syntax:

VAL(string)
Copy after login

Where:

  • string: The string to convert.

For example:

SELECT VAL('12345X') FROM dual;
Copy after login

Output:

12345
Copy after login
Copy after login
Copy after login

Note:VAL function for characters that contain non-numeric characters Strings may be unreliable. In this case, it is better to use the TO_NUMBER function.

The above is the detailed content of How to convert string to number 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!