Wednesday, February 13, 2019

DATE command in SQL

                                                                                             edited  by Sukamal
1:
 select sysdate
from dual
output:
SYSDATE
13-FEB-19

2:
select to_char(sysdate,'dd/mm/yy')
from dual
output:
TO_CHAR(SYSDATE,'DD/MM/YY')
13/02/19

3:
 select to_char(sysdate,'dd/mm/yyyy')
from dual
output:
TO_CHAR(SYSDATE,'DD/MM/YYYY')
13/02/2019

4:
select to_char(sysdate,'dy/mon/yyyy')
from dual
output:
TO_CHAR(SYSDATE,'DY/MON/YYYY')
wed/feb/2019

5:
select to_char(sysdate,'day/month/yyyy')
from dual
output:
TO_CHAR(SYSDATE,'DAY/MONTH/YYYY')
wednesday/february /2019

6:
select to_char(sysdate,'dd/mm/yy,hh:mi:ss')
from dual
output:
TO_CHAR(SYSDATE,'DD/MM/YY,HH:MI:SS')
13/02/19,02:48:55

7:
create table employee(id varchar2(20) primary key,name varchar2(20),dob date);
insert into employee values('1','vk',to_date('05/11/1988','dd/mm/yyyy'));
insert into employee values('2','msd',to_date('02/07/1982','dd/mm/yyyy'));
select *
from employee
output:

ID
NAME
DOB
2
msd
02-JUL-82
1
vk
05-NOV-88

8:Find the name of the employee who is younger than msd.

select name
from employee
where dob>(select dob from employee where name ='msd');
output:
NAME
vk

9:Find the name of employee who was born before 1985.

select name
from employee
where dob <to_date('1985','yyyy');
output:
NAME
msd

10:Find the name and month of dob of each employee.

 select name,to_char(dob,'mm') as month
from employee
output:
NAME
MONTH
msd
07
vk
11

11:Find the age of all employee.

select floor((sysdate-dob)/364.25)
from employee;
output:
FLOOR((SYSDATE-DOB)/364.25)
30
36


No comments:

Post a Comment