您好我正在尝试使用以下内容创建视图:
CREATE OR REPLACE VIEW CONCERT_EVENTS1 AS
SELECT CONCERT.CONCERT_ID, EVENT.EVENT_ID, CONCERT.NAME, EVENT.DATE1 , CONCERT.DURATION,
CONCERT.COST AS TO_CHAR(COST, 'L9,999.99')
FROM EVENT
INNER JOIN CONCERT
ON CONCERT.CONCERT_ID = EVENT.CONCERT_ID;
以下是我收到的错误:
Error starting at line 1 in command:
CREATE OR REPLACE VIEW CONCERT_EVENTS1 AS
SELECT CONCERT.CONCERT_ID, EVENT.EVENT_ID, CONCERT.NAME, EVENT.DATE1 , CONCERT.DURATION,
CONCERT.COST AS TO_CHAR(COST, 'L9,999.99')
FROM EVENT
INNER JOIN CONCERT
ON CONCERT.CONCERT_ID = EVENT.CONCERT_ID
Error at Command Line:2 Column:113
Error report:
SQL Error: ORA-00923: FROM keyword not found where expected
00923. 00000 - "FROM keyword not found where expected"
*Cause:
*Action:
我的SQL有什么问题?
答案 0 :(得分:1)
AS语句不正确。 AS用于选择重命名列。所以CONCERT.COST作为CONCERT_COST会在您的视图中将列重命名为CONCERT_COST。如果要格式化列,则在as:
的左侧TO_CHAR(CONCERT.COST, 'L9,999.99') AS FORMATED_COST
如果您仍想重命名该列。
答案 1 :(得分:0)
您的" AS TO_CHAR(费用,' L9,999.99')"是不对的。 " As"声明用于对列进行别名,您不希望将列命名为" TO_CHAR(COST,' L9,999.99')"
我相信你想要的是:
CREATE OR REPLACE VIEW CONCERT_EVENTS1 AS
SELECT CONCERT.CONCERT_ID, EVENT.EVENT_ID, CONCERT.NAME, EVENT.DATE1 , CONCERT.DURATION,
TO_CHAR(CONCERT.COST, 'L9,999.99') as 'ALIAS_HERE'
FROM EVENT
INNER JOIN CONCERT
ON CONCERT.CONCERT_ID = EVENT.CONCERT_ID;
答案 2 :(得分:0)
此消息始终指示查询投影中的语法错误,即SELECT和FROM关键字之间的位:
ORA-00923: FROM keyword not found where expected
你仍然得到它,因为你已经消除了原始布鲁姆的建议修复。现在您有COST列的两个声明....
CONCERT.COST TO_CHAR(CONCERT.COST, 'L9,999.99') AS FORMATED_COST
语法要求我们在投影中的每一列之间加上逗号:
CREATE OR REPLACE VIEW CONCERT_EVENTS1 AS
SELECT CONCERT.CONCERT_ID
, EVENT.EVENT_ID
, CONCERT.NAME
, EVENT.DATE1
, CONCERT.DURATION
, CONCERT.COST
, TO_CHAR(CONCERT.COST, 'L9,999.99') AS FORMATED_COST
FROM EVENT INNER
JOIN CONCERT
ON CONCERT.CONCERT_ID = EVENT.CONCERT_ID
或者,如果您不想在视图中使用数字COST列,请将其删除。
我知道语法错误对初学者来说很难,但你真的需要学会用冷静的眼光看待自己的代码。每当你删掉一个逗号时,你都无法运行到SO。以适当的方式布置代码将有助于:更容易阅读的代码更易于调试。出于同样的原因,您应该避免将所有代码都放在大写字母中。