0% found this document useful (0 votes)
13 views

single row functions-1st (3) (3)

Uploaded by

ianzeha21
Copyright
© © All Rights Reserved
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
13 views

single row functions-1st (3) (3)

Uploaded by

ianzeha21
Copyright
© © All Rights Reserved
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 5

Single Row functions

Case Manipulation functions


General functions
Null functions
Number functions
String functions
Control statements
Date functions
Date conversion functions

1)Case manipulation function

Upper
lower
Initcap -Steven

Select upper(first_name),lower(first_name),Initcap(first_name) from employees;

2)General functions

a) Greatest
b)least
c)Concat
d)Unique/distinct
e)first
f)last

Select greatest(9,4,5),least(9,4,5) from dual;

Select concat(first_name,last_name)from employees;

Select distinct(department_id) from employees;

Select department_id from employees order by department_id desc nulls last ;

3)Null function

a)nvl() - 2 args,If the 1st arg is null,


returns 2nd arg,else 1st arg.

b)nvl2()- 3 args,If 1st arg is null,returns 3rd arg,else 2nd arg.


c)nullif() -2 args....If both the args are same,returns null,else 1st arg is
displayed.
d)coalesce()- multiple args....always returns the 1st not null value....

Select nvl (5,7) from dual;

Select nvl2(4,5,6) from dual;

Select nullif(5,8) from dual;

Select coalesce (null,null,null,8,9,7,null) from dual;

Select commission_pct,nvl(commission_pct,20) from employees;


4)Number functions

a)Round
b)trunc
c)power
d)sqrt
e)abs
f)sign
g)mod
h)ceil
i)floor

select round(2.2),round(2.9) from dual;

select trunc(2.2),trunc(2.9) from dual;

select ceil(2.2),ceil(2.9) from dual;

select floor(2.2),floor(2.9) from dual;

select power(3,2)from dual;

select sqrt(9)from dual;

select mod(10,3)from dual;

select sign(-9),sign(9)from dual;

select abs(-9),abs(9)from dual;

select mod(10,3)from dual;

anything below 2.5-lowest int

anything that is 2.5 or above-highest int

Select * from employees;

Select department_id ,commission_pct from employees;

Select 22 sum from dual;


Select 'HAI' name from dual;

Date Functions:-

1)Add_months
2)Months_between
3)Next_day
4)Last_day
5)String function
6)Control statements
7)Date functons
8)Date conversion functions
___________________________________________________________________________________
_____________________________________

1)Basics and Operators:-


=========================

1)What is a database?

2)Difference between DBMS and RDBMS?

3)What are the functions of a database?

4)Names like 'a%'


like '%a'
like '%a%'
like '_a%'
like 'a_%'
like 'a%y'

SELECT first_name FROM employees WHERE first_name LIKE 'Steven%';

SELECT first_name FROM employees WHERE first_name LIKE 'a%';


SELECT first_name FROM employees WHERE first_name LIKE '%a';
SELECT first_name FROM employees WHERE first_name LIKE '%a%';
SELECT first_name FROM employees WHERE first_name LIKE '_a%';
SELECT first_name FROM employees WHERE first_name LIKE 'a_%';
SELECT first_name FROM employees WHERE first_name LIKE 'a%y';

5) Fetch the names of the employees whose salary is below 10000 and above 15000?
SELECT first_name, last_name, salary, department_id
FROM employees
WHERE salary NOT BETWEEN 10000 AND 15000;

6)Fetch the names of the employees whose salaries are 17000,10000 and 24000
respectively?

7)Difference between SQL and MYSQL?

8)Display the first_name,last_name and salary by providing a space amongst them....


(Concatenate operator)...

SELECT first_name, last_name, first_name || last_name || salary FROM employees;

9)Fetch the names of the employees whose name starts with 'N' and ends with 'y'?
10)Fetch the employee whose name is David and is earning 9500rs?

2)Functions:-
==============
1.Display the outputs by taking scenarios from employees table and apply several
null functions?

2.Print 'Best','Better','Bad' and 'worst' against each departments using case


statement...

3.Fetch First monday of last month?

select next_day(add_months(trunc(sysdate, 'mm'), -1), 'monday') first_monday from


dual;

4.Fetch first day of previous month?


select trunc(trunc(sysdate,'MM')-1,'MM') "First Day of Last Month" from dual;

select trunc(trunc(sysdate,'MM')-1,'MM') "First Day of Last


Month",trunc(sysdate,'MM')-1 "Last Day of Last Month" from dual;

select last_day(add_months(sysdate,-1)) from dual;(for last day of last month) this


is correct

select trunc(add_months(sysdate,-1),'MM') from dual;(for first day of last month)


this is correct

5.Fetch first day of this year?


SELECT TRUNC (SYSDATE, 'YEAR')as first_day from dual;

6.Fetch the names of the employees who have joined in the month of september?

7.Fetch the names of the employees who have joined in the month of Aug94?

8.What is the difference between Decode and case statement?

9.Why do we use control statements?

10.What is the difference between replace and translate functions?Elaborate with an


example..

GROUP FUNCTION:
1.Fetch the no.of salaried employees in each department?
Select deptno,count(*) from emp group by deptno;

2.Fetch department wise min salary?

SELECT first_name, last_name, salary, department_id


FROM employees
WHERE salary IN
( SELECT MIN(salary)
FROM employees
GROUP BY department_id
);
3.Fetch the null values from commission_pct using count?

4.Fetch the not null values from Commission_pct using count?

5.Fetch department wise max salary?

You might also like