0% found this document useful (0 votes)
6 views3 pages

Worksheet 14 - Only Ans - Single Row Function

The document provides a series of SQL queries and their outputs, focusing on single row functions in MySQL. It includes examples of functions like ROUND, TRUNCATE, DAYOFMONTH, and MID, along with explanations of differences between NOW() and SYSDATE(). Additionally, it lists outputs for various queries involving string manipulation and date functions, as well as identifying single row functions.

Uploaded by

teacherafs2025
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
6 views3 pages

Worksheet 14 - Only Ans - Single Row Function

The document provides a series of SQL queries and their outputs, focusing on single row functions in MySQL. It includes examples of functions like ROUND, TRUNCATE, DAYOFMONTH, and MID, along with explanations of differences between NOW() and SYSDATE(). Additionally, it lists outputs for various queries involving string manipulation and date functions, as well as identifying single row functions.

Uploaded by

teacherafs2025
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 3

Informatics Practices

(Single Row Functions)


SQL - Ans
1. Write the output of the following SQL queries:
a) SELECT ROUND(6.5675, 2); 6.57
b) SELECT TRUNCATE(5.3456, 1); 5.3
c) SELECT DAYOFMONTH('2009-08-25'); 25
d) SELECT MID('Class 12', 2,3); las
2. Write the output of the following SQL queries :
(i) SELECT INSTR(‘UNICODE’,’CO’); 4
(ii) SELECT RIGHT(‘Informatics’,3); ics
3. State difference between date functions NOW( ) and SYSDATE( ) of MySql.

Now() Sysdate()

Now displays the date and time at Sysdate() displays the date and time at the
the beginning of the command. exact time of the execution of the
command.

It always displays the same date and It displays the exact date and time at
time in a single sql command. No which it is executed within the single
matter how many times it is being command.
executed.

Example:

4. Name a function of MySql which is used to remove trailing and leading spaces from a string.

trim

5. Consider the following table named 'SBOP" with details of account holders. Write output

(i) SELECT ROUND(Balance,-3) FROM SBOP WHERE


AccountNo=”SB-5”;

Ans. i)
ROUND(Balance,-3)
63000

6. Write the output of the following SQL queries :


(i) SELECT RIGHT(‘software’, 2); re
(ii) SELECT INSTR(‘twelve’,‘lv’); 4
(iii) SELECT DAYOFMONTH(‘2014-03-01’); 1
(iv) SELECT ROUND(76.987, 2); 76.99
Informatics Practices
(Single Row Functions)
SQL - Ans
7. Write the output of the following SQL queries:
i. SELECT INSTR(‘INTERNATIONAL’, ‘NA’); 6
ii. SELECT LENGTH(CONCAT(‘NETWORK’,’ING’)); 10
iii.SELECT ROUND(563.345,-2); 600
iv. SELECT DAYOFYEAR(‘2014-01-30’); 30
8. Pranay, who is an Indian, created a table named “Friends” to store his friend’s detail.
Table “Friends” is shown below. Write output for (i) and (ii).

i. Select ucase(concat(name,”*”,city)) from friends where country like ‘Denmark’;


ii. Select mid(name,1,4) as “UID” from friends where country like ‘USA’;
i. ucase(concat(name,”*”,city))
CHARLES*COPENHAGEN
JETTE*NYKOBING
ii. UID
Alic
Ange

9. Write the output of the following SQL queries:


i) SELECT TRUNCATE(8.975,2); 8.97
ii) SELECT MID(‘HONESTY WINS’,3,4); NEST
iii) SELECT RIGHT(CONCAT(‘PRACTICES’,’INFORMATICS’),5); ATICS
iv) SELECT DAYOFMONTH(‘2015-01-16’); 16
10. Write the output of the following SQL queries :
(i) SELECT MID(‘BoardExamination’,2,4); oard
(ii) SELECT ROUND(67.246,2); 67.25
(iii) SELECT INSTR(‘INFORMATION FORM’,‘FOR’); 3
(iv) SELECT DAYOFYEAR(‘2015-01-10’); 10
11. Write output.
Table : Store
StoreId Name Location City NoOfEmployees DateOpened SalesAmount
S101 Planetfashion KarolBagh Delhi 7 2015-10-16 300000
S102 Trends Nehru Mumbai 11 2015-08-09 400000
Nagar
S103 Vogue Vikas Delhi 10 2015-06-27 200000
Vihar
S104 Superfashion Defence Delhi 8 2015-02-18 450000
Colony
S105 Rage Bandra Mumbai 5 2015-09-22 600000
(i) SELECT Name, length (name), left (name, 3) FROM Store where NoOfEmployees<3;
i) Empty Set

12. Write the output of the following SQL queries:


SELECT POW(INSTR(‘My_Database’,’_’),2); 9
13. Consider the table given below :
Informatics Practices
(Single Row Functions)
SQL - Ans
Write output.

(i) SELECT Name, LENGTH(Name) FROM Salesperson;

Ans.
Name Length()
Amit Kumar 10
Deepika Sharma 14
Vinay Srivastav 15
Kumar Mehta 11
Rashmi Kumar 12
14. Identify Single Row functions of MySQL amongst the following :
TRIM(), MAX(), COUNT(*), ROUND()
Trim() and Round() are single row functions

15. Consider the Table “Gym” and write output

(i) SELECT MID(Mname,1,2)from Gym;

Ans.
MID(Mname,1,2)
Am
Ra
Ge
Fa
Sa
La
Su
Mi
Da
Aj
16. Observe the given table named “Loan” carefully
and predict the output of the
following queries:
i. SELECT concat(left(file_no,2),
right(cust_name,2)) AS “ID” from loan where
Bank='ICUCI Ltd.';
ii. select round(loan_amt-loan_amt*10/100) As
"Discounted Payment" from loan where
loan_amt>700000;
i) ID
23mi
43et
ii) Discounted Payment
728888
671164

You might also like