我有 EMP 表它的列按照 Oracle 中的 Scott。我想在一个名为“语句”的列中显示所有列,如下所示。
前福特是一名分析师,他的经理是琼斯,部门研究部门的薪水为 3000
金是总统,他的经理没有部门会计的薪水 5000
尝试这样的事情:
SELECT emp.ename || ' IS A ' || emp.job || ' AND HIS MANAGER IS ' || mgr.ename || ' HAVING SALARY ' || TO_CHAR(emp.sal) || ' FROM DEPARTMENT ' || dept.dname
FROM emp
INNER JOIN emp AS mgr ON emp.mgr = mgr.empno
INNER JOIN dept ON dept.deptno = emp.deptno
您可以使用管道组合字符串:
SELECT 'COLUMN1' || ' ' || 'COLUMN2'
FROM DUAL
编辑:
使用可空管理器的实际查询进行更新:
SELECT emp.ename || ' IS A ' || emp.job || ' AND HIS MANAGER IS ' || NVL(mgr.ename, 'NULL') || ' HAVING SALARY ' || TO_CHAR(emp.sal) || ' FROM DEPARTMENT ' || dept.dname
FROM emp
LEFT JOIN emp AS mgr ON emp.mgr = mgr.empno
INNER JOIN dept ON dept.deptno = emp.deptno
select x.ENAME||' is a ' || x.JOB||' and his manager is '||y.ENAME||' having salary '||x.sal||' from department '||d.DNAME
FROM EMP x, EMP y, dept d
where x.MGR = y.EMPNO(+)
and x.DEPTNO = d.DEPTNO