I’m trying to create a view in an Oracle database, but keep getting an ORA-00907 error (missing right parenthesis). My SQL is as below:
CREATE VIEW my_view AS ( SELECT metadata.ID,metadata.Field1,metadata.Field2,metadata.Field3,metadata.Field4,attribute1.StrValue AS Attr1, attribute2.StrValue AS Attr2 FROM metadata,data AS attribute1,data AS attribute2 WHERE ( metadata.Type = 'TYPE1' ) AND ( metadata.ID = attribute1.ID AND attribute1.name = 'attr1' ) AND ( metadata.ID = attribute2.ID AND attribute2.name = 'attr2' ) )
Where the table metadata defines entities, and data defines attributes for those entities.
This works fine in MS SQL and MySQL, but I keep getting the above error from Oracle.
Not been working with Oracle too long, so I don’t know a whole lot about its quirks.
You need to remove the AS in the FROM clause. Oracle allows the optional AS for aliasing column names but not for providing aliases
Depending on the tool you’re using, it may be useful to know that SQL*Plus will show you exactly where a syntax error is occurring– the snippet below shows it objecting to the AS keyword.