编写查询所有学生的SQL语句及Student1表查询报错求助
Hey there! Let's break down your questions and fix that error step by step.
To retrieve every record from your student table (assuming it's named Student1), the simplest query is:
SELECT * FROM Student1;
If you want to specify only certain columns (which is often better practice to avoid fetching unnecessary data), you can list them explicitly:
SELECT student_id, student_fname, student_lname, student_dob, student_email FROM Student1;
Just replace the column names with whatever applies to your actual table schema.
Let's start by looking at your problematic query:
select * from student1 where student_fname student_lname like '%a';
The ORA-00920 error happens because Oracle can't interpret what you mean by placing student_fname and student_lname directly next to each other—you're missing an operator to define their relationship.
I assume you're trying to do one of two common things here:
Option 1: Match against the combined first and last name
If you want to check if the full name (first + last, separated by a space) ends with 'a', use Oracle's string concatenation operator||:SELECT * FROM student1 WHERE (student_fname || ' ' || student_lname) LIKE '%a';The parentheses clarify the order of operations, and the space ensures the first and last names don't run together into a single unreadable string.
Option 2: Match against either the first name OR last name
If you want to find rows where either the first name ends with 'a' OR the last name ends with 'a', use theORoperator to separate the two conditions:SELECT * FROM student1 WHERE student_fname LIKE '%a' OR student_lname LIKE '%a';If you meant to find names that contain 'a' anywhere (not just the end), swap
%afor%a%.
That should resolve the error and get your query working as intended!
内容的提问来源于stack exchange,提问作者agam

