问题
I have a Classes table which is as follows:
Classes(classid, dept_code, course#, sect#, year, semester, limit, class_size, room, TA_B#)
The qeustion is: Find the classid, dept_code and course# of each undergraduate class (i.e., course# < 500) that was offered in Spring 2017. For each such class, also list the number of seats available (computed by limit – class_size) under the header “seats_available”.
I tried this simple approach:
select classes.classid, classes.dept_code, classes.course#,
classes.limit-classes.class_size as'seats_available'
from classes
where limit>class_size and year='2017' and semester='Spring'and course# < 500;
0 But I am getting an error:
ERROR at line 1:
ORA-00923: FROM keyword not found where expected
What am I missing? This error will go if I remove this code of line:classes.limit-classes.class_size as'seats_available'
I am using Oracle database
回答1:
In the SQL standard identifiers need to be enclosed in double quotes ("). And the Oracle database complies with the standard there.
Single quotes (') are for character constants e.g. as you did in semester='Spring', they can not be used for identifiers like column names, table names or a column alias.
So you need to use:
classes.limit-classes.class_size as "seats_available"
You don't actually need the double quotes though, as your identifier does not contain any invalid characters, so
classes.limit-classes.class_size as seats_available
will work just as well
Unrelated, but: numbers should not be enclosed in single quotes 2017 is a number constant, '2017' is a string constant. So you should use where year = 2017 instead
来源:https://stackoverflow.com/questions/53003063/creating-a-new-attribute-in-oracle-database-from-two-other-attributes