首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >解码函数oracle中的解码函数

解码函数oracle中的解码函数
EN

Stack Overflow用户
提问于 2022-09-15 13:31:33
回答 1查看 25关注 0票数 0

我有一个要求,当用户选择英语时,我必须执行此查询(SUBSTR(sct.state_customer_type,INSTR(sct.state_customer_type,'(')+1,INSTR(sct.state_customer_type,')')-INSTR(sct.state_customer_type,'(')-1)),如果选择该语言为西班牙语,则执行此查询(SUBSTR(sct.state_customer_type,1,INSTR(sct.state_customer_type,'(')-1))。语言id也会动态出现。如何在另一个解码函数中编写解码。

谢谢你事先的答复。

EN

回答 1

Stack Overflow用户

发布于 2022-09-15 13:57:37

我在代码中没有看到任何解码函数,但是如果您的语言id变量是v_lang,您可以编写:

代码语言:javascript
复制
select decode(v_lang,
    'English', 
        (SUBSTR(sct.state_customer_type,INSTR(sct.state_customer_type,'(')+1,INSTR(sct.state_customer_type,')')-INSTR(sct.state_customer_type,'(')-1)),
    'Spanish',
        (SUBSTR(sct.state_customer_type,1,INSTR(sct.state_customer_type,'(')-1)),
    null -- if v_lang is something else
    )
from ....
where ....

然而,现在我们建议使用ANSI CASE语句而不是decode。这是类似的,但更容易阅读和更可移植。

代码语言:javascript
复制
select CASE v_lang
    WHEN 'English'
    THEN (SUBSTR(sct.state_customer_type,INSTR(sct.state_customer_type,'(')+1,INSTR(sct.state_customer_type,')')-INSTR(sct.state_customer_type,'(')-1))
    WHEN 'Spanish'
    THEN (SUBSTR(sct.state_customer_type,1,INSTR(sct.state_customer_type,'(')-1))
    ELSE null -- if v_lang is something else
    END
from ....
where ....
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/73732067

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档