这是一个在Transact-sql
中完美运行的SQL语句SELECT a.Account_ID, a.First_Name, a.Last_Name, m.number
FROM Account a,
(SELECT R_Account_ID, COUNT(Notification_ID) AS number
FROM Rcv_Send_Event_Notf
GROUP BY R_Account_ID) m
WHERE a.Account_ID = m.R_Account_ID
但它不在Oracle中。它在大多数select语句中抱怨m.number
。我相信也是因为第3行的AS number
。
user.table.column,table.column或列规范无效......
Oracle中的列别名有不同的方法吗?
感谢您的帮助
答案 0 :(得分:5)
Number
是Oracle中的关键字,因此如果不使用双引号,则无法将其用作别名。大多数人会建议不要将它用作别名,句号。
> select d.number from (select sysdate as number from dual) d
Error starting at line 3 in command:
select d.number from (select sysdate as number from dual) d
Error at Command Line:3 Column:9
Error report:
SQL Error: ORA-01747: invalid user.table.column, table.column, or column specification
01747. 00000 - "invalid user.table.column, table.column, or column specification"
> select d.number from (select sysdate as "number" from dual) d
Error starting at line 2 in command:
select d.number from (select sysdate as "number" from dual) d
Error at Command Line:2 Column:9
Error report:
SQL Error: ORA-01747: invalid user.table.column, table.column, or column specification
01747. 00000 - "invalid user.table.column, table.column, or column specification"
> select d."number" from (select sysdate as "number" from dual) d
number
-------------------------
07-MAY-12 12:32:28 PM
答案 1 :(得分:1)
如果我没有错过任何内容,你可以使用
select a.account_ID, a.First_Name, a.Last_Name, count(*)
from Account a
inner join RCV_Send_Event_Notf m on a.Account_Id = m.R_Account_Id
Group by a.account_Id, a.First_Name, a.Last_Name;
答案 2 :(得分:1)
Oracle可能不喜欢名称“number”,因为它是一个关键字。我“简化”了查询并重命名为“数字”,它似乎正常工作
SELECT m.number_col
FROM dual a,
(SELECT 123 AS number_col
FROM dual ) m
您还可以使用WITH子句:
WITH m AS
(SELECT sysdate as number_col
FROM dual )
SELECT m.number_col
FROM dual a, m