SQL Questions and Answers – SQL Like Operator

This set of SQL Multiple Choice Questions & Answers (MCQs) focuses on “SQL Like Operator”.

1. Which operator is used to search for a specified pattern in a column?
a) In
b) Between
c) Like
d) Pattern
View Answer

Answer: c
Explanation: The SQL LIKE clause is used to compare a value to similar values using wildcard operators. This operator is used to search for a specified pattern in a column.

2. The SQL LIKE operator is used in which of the following clause?
a) Select
b) Having
c) Group by
d) Where
View Answer

Answer: d
Explanation: The SQL LIKE operator is used in a WHERE clause to search for a specified pattern in a column.

3. Which of the following wildcards are used in conjunction with the LIKE operator?
a) %, _
b) !, %
c) !, _
d) *, %
View Answer

Answer: a
Explanation: %, _ are the two wildcards used in conjunction with the LIKE operator to search for a specified pattern in a column of the specified table.
advertisement
advertisement

4. To search for a value in a database table, when we don’t have an exact value to search for, which of the following is used?
a) Like
b) Between
c) In
d) Having
View Answer

Answer: a
Explanation: SQL LIKE is used to search for a value in a database table, when we don’t have an exact value to search for. This operator is used to select rows that match a character pattern.

5. The percent sign (%) represents which of the following?
a) Zero, one or multiple characters
b) Single character only
c) Multiple characters only
d) Two characters only
View Answer

Answer: a
Explanation: The percent sign is used in conjunction with the LIKE operator. It is used to represent zero, one, or multiple characters.

6. The underscore ( _ ) represents which of the following?
a) Zero or more characters
b) Two characters
c) Multiple characters
d) Exactly one character
View Answer

Answer: d
Explanation: The underscore ( _ ) is used in conjunction with the LIKE operator. It is used to represent exactly one character.

7. The percent sign and the underscore cannot be used in combinations.
a) True
b) False
View Answer

Answer: b
Explanation: The percent sign and the underscore can be used in combinations. For example, _r% represents any values that have “r” in the second position. Both %, _ can be used in a single pattern.
advertisement

8. Which of the following pattern matches strings which contain the substring ‘xxx’ in them at any position?
a) _xxx%
b) %xxx_
c) _xxx_
d) %xxx%
View Answer

Answer: d
Explanation: _ is used to match exactly one character. % is used to match zero or more characters. So, %xxx% represents any values that have xxx in any position.

9. The pattern used in LIKE clause must be enclosed in single quotations.
a) True
b) False
View Answer

Answer: a
Explanation: Patterns that are to be searched using LIKE clause must be enclosed in single quotes. To search for a pattern like _a%, we use LIKE ‘_a%’ in WHERE clause.
advertisement

10. The pattern ‘x_%_%’ matches which of the following strings?
a) Strings which starts with x and contain any number of characters
b) Strings which have x in any position
c) Strings which start with ‘a’ and contain at least 2 more characters
d) Strings which start with ‘a’ and contain exactly 2 characters
View Answer

Answer: c
Explanation: % represents zero or more characters, whereas _ represents exactly one character. As the given pattern has two % characters, the actual string may contain zero characters in that place, whereas in the positions with _ , there must be a character. So, the given pattern should contain at least 2 more characters along with a.

Sanfoundry Global Education & Learning Series – SQL.

To practice all areas of SQL, here is complete set of 1000+ Multiple Choice Questions and Answers.

If you find a mistake in question / option / answer, kindly take a screenshot and email to [email protected]

advertisement
advertisement
Subscribe to our Newsletters (Subject-wise). Participate in the Sanfoundry Certification contest to get free Certificate of Merit. Join our social networks below and stay updated with latest contests, videos, internships and jobs!

Youtube | Telegram | LinkedIn | Instagram | Facebook | Twitter | Pinterest
Manish Bhojasia - Founder & CTO at Sanfoundry
Manish Bhojasia, a technology veteran with 20+ years @ Cisco & Wipro, is Founder and CTO at Sanfoundry. He lives in Bangalore, and focuses on development of Linux Kernel, SAN Technologies, Advanced C, Data Structures & Alogrithms. Stay connected with him at LinkedIn.

Subscribe to his free Masterclasses at Youtube & discussions at Telegram SanfoundryClasses.