0% found this document useful (0 votes)
59 views5 pages

Question Bank-Chapter 6

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)
59 views5 pages

Question Bank-Chapter 6

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/ 5

Shree Swaminarayan English Medium School, Salvav, Vapi

Question bank-Chapter 6 Functions in MySql

Section A

Multiple Choice Questions:

1.Which function returns the answer int integer type?


a) LENGTH() b) INSTR() c) Both a and b d) only b.

2.What does the TRIM() function do?


a) Removes leading and trailing spaces b) Cuts a string to a specific length
c) Capitalizes the first letter of each word d) Converts a string to lowercase.

3.Answer of “Select round(23.34,-1); “ is


a) 23.3 b)23 c)20 d)20.34

4) Veena wants to calculate her age, what will be the suitable function she use
from the give list
a) YEAR() b) EXTRACT_YEAR() c) DAYOFYEAR() d) DATE_YEAR()

5) which of the following is not a text function?


A)TRIM() B)TRUNCATE() C) LEFT() D)MID()

6)Which of the following is not a numeric function?


A)MOD() B) SIGN() C)MID D)POW()

7)SELECT SIGN(0); will return


A)1 B)0 C)-1 D)None.

8)Functions MID() and SUBSTR() are same.


A)False B)True

9)To display system date with time, the function is


A)Sysdate() B)Time() C)DATETIME() D)CURDATE()

10)select left(“ABCD”,2) and select substr(“ABCD”,1,2) will return the same


answer.
A)YES B)NO

Answer Key:

Multiple Choice Questions:

1. (a)c) both a and b (b)a) Removes leading and trailing spaces (c)c) 20 b)
(4)a) YEAR() 5)B)TRUNCATE() 6)D)POW() 7)B)0 8)B)True
9)A)SYSDATE() 10)A)YES
Section C (3 marks)

Q1Write a query to display current date and time. Or

Write the SQL command that will display the current time and date.
Ans. mysql> SELECT NOW();

Predict the output of the following:


(I)SELECT ROUND(26.365675, 2);

(ii) SELECT TRUNCATE (11.28436, 1);

(iii) SELECT DAYOFMONTH('2020-08-25');

(iv) SELECT MID('Pandemic Year', 2,3);

(v) SELECT INSTR('CODE UNICODE', 'CO');

(vi) SELECT INSTR('DCODE UNICODE', 'co');

(vii) SELECT LEFT('Informatics', 3), RIGHT('Practices',3);

(viii)SELECT LENGTH(CONCAT('INTER', 'NETWORK', 'KING'));

(ix)SELECT ROUND (234.7894, -1)*5;

(x) SELECT ROUND (234.7894, 0)*5;

(xi) SELECT ROUND (234.7894, -2) *5;

(xii) SELECT MID('One Good',3,4);

(xiii) SELECT TRUNCATE (17.4975,2);

(xiv) SELECT RIGHT (CONCAT('PYTHON', 'PRACTICES', 'INFORMATICS'), 9);

(xv)SELECT MID('OnlineEducation',2,4);

(xvi)SELECT ROUND (64.26446,3);

(xvii) SELECT INSTR('INFORMATICS PRACTICES', 'ACT');

(xviii)SELECT POW(INSTR('Success@hardwork', '@'),2);

(xix) SELECT POW (LENGTH('WORK'), 3);

(xx) SELECT MONTH('2020-11-23') * POW(2,3);


Ans.(I)26.37 (ii) 11.2 (iii) 25 (iv) and (v) 1 (vi) 2 (vii) Inf ces (viii) 16
(ix) 1150 (x) 1175
(xi) 1000 (xii) e Go (xiii) 17.49 (xiv) FORMATICS (xv) nlin (xvi)64.264
(xvii) 15 (xviii) 64
(xix)64 (xx) 88

Q2. Explain TRIM() function with examples.


Ans-Trim() function is used to trim extra spaces and extra characters from left
and right side.
Syntax to trim spaces from both sides . select trim(‘ abc ‘);
syntax to trim extra characters from left side -select trim(leading ‘ *‘ from ‘*abc’);
syntax to trim extra characters from right side -select trim(trailing ‘ *‘ from
‘abc*’);

Section E
Q.1 Consider a table SALESMAN with the following data.

SNO SNAME SALARY BONUS DATE OF JOIN


A01 Beena Mehta 30000 45.23 29-10-2019
A02 K.L. Sahay 50000 25.34 13-03-2018
B03 Nisha Thakkar 30000 35.00 18-03-2017
B04 Leela Yadav 80000 NULL 31-12-2018
C05 Gautam Gola 20000 NULL 23-01-1989
C06 Trapti Garg 70000 12.37 15-06-1987
D07 Neena Sharma 50000 27.89 18-03-1999

Write SQL queries using SQL functions to perform the following operations:

a) Disaplay salesman name and bonus after rounding off to zero decimal places.
b) Display the position of occurance of the string “ta” in salesman names.
c) Display the four characters from salesman name starting from second
character.
d) Display the month name for the date of join of salesman.
e) Display the month of the weekday for the date join of salesman.

Ans :

a) SELECT sname, round (bonus, 0) FROM Salesman;


b) SELECT instr(Sname, "ta") FROM Salesman;
c) SELECT mid (Sname, 2,4) FROM Salesman;
d) SELECT monthname (DateofJoin) FROM Salesman;
e) SELECT dayname (DateofJoin) FROM Salesman;
Q.2 Write the SQL functions which will perform the following operations:

(1) To display the name of the month of the current date.


(2) To remove spaces from the beginning and end of a string, "Panorama".
(3) To display the name of the day e.g., Friday or Sunday from your date of birth,
dob.
(4) To display the starting position of your first name(fname) from your whole
name (name).
(5) To compute the remainder of division between two numbers, n1 and n2.

Ans.

1) SELECT MONTHNAME(CURDATE());
2) SELECT TRIM(" Panorama ");
3) SELECT DAYNAME('2000-07-22');
4) SELECT INSTR('Gupta Ashwini', 'Ashwini') AS StartingPosition;
5) SELECT MOD(n1, n2);

Q.3 Write suitable SQL query for the following:

1) Display 7 characters extracted from 7th left character onwards from the
string 'INDIA SHINING’.
2) Display the position of occurrence of string 'COME' in the string
'WELCOME WORLD'.
3) Round off the value 23.78 to one decimal place.
4) Display the remainder of 100 divided by 9.
5) Remove all the expected leading and trailing spaces from a column userid
of the table 'USERS'.

Ans:

1) SELECT SUBSTR('INDIA SHINING', 7, 7);


2) SELECT INSTR('WELCOME WORLD', 'COME');
3) SELECT ROUND(23.78, 1);
4) SELECT MOD(100, 9);
5) SELECT TRIM(userid) FROM USERS;

Q.3 Write suitable SQL query for the following:

1) If Str = "INFORMATICS PRACTICES ...." and Str1 = "... FOR CLASS XI"Write
commands to print the output as 'informatics practices for class xi'
2) Write commands to display the system date.
3) Write a command to display the name of current month.
4) Write SQL statement to display : Today, the date is <current date>
5) Write command to print the day of the week of your Birthday in the year
2005.

Ans:
1) SELECT CONCAT(LCASE('INFORMATICS PRACTICES'), ' ', LCASE('FOR CLASS
XI'));
2) SELECT SYSDATE();
3) SELECT MONTHNAME(CURDATE());
4) SELECT CONCAT('Today, the date is ', CURDATE()) AS CURDATE;
5) SELECT DAYOFWEEK('2005-07-21');

You might also like