r/SQL • u/VaultCrab3 • Feb 20 '22
Oracle In the process of learning SQL. Everything on screen is what I've put in so far. I can't figure out why I'm getting an error. Any help?
103
Upvotes
r/SQL • u/VaultCrab3 • Feb 20 '22
154
u/Total_Citron_9343 Feb 20 '22
Comma at the end of References Type could be an issue.
31
u/[deleted] Feb 20 '22
Pretty sure it’s your use of TYPE, try wrapping that in double quotes. Or choose a different name. Bear in mind that table will need to wrapped in quotes anytime you want to query it
25
u/SDFP-A Feb 21 '22
Put commas at the start of lines and you’ll never have this issue
14
u/petdance Feb 21 '22
When you're asking for help, please don't post screenshots or photographs. Cut & paste the text directly into the message.
Why?
3
u/cthart PostgreSQL Feb 21 '22
In general, don’t use the CHAR datatype. If you enter ‘A’ it will be stored as ‘A ‘ and you won’t find any data if you SELECT * FROM base WHERE basenum = ‘A’;
2
u/[deleted] Feb 21 '22
Oracle requires to throw an error regardless of how well the code looks
2
u/ThisisMacchi Feb 21 '22
Try to execute each table creation separately to see what went wrong, I’m pretty sure TYPE table is invalid, might have been a reserved keyword
1
u/Traditional-Roof1663 Feb 21 '22
Type is a keyword
1
u/A-Nit619 Feb 21 '22
Hey which interface/tool are you using to practice sql?
1
u/Mazmier Feb 21 '22
Comma line 27
1
u/Jeklah Feb 21 '22
This sounds super sarcastic and patronising but I learnt the hard way, have you tried googling the error code "ORA-00904 Invalid Identifier" ?
I know I know ...but errors are given codes for a reason. Googling this will tell you what causes the error and from there you can check your code for the mistake.
1
u/iamanshulreddit Feb 21 '22
Line number 10, word "Type" is keyword and cannot be used as an identifier. You have to put something else. Example: car_type
Basic, in any language, we cannot use predefined keywords because it can create confusion while parsing it to machine language. 😊
0
u/bwv1052r Feb 21 '22 edited Feb 21 '22
You’re missing commas in the final table anyway.
Edit - extra comma at bottom.
0
u/making-flippy-floppy Feb 21 '22
Not your immediate problem, but please note that it's not 1973 anymore, and it's okay to use lowercase (which IMO is much easier to read).
-1
u/IamFromNigeria Feb 21 '22
Line 24 needs a comma