Skip to main content

SQL Interview Questions on Functions

SQL Functions:

Use only functions for data manupulation.

1. List employees whose name having 4 characters
2. List employees whose job is having 7 characters
3. Find out howmany times letter 'S' occurs in 'qspiders'
4. List the employees whose job is having last 3 characters as 'man'
5. List employees whose job is having first 3 characters as 'man'
6. Display all the names whose name is having exactly 1 'L'
7. Display dept names which are having letter 'O'
8. Display the output as shown below,
   Scott working as a clerk earns 3000 in dept 20
9. Display employees who earn odd numbered salaries
10. Display number of employees getting NULL comission.
11. Display total sal and comm drawn by dept 30
12. Count number of clerks in dept 10 and 20
13. List Department wise total salary
14. List department wise total sal only if the total sal is > 3000
15. Display job wise total salary excluding dept 30 only if the total salary is > 5000
16. Display job wise max sal only for managers, clerks, salesman working in dept 10 and 20. Sort the data by des order of the max salary.
17. Display job wise number of employees in all the department with total salary > 9000
18. Display the department number having atleast 4 employees in it
19. Display the department having only saleman in it
20 Calculate number of L in string 'HELLLLL'
21. Display all the employees whose job has a string 'MAN'
22. Display all the employees whose job starts with string 'MAN'
23. Display all the employees whose job ends with string 'MAN'
25. Display first 3 characters of ename in lower case and rest everything in upper case.
If ename is 'MITHUNASHOK' then display  this as 'mitHUNASHOK'

26. Display the result from emp table as below.

SMITH is a CLERK and gets salary 2000 

Here SMITH is ename column, CLERK is JOB and 2000 is SAL column and rest everything is literal strings.


Vijay_twinkle5 said…
can u pls update the solution for query
Jobwise 2nd or 3rd highest sal where i'll pass 2nd dynamically
using subqueries.
hi sir for Question NO. 4
--will select all the employees who are mangers
--says no rows selected
why it is so
saurabh suman said…
Answer For Question 4 is
FROM emp
WHERE SUBSTR(job,-3,3)='MAN';
akash dev said…
Answer For 21st:
SQL> select * from emp
where INSTR(job,'MAN') >= 1;
Afifa Kauser said…
can u pls post remaining answers for reference
karthik said…
Did u got any reply for the remaining questions ? If so,please share me the answers
Hitesh said…
can you tell the answer for ques 6
chinnu said…
MAN size is 3, u haven't specified any size so it can not compare with the unknown size
answer of 3:- select LEN('qspiders')-LEN(REPLACE('qspiders','s',''))
Irene Hynes said…

Allow me to show my gratitude bloggers. You guys are like unicorns. Never seen but always spreading magic. Your content is yummy. So satisfied.

I come up with a problem. In the pivot I want to summarize amount based on Hub and I want to always select the latest data of a country to add
Date Hub Country Amount
2017.01.01 Asia China 80
2017.01.02 Asia Japan 75
2017.01.03 Asia China 85
2017.01.01 Europe France 50
2017.01.05 Europe France 55
2017.01.02 Europe Turkey 20
I want to pivot to always select the latest data for each country and summarize based on Hub . Eg, for Asia that is 75+85=160, and for Europe, that is 55+20=75

It was cool to see your article pop up in my google search for the process yesterday. Great Guide.
Keep up the good work!

Irene Hynes
ajay ak said…
Pretty blog, so many ideas in a single site, thanks for the informative article, keep updating more article.
PHP course in chennai
w3 Webschool said…
Wonderful blog & good post.Its really helpful for me, awaiting for more new post. Keep Blogging!
Web Design Training

Popular posts from this blog

SQL Interview Questions on Subqueries

SUB Queries:
1. List the employees working in research department 2. List employees who are located in New York and Chicago
3. Display the department name in which ANALYSTS are working
4. Display employees who are reporting to JONES
5. Display all the employees who are reporting to Jones Manager
6. Display all the managers in SALES and ACCOUNTING department
7. Display all the employee names in Research and Sales Department who are having at least 1 person reporting to them
8. Display all employees who do not have any reportees
9. List employees who are having at least 2 reporting
10. List the department names which are having more than 5 employees
11. List department name having at-least 3 salesman
12. List employees from research and accounting having at-least 2 reporting
13. Display second max salary
14. Display 4th max salary
15. Display 5th max salary  -- Answer for nth Max Salary
Co-Related Subqueries:
16. Write a query to get 4th max salary from EMP table
17. Write a query to get 2nd…

Answers for SUB Queries

1. SQL> select empno, ename from emp where deptno=(select deptno from dept where dname='RESEARCH');

2. SQL> select empno, ename from emp where deptno in (select deptno from dept where loc in ('NEW YORK','CHICAGO'));

3. SQL> select dname from dept where deptno in ( select deptno from emp where job ='ANALYST');

4. SQL> select empno, ename, mgr from emp where mgr = (select empno from emp where ename='JONES');

5. SQL> select empno, ename, mgr from emp where mgr = (select mgr from emp where ename='JONES')

6. SQL> select empno, ename, job from emp where deptno in ( select deptno from dept where dname in ('SALES','ACCOUNTING'))

7. SQL> select empno, ename, job from emp where deptno in ( select deptno from dept where dname in ('SALES','RESEARCH')) and empno in (select mgr from emp)

8. SQL> select empno, ename from emp where empno not in ( select mgr from emp where mgr is not null)

9. select…

'Linux-x86_64 Error: 28: No space left on device' While trying to start the database -- Error

SQL> startup mount pfile='/tmp/initdlfasp12.ora'
ORA-27102: out of memory
Linux-x86_64 Error: 28: No space left on device

This as you can see is on Linux x86 with 64 bit processor. We got this error after we changed SGA on 10gR2 database. So was sure that this is something to do with the OS.

Parameters to check for this are shmall.

shmall is the total amount of shared memory, in pages, that the system can use at one time.

$cat /proc/sys/kernel/shmmax

$ getconf PAGE_SIZE

As per Oracle SHMALL should be set to the total amount of physical RAM divided by page size.

Our system has 64GB memory, so change kernel.shmall = 1024 * 1024 * 1024 * 64 / 4096 = 16777216

Once this value is calculated you can modify Linux system configuration file directly.

$ su - root
vi /etc/sysctl.conf file:


# sysctl -p

Once this is done the database was started without any problem.