是否可以从子查询中获取多个值? [英] Is it possible to get multiple values from a subquery?
问题描述
有什么方法可以让子查询在oracle db中返回多个列? (我知道此特定的sql会导致错误,但它总结了我想要的内容)
Is there any way to have a subquery return multiple columns in oracle db? (I know this specific sql will result in an error, but it sums up what I want pretty well)
select
a.x,
( select b.y, b.z from b where b.v = a.v),
from a
我想要这样的结果:
a.x | b.y | b.z
---------------
1 | 2 | 3
我知道可以通过联接解决此问题,但这不是我要的.
I know it is possible to solve this problem through joins, but that is not what I am asking for.
我的问题很简单,是否有办法从子查询中获取两个或多个值?也许使用双重解决方法?这样就没有实际的联接,但是每行都有一个新的子查询吗?
My Question is simply if there is any way, to get two or more values out of a subquery? Maybe some workaround using dual? So that there is NO actual join, but a new subquery for each row?
这是一个基本问题.我知道,您可以使用join解决所有这些问题.您根本不需要这样的子查询(甚至对于一列也不需要).但是他们在那里.那么我可以那样使用它们吗?还是根本不可能?
This is a principle question. You can solve all these problems using join, I know. You do not need subqueries like this at all (not even for one column). But they are there. So can I use them in that way or is it simply impossible?
推荐答案
Select子句中的子查询(如您所述)也称为标量子查询,这意味着它是一种表达形式.这意味着它只能返回一个值.
A Subquery in the Select clause, as in your case, is also known as a Scalar Subquery, which means that it's a form of expression. Meaning that it can only return one value.
恐怕您不能从单个Scalar子查询中返回多个列,不.
I'm afraid you can't return multiple columns from a single Scalar Subquery, no.
有关Oracle Scalar子查询的更多信息:
Here's more about Oracle Scalar Subqueries:
http://docs.oracle.com/cd/B19306_01/server .102/b14200/expressions010.htm#i1033549
这篇关于是否可以从子查询中获取多个值?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!