sql - Oracle LIKE operator with DECODE
问题描述
I am new to learning oracle and I am having some problems in understanding the syntax.
INSERT INTO TEMP_BILL_PAY_LWDAY_PL
WITH tmp_acc AS (
SELECT ac_id,ac_currency,ac_category,ac_co_code
FROM account
WHERE ac_co_code LIKE decode(Currency,'','%','ALL','%',Currency) AND ac_category = '9986'
)
This is the oracle pl/sql statement, could anybody please tell me what this line means.
WHERE ac_co_code LIKE decode(Currency,'','%','ALL','%',Currency)
I dont understand what decode means here with LIKE. I would really appreciate some help.
解决方案
It's producing a search pattern on the fly. The logic uses DECODE()
to decide:
If the value
Currency
is an empty VARCHAR ('') then use%
as the pattern for theLIKE
. The condition will be equivalent to:WHERE ac_co_code LIKE '%'
Else, if the value
Currency
is'ALL'
then use%
as the pattern for theLIKE
. The condition will be equivalent to:WHERE ac_co_code LIKE '%'
Else use the value of
Currency
as the pattern for theLIKE
. The condition will be equivalent to:WHERE ac_co_code LIKE Currency
See Oracle Online Docs for details.
推荐阅读
- reactjs - 我想在反应 js 中创建检查嵌套数据的复选框
- ruby - Ruby 中是否有一种优雅的方式来过滤散列数组的散列?
- python - df.to_latex() 的格式
- r - 使用 {gtsummary} 显示survey.design 对象的置信区间?
- docker - Traefik 可以在不安装 docker.socket 的情况下运行吗
- python-2.7 - 如何独立运行由gnu-radio伴侣生成的python文件(.py)(没有GRC GUI)?
- c++ - 从 C++ 调用 GNU Octave 时出现编译错误
- php - PHP:如何发送在同一服务器中找到多个附件的电子邮件
- mysql - SQL MATCH 忽略 WELCOME 这个词
- java - 从控制器创建和下载 PPTX 文件