Skip to content
Exercises · Q2

Q.Write the output produced by the following SQL statements:

a) SELECT POW(2,3);
b) SELECT ROUND(342.9234,-1);
c) SELECT LENGTH("Informatics Practices");
d) SELECT YEAR("1979/11/26"), MONTH("1979/11/26"), DAY("1979/11/26"), MONTHNAME("1979/11/26");
e) SELECT LEFT("INDIA",3), RIGHT("Computer Science",4), MID("Informatics",3,4), SUBSTR("Practices",3);
Tripura TbseTextbookSubjective· 3mImportance★★★★★
44% · 42/95 Questions
✓ Free question

These SQL statements demonstrate built-in string, numeric, and date functions that manipulate or extract information from values without querying any table.

Why These Functions Matter

SQL provides a rich library of built-in functions that operate on literals (constant values) or column data. When you SELECT a function with a literal argument and no FROM clause, SQL evaluates the function immediately and returns the result as a single-row output. These functions are essential for data transformation, formatting reports, and extracting meaningful information from stored values.

Let's trace each statement and understand what every function does.


(a) SELECT POW(2,3);

Function: POW(base, exponent) raises the base to the power of the exponent.

Here, 23=2×2×2=82^3 = 2 \times 2 \times 2 = 8.

Output:

+----------+
| POW(2,3) |
+----------+
|        8 |
+----------+

(b) SELECT ROUND(342.9234,-1);

Function: ROUND(number, decimals) rounds a number to a specified number of decimal places. When decimals is negative, rounding happens to the left of the decimal point.

  • ROUND(342.9234, -1) rounds to the nearest ten.
  • The digit in the tens place is 4. The digit to its right (units place) is 2, which is less than 5, so we round down.
  • Result: 340.0340.0 (displayed as 340 in most SQL engines).

Output:

+------------------------+
| ROUND(342.9234,-1)     |
+------------------------+
|                    340 |
+------------------------+
Tip

Negative precision in ROUND is powerful for aggregating data to the nearest hundred, thousand, etc. — useful in financial or statistical summaries.


(c) SELECT LENGTH("Informatics Practices");

Function: LENGTH(string) returns the number of characters in the string, including spaces.

Count the characters in "Informatics Practices": "Informatics" has 11 letters, then 1 space, then "Practices" has 9 letters.

Total: 21 characters (11 in "Informatics", 1 space, 9 in "Practices").

Output:

+----------------------------------+
| LENGTH("Informatics Practices")  |
+----------------------------------+
|                               21 |
+----------------------------------+

(d) SELECT YEAR("1979/11/26"), MONTH("1979/11/26"), DAY("1979/11/26"), MONTHNAME("1979/11/26");

Functions: These extract components from a date string in YYYY/MM/DD format.

  • YEAR("1979/11/26") → 1979
  • MONTH("1979/11/26") → 11 (November is the 11th month)
  • DAY("1979/11/26") → 26
  • MONTHNAME("1979/11/26") → "November" (the full name of the month)

Output:

+---------------------+----------------------+--------------------+-----------------------------+
| YEAR("1979/11/26")  | MONTH("1979/11/26")  | DAY("1979/11/26")  | MONTHNAME("1979/11/26")     |
+---------------------+----------------------+--------------------+-----------------------------+
|                1979 |                   11 |                 26 | November                    |
+---------------------+----------------------+--------------------+-----------------------------+
Note

MONTHNAME returns the locale-dependent full month name. In English environments, November; in other locales, the translated equivalent.


(e) SELECT LEFT("INDIA",3), RIGHT("Computer Science",4), MID("Informatics",3,4), SUBSTR("Practices",3);

These are substring extraction functions.

LEFT("INDIA", 3)

Extracts the leftmost 3 characters from "INDIA".

Result: "IND"

RIGHT("Computer Science", 4)

Extracts the rightmost 4 characters from "Computer Science".

The string ends with "...ence", so the last 4 are: "ence"

MID("Informatics", 3, 4)

MID(string, start, length) extracts a substring starting at position start (1-indexed) for length characters.

  • Start at position 3 of "Informatics": the 3rd character is 'f'.
  • Extract 4 characters: 'f', 'o', 'r', 'm'.
  • Result: "form"

SUBSTR("Practices", 3)

SUBSTR(string, start) extracts from position start to the end of the string.

  • Start at position 3 of "Practices": the 3rd character is 'a'.
  • Extract from 'a' to the end: "actices".
  • Result: "actices"

Output:

+-------------------+-------------------------------+---------------------------+------------------------+
| LEFT("INDIA",3)   | RIGHT("Computer Science",4)   | MID("Informatics",3,4)    | SUBSTR("Practices",3)  |
+-------------------+-------------------------------+---------------------------+------------------------+
| IND               | ence                          | form                      | actices                |
+-------------------+-------------------------------+---------------------------+------------------------+
Watch out

SQL string positions are 1-indexed, not 0-indexed like Python or C. MID("ABC", 1, 1) returns "A", not "B".


✓Final answer

(a) 8

(b) 340

(c) 21

(d) 1979 | 11 | 26 | November

(e) IND | ence | form | actices

Unlock everything free for 14 days

  • Full step-by-step solutions
  • Concept-first explanations
  • Methods, shortcuts & mistakes
  • PYQ mapping + timed mock tests

Full access for 14 days. No credit card required.