oracle – PL SQL – 将数值转换为varchar(百分比)

前端之家收集整理的这篇文章主要介绍了oracle – PL SQL – 将数值转换为varchar(百分比)前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我有一个查询,它使用两个子查询输出(R1,R2)来划分它们:

select a.R1/b.R2*100.0 as Result
from
(query1) a,(query2) b

除法输出是(十进制)数字以及R1,R2输出.

我想在结果中添加’%’符号(即10,75%),但使用类似下面的解决方案,会返回错误01722 =无效的数字

select cast(cast(a.R1/b.R2*100.0 as decimal(10,2)) as varchar(10)) + '%' as Result
from
(query1) a,(query2) b

解决方法

欢迎!

sql-Pl / sql并置运算符替换加法运算符”|||’.

我们不能直接在数字格式模型中使用字符文字,例如在日期时间转换中.

SQL Concatenation operator

PL/SQL Concatenation operator

Number format models

例子:

select cast(round(10.75,2) as varchar(10)) || '%' as result
from   dual

select to_char(round(1234567890.29,2),'9G999G999G999D99' ) || '%' as result
from   dual

PS.
路线总是一样的:

How to ask

All the “oracles” are here:

猜你在找的Oracle相关文章