在写一个8张表一起union all 的SQL时,遇到了ORA-01789:query block has incorrect number of result columns
顾名思义,查询块的列数目不相等。
下面的SQL,查询时就会报ORA-01789错误
select empno, ename, job, sal from emp t where t.deptno = 20
union
select empno, ename, sal from emp t where t.deptno = 30
补上第二个块的列,补齐了就可以正常查询了。
select empno, ename, job, sal
from emp t
where t.deptno = 20
union
select empno, ename, 'job', sal
from emp t
where t.deptno = 30