oracle sql:如何在同一时间重命名2列

时间:2017-10-11 13:28:11

标签: oracle

SELECT last_name,salary,department_id FROM HR.EMPLOYEES 
WHERE salary IN('17000','9000') AND DEPARTMENT_ID IN('60','90');
Alter table HR.EMPLOYEES rename column last_name to Employee AND
Alter table HR.EMPLOYEES rename column salary to "Monthly Salary";
  

我需要将“last_name”重命名为“Employee”,将“salary”重命名为“Monthly Salary”

     

oracle的消息:SQL命令未正确结束

2 个答案:

答案 0 :(得分:1)

我会这样做

Alter table HR.EMPLOYEES rename column last_name to Employee ;
Alter table HR.EMPLOYEES rename column salary to "Monthly Salary";

我会摆脱' AND'并使用&#39 ;;'

完成命令

答案 1 :(得分:0)

您可能只想在查询中使用AS来指定别名:

SELECT last_name AS Employee,
       salary    AS "Monthly Salary",
       department_id
FROM   HR.EMPLOYEES 
WHERE  salary IN('17000','9000')
AND    DEPARTMENT_ID IN('60','90');

但是,您可以单独rename each column

Alter table HR.EMPLOYEES rename column last_name to Employee;
Alter table HR.EMPLOYEES rename column salary to "Monthly Salary";

(但您应该避免使用区分大小写的列名称 - 否则您必须在每个语句中使用双引号列名称和确切的大小写。)