gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-05 00:03:26 25 4
gpt4 key购买 nike

我有一个查询,它使用两个子查询的输出(R1,R2)来划分它们:

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

除法器的输出是一个(十进制)数以及 R1、R2 的输出。

我想在结果中添加“%”符号(即 10,75%),但使用如下解决方案,返回错误 01722=invalid number
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 连接运算符:' || '。

我们 不能 直接使用字 rune 字 数字格式模型 中,就像在日期时间转换中一样。

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

附注。
路线总是一样的:

How to ask

All the "oracles" are here:

关于oracle - PL SQL - 将数值转换为 varchar(百分比),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6923610/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com