在Oracle中把标量子查询转换为复合子查询

以下来自cookbook 14.10

create type generic_obj
    as object (
    val1 varchar2(10),
    val2 varchar2(10),
    val3 date
 );

 select x.deptno,
        x.ename,
        x.multival.val1 dname,
        x.multival.val2 loc,
        x.multival.val3 today
  from (
select e.deptno,
       e.ename,
       e.sal,
       (select generic_obj(d.dname,d.loc,sysdate+1)
          from dept d
         where e.deptno=d.deptno) multival
  from emp e
       ) x


如果不用type,则需要三个标量来实现

SELECT x.deptno,
       x.ename,
       (SELECT dept.dname FROM dept WHERE dept.deptno = x.deptno) dname,
       (SELECT dept.loc FROM dept WHERE dept.deptno = x.deptno) loc,
       (SELECT SYSDATE + 1 FROM dept WHERE dept.deptno = x.deptno) today
  FROM emp x


你可能感兴趣的:(在Oracle中把标量子查询转换为复合子查询)