Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/sql/85.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
oracle SQL查询中的If-else_Sql_Oracle10g - Fatal编程技术网

oracle SQL查询中的If-else

oracle SQL查询中的If-else,sql,oracle10g,Sql,Oracle10g,我有一个场景,我可以得到两种类型的输入,但如果您包含输入1或输入2或两者,结果是相同的。以下是我目前的查询。此查询从电路和电话输入的数据库中检索客户id select customer.customer_id from circuits join customer on customer.cust_order = circuits.cust_order where circuitId= 'somecircuit' union select customer.customer_id from cu

我有一个场景,我可以得到两种类型的输入,但如果您包含输入1或输入2或两者,结果是相同的。以下是我目前的查询。此查询从
电路
电话
输入的数据库中检索
客户id

select customer.customer_id from circuits join customer on customer.cust_order = circuits.cust_order where circuitId= 'somecircuit'
union
select customer.customer_id from customer join telephone on telephone.number = customer.number where telephone = '34234242'
现在,如果输入电话不可用,我需要第二个查询不执行,反之亦然。在查询本身中是否有这样做的方法

我不打算为此创建PL/SQL块,如果在SQL中没有办法做到这一点,我必须求助于Java,并针对每个场景使用两个不同的查询

这样行吗

select customer.customer_id
from circuits join customer on customer.cust_order = circuits.cust_order
where circuitId is not null
union
select customer.customer_id
from customer join telephone on telephone.number = customer.number
where telephone is not null

您可以在SQL查询中联接所有表,并让WHERE条件处理其余的表:

选择customer.customer\u id
从电路在customer.cust_订单上加入客户=电路.cust_订单
在电话上加入电话。号码=客户。号码
其中,circuitId='somecircuit'或telephone='34234242'


设置的电路id将检索客户的数据或电话号码。

如果电路id为空,它不会失败吗?如果电路输入为空,则我将发送空字符串,并且电路表将不匹配任何内容,并且连接条件将导致空结果。否,即使未提供电路ID,OR操作员也将帮助我们使用电话号码获取记录。