IPA IP 2024 Question 93

Topic: Databases

A question IPA Japan published in 令和6年度 ITパスポート試験 公開問題 問93, translated into English. ITPEC is based on the same exams.

From the “Employee” table managed in a relational database, the employees whose names match ‘%葉_’ were extracted. How many employees were extracted? Here, “_” represents any one (1) character, and “%” represents a character string that consists of zero (0) or more of any characters.

Employee

Employee numberName
S001千葉翔
S002葉山花子
S003鈴木葉子
S004佐藤乙葉
S005秋葉彩葉
S006稲葉小春

Explanation

2 employees — ‘%葉_’ matches a name whose second-to-last character is 葉: any characters or none before it, and exactly one character after it.

The pattern must match the whole name: % stands for zero or more characters and _ for exactly one, so 葉 has to be followed by exactly one character.

Employee numberNameCharacters after 葉Match
S001千葉翔oneYes
S002葉山花子threeNo
S003鈴木葉子oneYes
S004佐藤乙葉noneNo
S005秋葉彩葉two, or none after the last 葉No
S006稲葉小春twoNo

S001 and S003 are extracted.

Answer (b)

Why not others:

  • •(a) 1 and (c) 3 — miscounts: exactly two names, S001 and S003, have one character after 葉
  • •(d) 4 — reads _ as zero or one character, which adds S004 and S005, whose names end in 葉

Key rule: In an SQL LIKE pattern, % is any string including the empty one and _ is exactly one character, and the pattern covers the whole value, so '%X_' means X is the second-to-last character.

Databases · AI-written, may contain errors

This question comes from the past questions IPA Japan publishes, translated into English by ITPEC Practice. ITPEC Practice is an independent study tool and is not affiliated with IPA or ITPEC. See the original paper (PDF) or Report an issue.