Question:

Write SQL queries for the following:
(i) To calculate the square of 15.
(ii) To round the number 456.789 to the nearest integer.
(iii) To display the position of first occurrence of 'com' in the string 'mycommercial.com'.
(iv) To display the name of the day for the date '2024-11-07'.
(v) To display the current date and time.

Show Hint

Use POWER() for exponents, ROUND() for rounding, INSTR() for finding positions, DAYNAME() for weekdays, and NOW() for current time.
Updated On: Jul 14, 2025
Hide Solution
collegedunia
Verified By Collegedunia

Solution and Explanation

(i) Calculate the square of 15:
To get the square of a number, use POWER().
SELECT POWER(15, 2);

Explanation: POWER() returns the value of the first argument raised to the power of the second.
So 15 squared is 15 to the power 2, which equals 225.
(ii) Round 456.789 to nearest integer:
Use ROUND() to round decimal numbers.
SELECT ROUND(456.789, 0);

Explanation: The ROUND() function takes the number and the number of decimal places.
0 means no decimal places, so it rounds to the nearest whole number.
Result is 457.
(iii) Position of 'com' in 'mycommercial.com':
Use INSTR() to find position of substring.
SELECT INSTR('mycommercial.com', 'com');

Explanation: INSTR() returns the position of the first occurrence of the substring in the string.
Here, 'com' first appears starting at position 3 in 'mycommercial.com'.
(iv) Display name of the day for given date:
Use DAYNAME() to get day name from a date.
SELECT DAYNAME('2024-11-07');

Explanation: DAYNAME() returns the weekday name.
For 2024-11-07, it will return 'Thursday'.
(v) Display current date and time:
Use NOW() or CURRENT TIMESTAMP.
SELECT NOW();

Explanation: NOW() returns the current date and time based on the system.
It is useful for timestamps, logging, and audit trails.
Was this answer helpful?
0
0

Top Questions on SQL Queries

View More Questions

Questions Asked in CBSE CLASS XII exam

View More Questions