不知何故,Oracle 11g认为我的视图创建代码中有重复的列名:
DROP VIEW users_view;
CREATE VIEW users_view AS
SELECT * FROM users u
INNER JOIN states s
ON u.state_id = s.state_id
INNER JOIN accounts a
ON u.account_id = a.account_id
;
/
我在SQLDeveloper中运行它并收到此错误消息:
Error starting at line : 109 in command -
CREATE VIEW users_view AS
SELECT * FROM users u
INNER JOIN states s
ON u.state_id = s.state_id
INNER JOIN accounts a
ON u.account_id = a.account_id
Error report -
ORA-00957: duplicate column name
00957. 00000 - "duplicate column name"
*Cause:
*Action:
我可以解决这个问题吗?
答案 0 :(得分:2)
显然,此查询有重复的列:
SELECT *
FROM users u INNER JOIN
states s
ON u.state_id = s.state_id INNER JOIN
accounts a
ON u.account_id = a.account_id
重复项包括u.state_id
,s.state_id
,u.account_id
和a.account_id
- 表别名将被忽略。
我建议您列出每个表中所需的所有列。但是,如果重复项只是JOIN
个键,则会有一个快捷方式 - 您可以使用USING
代替ON
:
SELECT *
FROM users u INNER JOIN
states s
USING (state_id) INNER JOIN
accounts a
USING (account_id)