Worksheet 24091101 Database Query using SQL
MCQs :
- Which SQL function is used to raise a number to a power?
- (A)
ROUND()
- (B)
MOD()
- (C)
POWER()
- (D)
TRIM()
- (A)
- What does the
ROUND()
function do in SQL?- (A) Rounds a number up
- (B) Rounds a number to the nearest integer
- (C) Truncates decimal places
- (D) Converts a number to a string
- Which SQL function returns the uppercase version of a string?
- (A)
UPPER()
- (B)
LCASE()
- (C)
MOD()
- (D)
LENGTH()
- (A)
- The function
LENGTH()
in SQL is used to:- (A) Return the position of a substring in a string
- (B) Return the length of a string
- (C) Trim spaces from both sides of a string
- (D) Convert a string to lowercase
- Which SQL function is used to extract a portion of a string?
- (A)
MID()
- (B)
LENGTH()
- (C)
UPPER()
- (D)
TRIM()
- (A)
- To get the current date and time in SQL, which function is used?
- (A)
DATE()
- (B)
NOW()
- (C)
MONTH()
- (D)
DAYNAME()
- (A)
- What does the
RTRIM()
function do in SQL?- (A) Removes spaces from the right side of a string
- (B) Removes spaces from the left side of a string
- (C) Removes both leading and trailing spaces
- (D) Converts a string to lowercase
- The function
INSTR()
is used for:- (A) Extracting a substring
- (B) Finding the position of a substring within another string
- (C) Converting text to uppercase
- (D) Calculating the length of a string
Assertion-Reasoning
- Assertion (A): The
TRIM()
function in SQL removes spaces from both sides of a string.
Reason (R): TheTRIM()
function only works on characters, not numbers.- (A) Both A and R are true, and R is the correct explanation of A.
- (B) Both A and R are true, but R is not the correct explanation of A.
- (C) A is true, but R is false.
- (D) A is false, but R is true.
- Assertion (A): The
DAYNAME()
function in SQL returns the name of the day for a given date.
Reason (R): TheDAY()
function returns the full name of the day, such as “Monday” or “Tuesday.”- (A) Both A and R are true, and R is the correct explanation of A.
- (B) Both A and R are true, but R is not the correct explanation of A.
- (C) A is true, but R is false.
- (D) A is false, but R is true.
SQL Programming Questions:
- Write an SQL query to raise 2 to the power of 5.
- Write an SQL query to round the number 23.567 to 2 decimal places.
- Write an SQL query to return the uppercase version of the string ‘database’.
- Write an SQL query to find the length of the string ‘SQL Functions’.
- Write an SQL query to extract ‘Functions’ from the string ‘SQL Functions’.
- Write an SQL query to get the current date and time.
- Write an SQL query to remove trailing spaces from the string ‘ Hello World ‘.
- Write an SQL query to find the position of ‘com’ in the string ‘Welcome’.
- Write an SQL query to return the name of the month from the current date.
- Write an SQL query to return the day of the week for ‘2023-09-01’.