我有一个要求,当用户选择英语时,我必须执行此查询(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也会动态出现。如何在另一个解码函数中编写解码。
谢谢你事先的答复。
发布于 2022-09-15 13:57:37
我在代码中没有看到任何解码函数,但是如果您的语言id变量是v_lang,您可以编写:
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。这是类似的,但更容易阅读和更可移植。
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 ....https://stackoverflow.com/questions/73732067
复制相似问题