在SQL中为函数传递多个值

时间:2015-05-27 14:46:55

标签: sql oracle

下面是我试图实现的示例查询,其思路是,查询应返回3个查询提取的值,其中两个查询在WHERE子句中具有函数。

SELECT DISTINCT X FROM T1 WHERE T1.X= 8755 UNION
SELECT DISTINCT X FROM T1 WHERE ISDESCENDANT(T1,8755) UNION
SELECT DISTINCT X FROM T1 WHERE ISANCESTOR(T1,8755)

上面的查询工作正常但是,我想用另一个查询的输出替换静态值8755。像,

SELECT Y FROM T1 WHERE T1.Z='Some_Name';

例如,如果上述查询返回 4个值(8755,8766,8788,8799),则应执行以下查询。

SELECT DISTINCT X FROM T1 WHERE T1.X= 8755 UNION
SELECT DISTINCT X FROM T1 WHERE ISDESCENDANT(T1,8755) UNION
SELECT DISTINCT X FROM T1 WHERE ISANCESTOR(T1,8755)

SELECT DISTINCT X FROM T1 WHERE T1.X= 8766 UNION
SELECT DISTINCT X FROM T1 WHERE ISDESCENDANT(T1,8766) UNION
SELECT DISTINCT X FROM T1 WHERE ISANCESTOR(T1,8766)

SELECT DISTINCT X FROM T1 WHERE T1.X= 8788 UNION
SELECT DISTINCT X FROM T1 WHERE ISDESCENDANT(T1,8788) UNION
SELECT DISTINCT X FROM T1 WHERE ISANCESTOR(T1,8788)

SELECT DISTINCT X FROM T1 WHERE T1.X= 8799 UNION
SELECT DISTINCT X FROM T1 WHERE ISDESCENDANT(T1,8799) UNION
SELECT DISTINCT X FROM T1 WHERE ISANCESTOR(T1,8799)

有什么办法可以实现吗? 请帮我。

1 个答案:

答案 0 :(得分:0)

试试这个:

puts str.scan(/"(.*)"/)[0][0]
# ^This is the text I want to save.