You are on page 1of 14

1

Experiment-1 Creating Table.

i. Employee Table:
Create table Employee
(person_name varchar2 (30),
Street varchar2 (14),
City varchar2 (30));
Output Message: Table created.

Ii.Works Table:
Create table Works
(person_name varchar2 (30),
Company_name varchar2 (30),
Salary number (10));
Output Message: Table created.

iii. Company Table:


Create Table Company
(Company_name varchar2 (30),
City varchar2 (30));
Output Message: Table created.

Iv.Manages Table:
Create table manges
(Person_name varchar2 (30),
Manager_name varchar2 (30));
Output Message: Table created.

Experiment-2 Renaming Table.

Alter Table employee RENAME TO emp_new;

Output Message:-Table Altered

Experiment-3 Data constraint (Primary Key, Foreign Key, Not Null), Data Insertion into table.

Create table program24

(E_id number(10) PRIMARY KEY,

E_name varchar2(15),

E_designation varchar2(15),

E_salary number(10),

E_city varchar2(10));

Output Message:Table created.


2

insert into program23values(:E_id ,:E_name,:E_designation ,: E_salary ,:E_city);

OUTPUT:

select * from program23;

OUTPUT:

Experiment-4 Viewing table.

Create table program24

(E_id number (10) PRIMARY KEY,

E_name varchar2 (15),

E_designation varchar2 (15),

E_salary number (10),

E_city varchar2 (10));

Output Message: Table created.

Insert into program23values

(:E_id ,:E_name,

:E_designation ,
3

: E_salary ,:E_city);

Select * from program23;

Output:

Experiment -5 Filtering Table.


Create table program1

(Rollno number(10),

name varchar2(15),

class number(2),

subject varchar2(10),

percentage number(10));

OutputMessage:Table created.

Insert into program1 values


(: rollno,: name,
: Class,: subject
: percentage);
OutputMessage: 1 row(s) inserted.
Select * from program1;

Select * from program1 where percentage > 65;

Output:
4

Experiment-6 Creating Table from another Table.


Create table program25

(E_id number(10),

E_name varchar2(15),

E_designation varchar2(15),

E_salary number(10));

OutputMessage: Table created.

Select * from program25;

Output:

ALTER TABLE program25 RENAME TO program100;

OutputMessage:Table altered.

Select * from program100;

Output:
5

Experiment-7 Inserting Data into a table form another table


Insert into table Program100 values

(:e_id,

:e_name,

:e_designation,

:e_salary);

OutputMessage:

E_id-101

E_name-amit

E_designation-manger

E-salary- 10000

Select submit button

1 row inserted

Experiment-8 delete, alter and update table.


i. ALTER:

alter table program2 add( E_city varchar2(10));

Output Message: table altered.

ii.Update:

UPDATE program2 SET E_city='raipur';

Output Message:6 row(s) updated.

select * from program2;

OUTPUT:
6

iii.DELETE

DELETE FROM program20 WHERE E_id = 101;

Output Message: 1 row(s) deleted.

Experiment-9 Group by Data, Aggrigate Function.


i. Creating table:

Create table emp123

(e_id number (10),

e_name varchar2 (20),

e_address varchar2 (20),

e_salary number (10));

Output Message:-Table created.

ii.Insert table:-

insert into emp123 values

(:e_id:e_name,

: e _address,

: e_salary);

Output:

Enter value for e_id: 101

Enter value for e_name: heena

Enter value for e_address: raipur


7

Enter value for e_salary: 2000

iii.Group by clauses:-

select sum(e_salary)from emp123 group by e_id;

SUM (E_SALARY)

---------------------

7000

4000

10000

Experiment-10 Oracle Function (Mathmetical, Character Function)


I - Mathmatical Function:-

(i)ABS

ABS returns the absolute value of n.

The following example returns the absolute value of -87:

SELECT ABS(-87) "Absolute" FROM DUAL;

Output
Absolute
----------
87

(ii)ACOS

ACOS returns the arc cosine of n. Inputs are in the range of -1 to 1,


and outputs are in the range of 0 to pi and are expressed in radians.

The following example returns the arc cosine of .3:

SELECT ACOS(.3)"Arc_Cosine" FROM DUAL;


Output

Arc_Cosine
----------
1.26610367

Similar to ACOS, you have ASIN (Arc Sine), ATAN (Arc Tangent)
functions.

(iii)CIEL
Returns the lowest integer above the given number.

Example:
8

The following function return the lowest integer above 3.456;

select ciel(3.456) “Ciel” from dual;


Output

Ciel
---------
4

(iv)FLOOR

Returns the highest integer below the given number.

Example:

The following function return the highest integer below 3.456;

select floor(3.456) “Floor” from dual;

Output

Floor
------------
3

(II) Character Function:

(i)LOWER

Returns a given string in lower case.

select LOWER(‘SAMI’) from dual;


output
LOWER
-------------
sami

(ii)UPPER

Returns a given string in UPPER case.

select UPPER(‘Sami’) from dual;


output
UPPER
------------------
SAMI

(iii)INITCAP

Returns a given string with Initial letter in capital.


9

select INITCAP(‘mohammed sami’) from dual;


output
INITCAP
------------------
Mohammed Sami

(iv) LENGTH

Returns the length of a given string.

select length(‘mohammed sami’) from dual;


output
LENGTH
------------
13

Experiment-11. Subquieries

Create table student

(sid number (10),

name varchar2(15),

age number(10));

Insert into student values(:sid,:sname,:age);

OUTPUT:
10

Experiment-12 set operations

SELECT EMP_ID, EMP_NAME, EMP_ADDRESS, EMP_SSN


FROM EMP_TEST
UNION
SELECT EMP_ID, EMP_NAME, EMP_ADDRESS, EMP_SSN
FROM EMP_DESIGN;

OUTPUT:

Experiment-13 JOINS
i.QUERY:

SELECT STUDENT _ID, STUDENT_NAME, ADDRESS, CLASS_ID


FROM STUDENT s
WHERE s.CLASS_ID = ‘DESIGN_01’
AND s.ADDRESS = ‘Troy’;

ii.QUERY:

SELECT STUDENT _ID, STUDENT_NAME, ADDRESS, CLASS_ID


FROM STUDENT s
WHERE s.CLASS_ID = ‘DESIGN_01’
OR s.ADDRESS = ‘Troy’;

OUTPUT:
11

Experiment-14. PL/SQL

declare
n number(10);
m number(10);
i number:=1;
begin
n:=:n;
while i<=10 loop
m:=n*i;
dbms_output.put_line(m);
i:=i+1;
end loop;
end;

Output:
12

Experiment-15 PL/SQL (PROCEDURES)

Declare
a number(10);
b number(10);
c number(10);
begin
a:=&a;
b:=&b;
c:=a*b;
dbms_output.put_line(c);
end;

OUTPUT:
13

Experiment-16Trigger

CREATE OR REPLACE TRIGGER display_salary_changes

BEFORE DELETE OR INSERT OR UPDATE ON customers

FOR EACH ROW

WHEN (NEW.ID > 0)

DECLARE

sal_diff number;

BEGIN

sal_diff := :NEW.salary - :OLD.salary;

dbms_output.put_line('Old salary: ' || :OLD.salary);

dbms_output.put_line('New salary: ' || :NEW.salary);

dbms_output.put_line('Salary difference: ' || sal_diff);

END;

Result

Old salary: 1500


New salary: 2000
Salary difference: 500
14

Experiment-17. Cursors

DECLARE

c_id customers.id%type;

c_name customerS.No.ame%type;

c_addr customers.address%type;

CURSOR c_customers is

SELECT id, name, address FROM customers;

BEGIN

OPEN c_customers;

LOOP

FETCH c_customers into c_id, c_name, c_addr;

EXIT WHEN c_customers%notfound;

dbms_output.put_line(c_id || ' ' || c_name || ' ' || c_addr);

END LOOP;

CLOSE c_customers;

END;

OUTPUT

1 Ramesh Ahmedabad
2 Khilan Delhi
3 kaushik Kota
4 Chaitali Mumbai
5 Hardik Bhopal
6 Komal MP

You might also like