FROM关键字未找到预期的ERROR

时间:2012-03-30 01:24:58

标签: oracle oracle11g

我正在尝试为家庭作业编写Oracle查询。分配是编写一个查询以返回所有员工的employee_id,job_id,hire_date和department_id,并编写第二个查询,列出job_hist表中的employee_id,job_id,start_date和department_id,并将结果合并为一个单独的输出。确保在输出中禁止重复。

我的代码:

SELECT employee_id AS "Employee ID", job_id AS "Job Id", TO_CHAR(NULL) hire_date "Hire     Date", department_id AS "Department Id",
FROM employees
UNION
SELECT employee_id AS "Employee Id", job_id AS "Job Id", TO_CHAR(NULL) start_date "Start     Date",department_id AS "Department Id", 
FROM job_history;

我收到错误:

ORA-00923: FROM keyword not found where expected

从书中我可以看出,序列看起来正确。任何帮助都会很棒!

删除逗号后的代码:

SELECT employee_id AS "Employee ID", job_id AS "Job Id", TO_CHAR(NULL) hire_date "Hire     Date", department_id AS "Department Id"
FROM employees
UNION
SELECT employee_id AS "Employee Id", job_id AS "Job Id", TO_CHAR(NULL) start_date "Start     Date",department_id AS "Department Id" 
FROM job_history;

4 个答案:

答案 0 :(得分:3)

在FROM关键字(UNION Syntax)之前删除逗号。

SELECT employee_id AS "Employee ID", 
       job_id AS "Job Id", TO_CHAR(NULL) hire_date "Hire     Date", department_id AS "Department Id"
FROM employees ....

答案 1 :(得分:1)

SELECT employee_id AS "Employee Id", job_id AS "Job Id", TO_CHAR(hire_date,'yyyy-mm-dd') AS "Some date", department_id AS "Department Id"
FROM employees
UNION
SELECT employee_id AS "Employee Id", job_id AS "Job Id", TO_CHAR(start_date,'yyyy-mm-dd') AS "Some date",department_id AS "Department Id"
FROM job_history;

这有效吗?

答案 2 :(得分:-1)

add_pidRun = ("INSERT INTO pidRun "
              "(pidSetPoint, pidMeasure, pidError, integrator, derivator)"
              "VALUES (%s, %s, %s, %s, %s")
data_pidRun = (pidControl.getPoint(), centSpeed, errSpeed, 0.0, 0.0)
cursor.execute(add_pidRun, data_pidRun)

答案 3 :(得分:-1)

SELECT employee_id,job_id,hire_date,department_id 来自员工 UNION ALL SELECT employee_id,job_id,start_date,department_id 来自job_history ORDER BY employee_id