Friday, 11 April 2014

How to create table in SQL/ORACLE

1. Create a table named admission_detail with attribute AID, Reg.no, DOB, Program Name, DOA.

Create table admission(AID int primary key, Reg_no int, name char(20), DOB date, Program_name char(20), DOA date)

insert into admission values(5896,101,'Raj','20-jan-89','Bcom','02-Feb-14')
insert into admission values(5897,102,'Raju','21-Mar-90','BBA','03-Jan-14')
insert into admission values(5898,103,'Rajan','26-Jul-90','IT','05-Jan-14')
insert into admission values(5899,104,'Ram','25-Jul-90','BBAIT','07-Jan-14')
insert into admission values(5895,105,'Ramu','29-Dec-76','BBA','07-Jan-14')

Admission
AIDREG_NONAMEDOBPROGRAM_NAMEDOA
5896101Raj20-JAN-89Bcom02-FEB-14
5897102Raju21-MAR-90BBA03-JAN-14
5898103Rajan26-JUL-90IT05-JAN-14
5899104Ram25-JUL-90BBAIT07-JAN-14
5895105Ramu29-DEC-76BBA07-JAN-14

2.Change the program name from BBA to BBAIT for AID 5896.
update admission
set program_name='BBAIT'
where AID=5896

AIDREG_NONAMEDOBPROGRAM_NAMEDOA
5896101Raj20-JAN-89BBAIT02-FEB-14
5897102Raju21-MAR-90BBA03-JAN-14
5898103Rajan26-JUL-90IT05-JAN-14
5899104Ram25-JUL-90BBAIT07-JAN-14
5895105Ramu29-DEC-76BBA07-JAN-14
3.Display age of all student.
select (months_between('29-Dec-76',DOB)/12) from admission

(MONTHS_BETWEEN('29-DEC-76',DOB)/12)
-12.05914
-13.228495
-13.575269
-13.572581
0
4.Add column program code?
alter table admission
add program_code int

AIDREG_NONAMEDOBPROGRAM_NAMEDOAPROGRAMME_CODE
5896101Raj20-JAN-89BBAIT02-FEB-14
5897102Raju21-MAR-90BBA03-JAN-14
5898103Rajan26-JUL-90IT05-JAN-14
5899104Ram25-JUL-90BBAIT07-JAN-14
5895105Ramu29-DEC-76BBA07-JAN-14
5.Calculate the year between DOB and DOA.
select (months_between(DOB,DOA)/12) from admission

(MONTHS_BETWEEN(DOB,DOA)/12)
-25.034946
-23.784946
-23.443548
-23.451613
-37.024194

6. How to view the table.
select * from Admission

No comments:

Post a Comment