未在预期位置找到 FROM 关键字(Oracle SQL)

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/22753519/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-19 02:18:17  来源:igfitidea点击:

FROM keyword not found where expected (Oracle SQL)

sqloracle

提问by Meta

I am currently working on some select queries and am getting the error FROM keyword not found where expectedin my last two queries, and I can;t for the life of me figure out what the problem is...

我目前正在处理一些选择查询,并且FROM keyword not found where expected在我的最后两个查询中遇到了错误,而且我一生都无法弄清楚问题是什么......

Here are my queries

这是我的疑问

SELECT Title, PubID AS 'Publisher ID', PubDate AS 'Publish Date' 
FROM Books WHERE PubID = 4 OR PubDate > '01-Jan-01' 
ORDER BY PubID ASC;

SELECT Title, (((Retail-Cost)/Cost) * 100) AS 'Markup %' 
FROM Books;

I am not sure if my math is correct in this one (retail - cost / cost * 100 is the goal).

我不确定我的数学是否正确(retail - cost / cost * 100 is the goal)

I have been trying for probably 45 minutes on the first query before giving up and doing the last one, to only get the same error on that one.

在放弃并执行最后一个查询之前,我一直在第一个查询上尝试了大约 45 分钟,但只在该查询上出现相同的错误。

回答by Justin Cave

Single quotes are used to surround string literals. Double quotes are used to surround identifiers. Column aliases are identifiers so you'd want to use double quotes

单引号用于包围字符串文字。双引号用于将标识符括起来。列别名是标识符,因此您需要使用双引号

SELECT Title, 
       PubID AS "Publisher ID", 
       PubDate AS "Publish Date" 
  FROM Books 
 WHERE PubID = 4 
    OR PubDate > '01-Jan-01' 
 ORDER BY PubID ASC;