CS405 – Database Programming with Oracle: Midterm Important MCQs (43 Solved Questions)
Computer Science • Read every solved MCQ with its verified answer key directly on this page. Free, no login required.
All 664 Midterm Packs · CS405 Course Page · CS405 Subjective Pack (24 Q&As)
-
Which section of a PL/SQL block contains the executable statements?
Topic: PL/SQL Block Structure & Basics
- DECLARE section
- BEGIN section ✓ Correct answer
- EXCEPTION section
- END section
-
Which sections of a PL/SQL block are optional?
Topic: PL/SQL Block Structure & Basics
- BEGIN and END
- DECLARE and BEGIN
- DECLARE and EXCEPTION ✓ Correct answer
- BEGIN and EXCEPTION
-
Which statement is used to print/display a message in PL/SQL?
Topic: PL/SQL Block Structure & Basics
- PRINT_LINE
- DBMS_OUTPUT.PUT_LINE ✓ Correct answer
- SHOW OUTPUT
- DISPLAY.MESSAGE
-
Which command is used to enable server output so that DBMS_OUTPUT messages are displayed?
Topic: PL/SQL Block Structure & Basics
- SET OUTPUT ON
- ENABLE SERVEROUTPUT
- SET SERVEROUTPUT ON ✓ Correct answer
- DBMS_OUTPUT ON
-
In PL/SQL, which operator is used to concatenate (join) strings in output statements?
Topic: PL/SQL Block Structure & Basics
- +
- &
- || ✓ Correct answer
- CONCAT
-
In PL/SQL, which operator is used to assign a value to a variable at the time of declaration (e.g. salary NUMBER := 5000)?
Topic: PL/SQL Block Structure & Basics
- =
- := ✓ Correct answer
- ->
- ==
-
What is the purpose of the IF-THEN-ELSE statement in PL/SQL?
Topic: Conditional Statements & Loops in PL/SQL
- Looping through records
- Conditional execution of statements ✓ Correct answer
- Handling exceptions
- Declaring variables
-
How is an IF-THEN-ELSE statement correctly ended in PL/SQL?
Topic: Conditional Statements & Loops in PL/SQL
- END;
- ENDIF;
- END IF; ✓ Correct answer
- CLOSE IF;
-
In the file's example, salary is 5000 and the condition is salary > 4000. What is printed?
Topic: Conditional Statements & Loops in PL/SQL
- Low Salary
- High Salary ✓ Correct answer
- 5000
- No output
-
Which function is used with IF-ELSE in the file's code to check whether a number is odd or even?
Topic: Conditional Statements & Loops in PL/SQL
- ROUND(number, 2)
- MOD(number, 2) ✓ Correct answer
- ABS(number, 2)
- POWER(number, 2)
-
MOD(15, 2) returns 1. According to the file's explanation, this means 15 is:
Topic: Conditional Statements & Loops in PL/SQL
- Even
- Odd ✓ Correct answer
- Prime
- Negative
-
Which loop structure is used in the file's code to print the multiplication table of 10 for the first 10 natural numbers?
Topic: Conditional Statements & Loops in PL/SQL
- WHILE i <= 10 LOOP
- FOR i IN 1..10 LOOP ✓ Correct answer
- LOOP UNTIL i = 10
- REPEAT i FROM 1 TO 10
-
The HAVING clause in SQL is used to filter:
Topic: SQL: GROUP BY, HAVING, ORDER BY & Group Functions
- Individual rows before grouping
- Groups of records created by the GROUP BY clause ✓ Correct answer
- Columns of a table
- Duplicate rows only
-
What is the difference between WHERE and HAVING clauses?
Topic: SQL: GROUP BY, HAVING, ORDER BY & Group Functions
- WHERE filters groups; HAVING filters rows
- WHERE filters individual rows; HAVING filters groups after aggregation ✓ Correct answer
- Both filter groups after aggregation
- WHERE is used only with GROUP BY
-
The GROUP BY clause is used to:
Topic: SQL: GROUP BY, HAVING, ORDER BY & Group Functions
- Sort the final result
- Filter individual rows
- Group rows based on a column ✓ Correct answer
- Join two tables
-
Group functions (such as SUM(), AVG(), COUNT()) perform operations on:
Topic: SQL: GROUP BY, HAVING, ORDER BY & Group Functions
- A single row
- Multiple rows ✓ Correct answer
- Table structure
- Column names
-
What does the query SELECT COUNT(*) FROM employees; return?
Topic: SQL: GROUP BY, HAVING, ORDER BY & Group Functions
- The average salary of employees
- The total number of employees ✓ Correct answer
- The number of departments
- The highest salary
-
In the file's example (GROUP BY deptno HAVING AVG(salary) > 50000), which departments are displayed?
Topic: SQL: GROUP BY, HAVING, ORDER BY & Group Functions
- All departments
- Departments whose total salary is greater than 50000
- Departments where average salary is greater than 50,000 ✓ Correct answer
- Departments having more than 50 employees
-
Which clause is used to sort the result of a query (e.g. faculty names in A-Z order)?
Topic: SQL: GROUP BY, HAVING, ORDER BY & Group Functions
- GROUP BY
- ORDER BY ✓ Correct answer
- HAVING
- WHERE
-
In the ORDER BY clause, ASC is:
Topic: SQL: GROUP BY, HAVING, ORDER BY & Group Functions
- Mandatory to write
- The default sorting order ✓ Correct answer
- Used for descending order
- Not allowed in Oracle
-
A Primary Key column in a table:
Topic: Keys & Constraints (Primary, Unique & Foreign Keys)
- Can contain NULL values
- Cannot contain NULL values and must be unique ✓ Correct answer
- Can contain duplicate values
- Is always of VARCHAR2 type
-
How many Primary Keys can a table have?
Topic: Keys & Constraints (Primary, Unique & Foreign Keys)
- Unlimited
- Two
- Only one ✓ Correct answer
- One per column
-
A Unique Key column:
Topic: Keys & Constraints (Primary, Unique & Foreign Keys)
- Cannot contain NULL values
- Can contain NULL values but values must be unique ✓ Correct answer
- Must be the first column of the table
- Cannot be combined with other constraints
-
How many Unique Keys can a table have?
Topic: Keys & Constraints (Primary, Unique & Foreign Keys)
- Only one
- Maximum two
- Multiple Unique Keys are allowed ✓ Correct answer
- None
-
A Foreign Key is a column (or set of columns) that:
Topic: Keys & Constraints (Primary, Unique & Foreign Keys)
- Uniquely identifies each row of its own table
- References the primary key of another table ✓ Correct answer
- Stores only numeric values
- Is used to sort records
-
The main purpose of a Foreign Key is to:
Topic: Keys & Constraints (Primary, Unique & Foreign Keys)
- Speed up queries
- Ensure referential integrity between tables ✓ Correct answer
- Encrypt table data
- Create a backup of the parent table
-
Foreign Keys help to prevent:
Topic: Keys & Constraints (Primary, Unique & Foreign Keys)
- Duplicate column names
- Orphan records (child records without a corresponding parent) ✓ Correct answer
- NULL values in the parent table
- Long table names
-
In the file's example, class_id in the Students table references class_id in the Classes table. Here class_id in Students is:
Topic: Keys & Constraints (Primary, Unique & Foreign Keys)
- A Primary Key
- A Unique Key
- A Foreign Key ✓ Correct answer
- An index
-
Which statement is used in the file's example to add a Foreign Key constraint to an existing table?
Topic: Keys & Constraints (Primary, Unique & Foreign Keys)
- CREATE FOREIGN KEY
- ALTER TABLE Students ADD CONSTRAINT fk_class FOREIGN KEY (class_id) REFERENCES Classes(class_id) ✓ Correct answer
- UPDATE Students SET FOREIGN KEY (class_id)
- INSERT CONSTRAINT FOREIGN KEY
-
The ROLLBACK command is used to:
Topic: Transactions, SELECT INTO & Common SQL Errors
- Save all changes permanently
- Undo uncommitted transactions ✓ Correct answer
- Delete a table
- Create a new transaction
-
ROLLBACK undoes all changes made:
Topic: Transactions, SELECT INTO & Common SQL Errors
- Since the database was created
- After the last COMMIT ✓ Correct answer
- Before the last COMMIT
- Only in the current row
-
If COMMIT is not executed, then ROLLBACK will:
Topic: Transactions, SELECT INTO & Common SQL Errors
- Have no effect
- Undo the changes ✓ Correct answer
- Save the changes
- Raise an error
-
In the file's ROLLBACK code, which function is used to display the number of rows before and after the rollback?
Topic: Transactions, SELECT INTO & Common SQL Errors
- SUM(*)
- COUNT(*) ✓ Correct answer
- TOTAL(*)
- ROWS(*)
-
In PL/SQL, SELECT ... INTO is used to:
Topic: Transactions, SELECT INTO & Common SQL Errors
- Insert multiple rows into a table
- Fetch data from a table into variables ✓ Correct answer
- Create a new table
- Sort the fetched data
-
If a SELECT INTO query returns no row, which error/exception occurs?
Topic: Transactions, SELECT INTO & Common SQL Errors
- TOO_MANY_ROWS
- NO_DATA_FOUND ✓ Correct answer
- INVALID_CURSOR
- VALUE_ERROR
-
If a SELECT INTO query returns more than one row, which error/exception occurs?
Topic: Transactions, SELECT INTO & Common SQL Errors
- NO_DATA_FOUND
- ZERO_DIVIDE
- TOO_MANY_ROWS ✓ Correct answer
- DUP_VAL_ON_INDEX
-
What is the error in the query: SELECT * FROM employee WHERE name = Ali;
Topic: Transactions, SELECT INTO & Common SQL Errors
- The table name is wrong
- The string value Ali must be enclosed in single quotes ('Ali') ✓ Correct answer
- WHERE cannot be used with SELECT
- A semicolon is missing
-
In database design, an Entity represents:
Topic: Database Design & Entity-Relationship Diagrams
- A real-world object ✓ Correct answer
- A column of a table
- A type of key
- A query result
-
In the file's Library System scenario, which of the following is an Entity?
Topic: Database Design & Entity-Relationship Diagrams
- Title
- ISBN
- Book ✓ Correct answer
- Author
-
In the file's ERD table, ISBN is an attribute of which entity?
Topic: Database Design & Entity-Relationship Diagrams
- Student
- Book ✓ Correct answer
- Loan
- Librarian
-
Which of the following is an attribute of the Loan entity in the file's ERD example?
Topic: Database Design & Entity-Relationship Diagrams
- Age
- Title
- Issue_Date ✓ Correct answer
- Address
-
In the file's query-based PL/SQL code, the employees displayed are those whose salary is:
Topic: Mixed / Other Important MCQs
- Less than the average salary
- Equal to the average salary
- Greater than the average salary ✓ Correct answer
- The minimum salary
-
In the same code, the average salary of all employees is stored into the variable avg_sal using:
Topic: Mixed / Other Important MCQs
- SELECT AVG(salary) INTO avg_sal FROM employees; ✓ Correct answer
- avg_sal := AVG(salary);
- GET AVG(salary) INTO avg_sal;
- FETCH AVG(salary) INTO avg_sal;