Class 12 Informatics Practices (065)
Sumita Arora Book Exercise Question Answer
Chapter 6 :- MySQL Functions Assignments
Type A – Short Answer Questions / Conceptual Questions
1. Define a Function.
Answer: Function is special type of Pre define command set that performed some operation and returns a single value.
2. What will be the output of following codes?
(i) mysql > SELECT CONCAT(CONCAT(‘Inform’, ‘actics’), ‘Practices’)
Answer: Informatics Practices
(ii) mysql> SELECT LCASE(‘INFORMATICS PRACTICES CLASS 11TH’)
Answer: informatics practices class 11th
(iii) mysql> SELECT UCASE(‘Computer studies’);
Answer: COMPUTER STUDIES
(iv) mysql> SLEECT CONCAT(LOWER(‘Class’), UPPER(‘xii’));
Answer: class XII
3. If Str = “INFORMATICS PRACTICES …” and Str1 = “… FOR CLASS XI”
Write commands to print the output as ‘informatics practices for class xi’
Answer: mysql> SELECT LOWER(CONCAT(Str, Str1));
OR
mysql > SELECT CONCAT(LOWER(Str), LOWER(Str1));
4. Write commands to display the system date.
Answer: SELECT SYSDATE();
5. Write a command to display the name of current month.
Answer: SELECT MONTHNAME(CURDATE() );
6. Write SQL statement to display – Today, the data is <current date>
Answer: SELECT CONCAT(‘today, the date is’ , CURDATE());
7. Write command to print the day of the week of your Birthday in the year 1999
Answer: SELECT DAYOFWEEK (‘1999-06-18);
8. Write command to display the current time.
Answer: SELECT CURTIME();
9. Consider two fields B_date, which stores the birth date and J_date, which stores the joining date of an employee.
Write commands to find out and display the approximate age of an employee as on today.
Answer: SELECT TIMESTAMPDIFF(YEAR, B_date, CURDATE()) AS “Age of Employee” FROM employee;
10. Anjali writes the following commands with respect to a table employee having fields, empno, name, department, commission :
Command 1: SLEECT COUNT(*) FROM EMPLOYEE;
Command 2: SELECT COUNT(COMMISSION) FROM EMPLOYEE;
She gets the output as 4 for the first command but gets an output 3 for the second command. Explain the output with justification.
Answer: The output is different because in first command, it’s count(*) which even includes null values but the second command is count(commission) which don’t include null values.
11. Write the SQL functions which will perform the following operations:
(i) To display the name of the month of the current date.
Answer: SELECT MONTHNAME(CURDATE());
(ii) To remove spaces from the beginning and end of a string ” Panorama “
Answer: SELECT TRIM(” Panorama “);
(iii) To display the name of the day, e.g. Friday or Sunday from your date of birth, dob.
Answer: SELECT DAYNAME(dob);
(iv) To display the starting position of your first name (fname) from your whole name (name)
Answer: SELECT INSTR(name, fname) FROM TABLENAME;
eg. SELECT INSTR(“ANJEEV SINGH ACADEMY . COM”, “SINGH”);
(v) To display the remainder of division between two numbers n1 and n2.
Answer: SELECT MOD(N1, N2);
Type B – Short Answer Questions
Type B – Short Answer Question – Next Page