Home > Database > Oracle > body text

What is the function that converts Oracle to number?

WBOY
Release: 2022-05-24 16:42:02
Original
7280 people have browsed it

oracle中转为数字的函数是“to_number”;该函数可将按一定格式编排过的字符串变回数值型的格式,字符串必须符合数值类型格式,若不符合则会出现错误提示,语法为“to_number(varchar2 or char,'格式')”。

What is the function that converts Oracle to number?

本教程操作环境:Windows10系统、Oracle 11g版、Dell G3电脑。

oracle转为数字的函数是什么

在oracle中,可以使用to_number()函数来将数据转为数字类型,该函数可以将字符串转换为数值型的格式,语法“to_number(varchar2 or char,'格式')”。

to_number()函数是oracle中常用的类型转换函数之一,是将一些处理过的按一定格式编排过的字符串变回数值型的格式。

1、to_number()函数可以将char或varchar2类型的string转换为一个number类型的数值;

2、需要注意的是,被转换的字符串必须符合数值类型格式,如果被转换的字符串不符合数值型格式,Oracle将抛出错误提示;

3、to_number和to_char恰好是两个相反的函数; 

示例如下:

What is the function that converts Oracle to number?

结果为:123.12

(1)to_number(varchar2 or char,'格式')

select to_number('000012134') from dual;  
select to_number('88877') from dual;
Copy after login

(2)如果数字在格式范围内的话,就是正确的,否则就是错误的;如:

select to_number('$12345.678', '$999999.99') from dual;  
select to_number('$12345.678', '$999999.999') from dual;
Copy after login

(3)可以用来实现进制转换;16进制转换为10进制:

select to_number('19f','xxx') from dual;  
select to_number('f','xx') from dual;
Copy after login

推荐教程:《Oracle视频教程

The above is the detailed content of What is the function that converts Oracle to number?. 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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template