如何使用cocece函数用字符串替换零值?

发布于 2025-02-13 01:19:21 字数 294 浏览 0 评论 0原文

试图在选择语句中使用cocece函数将“无分配”放在零值。 这是代码:

SELECT ORDER_ID, ORDER_DATE,
coalesce (SALES_REP_ID,'NA') REP
FROM ORDERS```
[But having error "inconsistent datatype"]
How do I fix it?

[Data, in which sales_rep_id have null values which i want to change it to 'unassigned']

Trying to put 'unassigned' to the null values using coalesce function within the select statement.
Here is the code:

SELECT ORDER_ID, ORDER_DATE,
coalesce (SALES_REP_ID,'NA') REP
FROM ORDERS```
[But having error "inconsistent datatype"]
How do I fix it?

[Data, in which sales_rep_id have null values which i want to change it to 'unassigned']

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

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

发布评论

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

评论(2

黑凤梨 2025-02-20 01:19:24

正如错误所提到的那样,您正在混合数据类型。在cocece功能中,您需要先将sales_rep_id转换为varchar。

SELECT ORDER_ID, ORDER_DATE,
coalesce (to_char(SALES_REP_ID), 'NA') REP
FROM ORDERS

As the error mentions, you are mixing data types. Inside the coalesce function you need to convert sales_rep_id to a varchar first.

SELECT ORDER_ID, ORDER_DATE,
coalesce (to_char(SALES_REP_ID), 'NA') REP
FROM ORDERS
好菇凉咱不稀罕他 2025-02-20 01:19:24

您需要确保不混合数据类型

SELECT ORDER_ID, ORDER_DATE,
       case when SALES_REP_ID is null 
            then 'NA'
            else to_char(SALES_REP_ID)
       end REP
FROM ORDERS

You need to make sure you don't mix data types

SELECT ORDER_ID, ORDER_DATE,
       case when SALES_REP_ID is null 
            then 'NA'
            else to_char(SALES_REP_ID)
       end REP
FROM ORDERS
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文