Oracle:使用强制多重集

时间:2015-08-30 08:22:53

标签: oracle oracle10g multiset

我有以下查询单独工作:

SELECT COUNT(u.id) FROM users u);
SELECT COUNT(s.id) FROM servers s);

我想在同一个查询中使用它们,所以我创建了这个:

SELECT CAST( MULTISET( SELECT count(u.id) FROM users u)
             AS NUMBER) AS nr_users,
       CAST( MULTISET( SELECT count(s.id) FROM servers s)
             AS NUMBER) AS nr_servers
FROM dual;

它返回错误:

ORA-00932: inconsistent datatypes: expected NUMBER got -00932.

count()会返回一个数字,我将multiset指定为数字,为什么它会给我这个错误?

1 个答案:

答案 0 :(得分:1)

子查询不返回集合类型,而是返回标量,只需使用

SELECT
    (SELECT count(u.id) FROM users u) AS nr_users,
    (SELECT count(s.id) FROM servers s) AS nr_servers
FROM dual;