【问题标题】:How to perform case in an oracle concat function?如何在 oracle concat 函数中执行大小写?
【发布时间】:2016-08-31 17:26:22
【问题描述】:

如何在 oracle concat 函数中执行大小写? 我想根据数字连接数字和字母。即,如果数字大于 1,则我必须附加 s,否则不附加。 我尝试了以下查询,但它不起作用。

  Select concat(count(*) , if count(*) > 1 then 's' else '') 
  from tablename 
  group by columnname;

【问题讨论】:

    标签: oracle select case concat


    【解决方案1】:

    在Oracle 中最好使用|| 进行连接,没有if 但有case 表达式。我将使用|| 展示解决方案,因为它是最佳实践,但如果您必须使用concat,您也可以这样做。此外,Oracle 会为您将数字转换为 VARCHAR2,但最好明确地编写您的转换。

    select to_char(count(*)) || case when count(*)  > 1 then 's' end from ....
    

    注意 - case 的默认值是 ''(与 Oracle 中的 NULL 相同),所以我不需要多写。

    【讨论】:

    • 选择to_char(count()) || case if count() > 1 then 'aa' end from careers group byoccupation * ERROR at line 1: ORA-00923: FROM keyword not found where expected
    • 可以复制粘贴吗? (因为简单地复制一行文本似乎太难了。)我刚刚告诉过你,Oracle 中没有if。你写了if,我写了when。你现在看到了吗?如果没有,只需复制和粘贴,以免抄写错误。
    猜你喜欢
    • 2013-08-26
    • 1970-01-01
    • 1970-01-01
    • 2015-09-26
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-08-10
    • 2022-01-24
    相关资源
    最近更新 更多