在Oracle SQL中乘以列值

发布于 2025-01-22 22:27:08 字数 583 浏览 2 评论 0原文

我有以下查询:

SELECT RTRIM(TO_CHAR('dst.' || per_growth,
                     'FM9G999G999G999G999G990D99999999999',
                     ' NLS_NUMERIC_CHARACTERS = '',.'' '),
             ',')
  FROM dst__d_data dst;

我已经串联 per_growth 列标记, dst。

现在,我想要的是 'dst。 || per_growth * 0.01 。但是,这是上升错误消息:

ORA-01722 :无效号码

在这种情况下如何执行乘法?

I have following query:

SELECT RTRIM(TO_CHAR('dst.' || per_growth,
                     'FM9G999G999G999G999G990D99999999999',
                     ' NLS_NUMERIC_CHARACTERS = '',.'' '),
             ',')
  FROM dst__d_data dst;

I have concatenated per_growth column label with the dst.

Now, what I want is 'dst.' || per_growth * 0.01. However, it is rising error message:

ORA-01722: invalid number

How can I carry out multiplication in this scenario?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

计㈡愣 2025-01-29 22:27:08

您现有的查询将引起相同的错误。您不能首先连接,然后将应用于_char; to_char期望一个数字,而不是字符串。首先将数字转换为字符串,然后将condenate 'dst。'转换为to_char的结果。

修复第一个错误(即使对于现有查询)后,参数中的0.01乘以to_char不应导致任何新问题。

Your existing query will raise the same error. You can't concatenate first, and then apply TO_CHAR; TO_CHAR expects a number, not a string. First convert the number to string, and then concatenate 'dst.' to the result of TO_CHAR.

After you fix this first mistake (even for your existing query), multiplying by 0.01 in the argument to TO_CHAR should not cause any kind of new problem.

够钟 2025-01-29 22:27:08

您可以使用

SELECT 'dst.'||.01 * TO_NUMBER( per_growth, 
                               'FM9G999G999G999G999G990D99999999999', 
                               'NLS_NUMERIC_CHARACTERS = '',.'' ')
  FROM dst__d_data;

在完成使用 '',。'''' 模式的数值转换后,

前缀一些字符串的内容(因为数据似乎具有逗号作为十进制的分离器)和乘法操作< kbd>

You can use

SELECT 'dst.'||.01 * TO_NUMBER( per_growth, 
                               'FM9G999G999G999G999G990D99999999999', 
                               'NLS_NUMERIC_CHARACTERS = '',.'' ')
  FROM dst__d_data;

prefix some string stuff after finishing the numerical conversion with '',.'' pattern(as the data seems to have comma as decimal seperator) and multiplication operation

Demo

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文