多表插页

时间:2014-01-23 09:25:54

标签: sql database oracle insert

请指导我哪里错了

    SQL> INSERT ALL
      2  WHEN SAL <= 950 THEN INTO scott.e VALUES (E.Empno, E.Ename, E.sal)
      3  WHEN SAL > 950 THEN INTO scott.j VALUES (J.Empno, J.Sal)
      4  SELECT Emp.Empno, Emp.Ename, Emp.Sal FROM scott.emp;
    WHEN SAL > 950 THEN INTO scott.j VALUES (J.Empno, J.Sal)
                                                      *
    ERROR at line 3:
    ORA-00904: "J"."SAL": invalid identifier


   SQL> DESC j
    Name                                                                    Null?           Type
    ----------------------------------------------------------------------- --------  ------------------------------------------------
    EMPNO                                                                            NUMBER(4)
    SAL                                                                              NUMBER(7,2)

请提供纠正代码的指南,因为我最好的代码是正确的,但仍然会产生错误。非常感谢。

2 个答案:

答案 0 :(得分:1)

试试这个,

INSERT ALL
     WHEN SAL <= 950 THEN 
          INTO scott.e VALUES (Empno, Ename, sal)
     WHEN SAL > 950 THEN 
          INTO scott.j VALUES (Empno, Sal)
     SELECT Empno, Ename, Sal FROM scott.emp;

答案 1 :(得分:0)

INSERT ALL
WHEN SAL <= 950 THEN INTO scott.e VALUES (t.Empno, t.Ename, t.sal)
WHEN SAL > 950 THEN INTO scott.j VALUES (t.Empno, t.Sal)
SELECT Emp.Empno, Emp.Ename, Emp.Sal 
FROM scott.emp t;

或只是

INSERT ALL
WHEN SAL <= 950 THEN INTO scott.e VALUES (Empno, Ename, sal)
WHEN SAL > 950 THEN INTO scott.j VALUES (Empno, Sal)
SELECT Emp.Empno, Emp.Ename, Emp.Sal 
FROM scott.emp ;