gpt4 book ai didi

sql - 如何在Oracle的where子句中使用IF THEN ELSE语句?

转载 作者:行者123 更新时间:2023-12-02 20:57:21 25 4
gpt4 key购买 nike

我很感兴趣的是如何在 Oracle 的 where 子句中使用 if-then-else 语句或任何控制结构。我想用作:

  • pcustomer_id IS NULL时,WHERE c.customer_id IS NULL
  • pcustomer_id IS NOT NULL时,则c.customer_id = pcustomer_id

我该怎么做?

SELECT *
FROM customer_inf c
WHERE
IF
pcustomer_id IS NULL THEN ( c.customer_id IS NULL )
ELSE (c.customer_id = pcustomer_id) END IF;

最佳答案

您需要捆绑它们

where (
(pcustomer_id is null
and c.customer_id is null)
or
(pcustomer_id is not null
and c.customer_id = pcustomer_id)
)

关于sql - 如何在Oracle的where子句中使用IF THEN ELSE语句?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39788415/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com