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

Oracle RDBMS Lab Manual Dec 2022 (26!10!2022)

Uploaded by

ASHIKA J
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
20 views

Oracle RDBMS Lab Manual Dec 2022 (26!10!2022)

Uploaded by

ASHIKA J
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 32

DEPARTMENT OF COMPUTER APPLICATIONS

SCOTT CHRISTIAN COLLEGE (Autonomous)


NAGERCOIL-629003

III B.C.A

RDBMS & ORACLE


20GRP6

RECORD NOTEBOOK

2022-2023

DEPARTMENT OF COMPUTER APPLICATIONS


SCOTT CHRISTIAN COLLEGE (Autonomous)
NAGERCOIL-629003
Class No Register No

Certificate and Bonafide record Work done by

…………………………………………………

Semester: V

…………………….. ……………………..
Staff-in-charge Head of the department

Date:………………….

Submitted for the practical examination held in November 2022 at Scott Christian
College (Autonomous), Nagercoil .

Examiner1:

Examiner2:
INDEX
S.NO CONTENT PG. NO SIGN
1

TABLE CREATION
2

FIBONACCI NUMBERS
3

ARMSTRONG NUMBER
4

𝐏𝐑𝐎𝐆𝐑𝐀𝐌 𝐔𝐒𝐈𝐍𝐆 𝐂𝐔𝐑𝐒𝐎𝐑


5

SUM OF DIGITS
6

MULTIPLICATION TABLE
7

REVERSING A NUMBER
8

PALINDROME
9

TRIGGERING THE TABLE


10

SQL OPERATIONS
11

USING SEQUENCES AND


SYNONYMS
12

VIEW CREATION
𝐄𝐱.𝐍𝐨 :
TABLE CREATION
𝐃𝐚𝐭𝐞 :

AIM :

To create sample table with required fields and constraints.

PROCEDURE:

1. Open SQL*plus

2. Enter the user name and password to begin and connect to oracle server.
3. In the SQL Prompt type the query to create tables with the following columns and
constraints.

Book Master

Column Datatype Constraint


Book Number VARCHAR2 (10) NOT NULL
Book Name VARCHAR2(15) NOTNULL
Author VARCHAR2 (10)
Publication VARCHAR2 (10)
Price

4. View the description of the above created table.


5. Insert all the research from the table.
6. List all the research from the table.
7. Stop the process.

CODING :

create table books1(bookno varchar2(10) primary key,bookname varchar2(15) not null,author


varchar2(10),publication varchar2(10),price number(8,2));
describe books1;
insert into books1 values('cs1','linux','peter','bpb','500'); insert into
books1 values('cs2','windows','john','oxford','425.50');
select*from books1;
insert into books1 values('cs3','word','maria','bpb','700');
select*from books1; insert into books1 values('cs4','msdos','norton','bpb','300');insert into
books1 values('cs5','maths','john','phi','350'); select*from books1;
OUTPUT:
RESULT :
PL/SQL program is executed successfully.
𝐄𝐱.𝐍𝐨 :
𝐃𝐚𝐭𝐞 :
FIBONACCI NUMBERS

AIM :
To write a PL/SQL code to find the fibonacci numbers.

PROCEDURE :

8. Open SQL*plus

9. Enter the username and password to login and connect to oracle server.

10. Type the command set server output on.

11. In SQL number of typed followed by filename. SQL and type the code in notepad window.

12. Declare the required variables.

13. Get the prompt number term as input to initialize y1=0; y2=1.

14. Open the loop and calculate F3=F1+F2.

15. Repeat it until we get the required number of terms and close the loop.

16. Display the result to execute the PL/SQL program using the command >@ filename.

17. Stop the process.

CODING:
Declare
i number;
n number;
f1 number;
f2 number;
f3 number;
begin
n:='&n';
f1:=0;
f2:=1;
dbms_output.put_line('The fibonacci numbers are;');
dbms_output.put_line(f1);
dbms_output.put_line(f2);
for i in 3..n loop
f3:=f1+f2;
dbms_output.put_line(f3)
; f1:=f2;
f2:=f3;
end loop; end;
OUTPUT :

RESULT :
PL/SQL program is executed successfully.
𝐄𝐱.𝐍𝐨 :
ARMSTRONG NUMBER
𝐃𝐚𝐭𝐞 :

AIM :
To write a SQL program to create Armstrong number.
PROCEDURE :

1. open SQL*plus.
2. Enter the username and password to login and connect to oracle server. ASQ >is display.
iii. In notepad, declare the required variable begin the loop and calculate the Armstrong
number
3. End the loop.
4. Display the output.
5. End the PL/SQL block.

CODING:
Declare

n number(3);

s number(3):=0;

t number(3);
begin
n:=&n;
t:=n;

while t>0 loop


s:=s+power((tmod10),3);
t:=trunc(t/10);

end loop;

if(s=n)then
dbms_output.put_line('thegivennumber '||n|is an armstrong number');
else dbms_output.put_line('the given number '||n||' is not an Armstrong number');
endif;

end;

OUTPUT:
RESULT:
PL/SQL program is executed successfully
𝐄𝐱.𝐍𝐨 :
𝐏𝐑𝐎𝐆𝐑𝐀𝐌 𝐔𝐒𝐈𝐍𝐆 𝐂𝐔𝐑𝐒𝐎𝐑
𝐃𝐚𝐭𝐞 :

𝐀𝐈𝐌 :
To write a PL/SQL code to find the program using cursor.

𝐏𝐑𝐎𝐂𝐄𝐃𝐔𝐑𝐄 :

1. Open SQL*plus

2. Enter the username and password to login and connect to oracle server. A SQL> is display

3. Type the command set server output on

4. In SQL number of type ed followed by forename SQL and type code in notepad window

5. Declare a cursor c1 to retrieve information using select statement

6. Declare another cursor c1 to update data's

7. In the executable section open the cursor

8. Fetch data ‘s from cursor

9. Display the data’s and close the cursor.

𝐂𝐎𝐃𝐈𝐍𝐆 :

SQL> create table employee(empno number(5), empname varchar2(10), salary number(8));

Table created.

SQL> insert into employee values(‘1’,’asha’,’30000’);

1 row created.

SQL> insert into employee values(‘2’,’ancy’,’35000’);

1 row created.

SQL> insert into employee values(‘3’,’rancy’,’20000’);

1 row created.

SQL> insert into employee values(‘4’,’alan’,’25000’);

1 row created.

SQL> insert into employee values(‘5’,’banu’,’38000’);

1 row created.
SQL>Select*from employee;

EmpnoEmpname Salary

--------------------------------------------------------------------
1 asha 30000
2 ancy 35000
3 rancy 20000
4 alan 25000
5 banu 38000

SQL>Declare

2 Cursor cl is select*from emp;

3 Begin

4 For I in cl

5 Loop

6 Dbms_output.put_line(I.ename||’ ‘||I.sal);

7 End loop;

8 End;

9 /

Asha 30000

Ancy35000

Rancy 20000
Alan 25000
Banu 38000

PL/SQL Procedure successfully completed.

𝐑𝐄𝐒𝐔𝐋𝐓 :
PL/SQL program is executed successfully.
𝐄𝐱.𝐍𝐨 :

𝐃𝐚𝐭𝐞 : SUM OF DIGITS

AIM:
To write a PL/SQL to find the sum of digits.

PROCEDURE:

1. Open SQL*Plus
2. Type ed(edit) followed any file name SQL
3. Type the required coding in the notepad window
4. Declare the required variable
5. Begin the loop and do the calculation
6. End the loop
7. Display the output
8. End the PL/SQL block
9. Save the file and selected file ->Exit
10. In SQL prompt type SQL->setserver output on to execute
11. In SQL prompt type SQL->@followed by file name, output in displayed.

CODING:

declare

number(10); s

number(10); r

number(10);

begin

n:='&n';
s:=0;

while n<>0 loop


r:=mod(n,10);
n:=n-r;
n:=n/10;
s:=s+r;
end loop;
dbms_output.put_line('sum of digits is:'||s);
end;
OUTPUT:

RESULT:

PL/SQL program is executed successfully.


𝐄𝐱.𝐍𝐨 :

𝐃𝐚𝐭𝐞 : MULTIPLICATION TABLE

AIM:
To write a PL/SQL code to create the multiplication table

PROCEDURE:

1. Open SQL*Plus
2. Enter the username and password to login and connect to oracle server
3. Type the command set server output on
4. In the notepad declare the required variables .
5. End the loop display the output
6. End the PL/SQL block
CODING:

Declare

i number;

n number;

c number;

begin

n:=&n

for i in 1..10 loop


c:=i*n;
dbms_output.put_line(i||'*'||n||'='||c );
end loop

end;
OUTPUT:

RESULT :
PL/SQL program is executed successfully.
𝐄𝐱.𝐍𝐨 :

𝐃𝐚𝐭𝐞 : REVERSING A NUMBER

AIM:
To write SQL queries to the concept of the reversing a number.

PROCEDURE:
1. Open SQL *plus

2. Enter the username and password login to connect oracle server.

3. In notepad declare the required variable begin the loop and allowed the receiving

number.

4. End the loop display the output.

5. End the PL/SQL block

CODING:
Declare

num1number(5);
num2number(5);
rev number(5);
begin
num1:=&num1;
rev:=0;
while num1>0 loop

num2:=num1 mod 10;

rev:=num2+(rev*10);

num1:=floor(num1/10);

end loop;

dbms_output.put_line('reverse number is:'||rev);


end;
RESULT:

PL/SQL program is executed successfully.


𝐄𝐱.𝐍𝐨 :

𝐃𝐚𝐭𝐞 : PALINDROME

AIM:
To write a PL/SQL code to find the palindrome.

PROCEDURE:

1. Open SQL*Plus
2. Enter the username and password to login and connect to oracle server. A
SQL>is display.
3. Type the command set server output on
4. In the notepad declare the required variable begin the loop and calculate the
palindrome
5. End the loop display the output
6. End the PL/SQL block
CODING:

Declare Strvarchar2(50):=’&String’;

Counter int:=length(str);

BEGIN dbms_Output.Put_line(Counter):

loop exit WHEN Counter=0;

exit WHEN not(substr,(Str,counter,1)=SubStr(Str,((length(Str)+1)counter),1));

Counter:=Counter-

1; end loop;

if counter=0 THEN dbms_Output.Put_line(Str||’is palindrome’) ;


elsedbms_Output.Put_line(Str||’is not palindrom’) ;
end if;
end ;
RESULT:

PL/SQL program is executed successfully.


𝐄𝐱.𝐍𝐨 :

𝐃𝐚𝐭𝐞 : TRIGGERING THE TABLE

AIM:
To create a database and run when changes are made to a table’s data.

PROCEDURE:

1. Open SQL*Plus
2. Enter the username and password to login
3. In the SQL Prompt type the query to create tables
4. Insert values into the tables
5. List all the records from the tables
6. Update the tables
7. End the loop display the output
8. End the PL/SQL block

CODING:

Create table employe1(empnonumber(5),empname varchar2(8),Street varchar2(20),city

varchar2(20)); insert into employe1 values(‘1’, ’rami', ’firstcross’, ’Mumbai’) ;

insert into employe1 values(‘2’, ’anu’, ‘Seccross’, ‘Chennai’) ;


insert into employe1 values(‘3’, ’sumi’, ‘thicross’, ‘Delhi’) ;
insert into employe1 values(‘3’, ’vinu’, ‘westcross’, ‘bombai’);

insert into employe1 values(‘5’, ’ammu’, ‘tcross’, ‘karur’) ;

Select*from employe1;

Create or replace trigger shows

beforeupdate on employe1

for each row

begin

dbms_Output.Put_line(‘the old name was:’);

dbms_Output.Put_line(:Old.empname);

dbms_Output.Put_line(‘the updated new name is :’);

dbms_Output.Put_line(:new.empname);

end;

update employe1 Set empname=’kiran' where empno=1;


RESULT:

PL/SQL program is executed successfully.


𝐄𝐱.𝐍𝐨 :

𝐃𝐚𝐭𝐞 : SQL OPERATIONS

AIM:
To prepare various operations of SQL.

PROCEDURE:

1. Open SQL* server


2. Enter the login credentials
3. Start with table creation => FNAME, LNAME, SSN number, address, salary, DNO are its
elements
4. In SQL prompt, type the required queries using the default table ‘EMPLOYEE’ woth 6 rows
and 6 columns
5. Using select table EMPLOYEE, execute the various set operations
6. The output will be displayed
7. Stop the process

CODING:

CREATE TABLE employee(FNAME varchar2(20), LNAME varchar2(20), SSN number(10), Address


varchar2(20), Salary number(10), DNO number(10));

DESCRIBE EMPLOYEE;

Insert into EMPLOYEE values(‘JOHN’, ‘SMITH’, ‘123456789’, ‘zion street’, ‘30000’,’5’);

Insert into EMPLOYEE values(‘FRANKLIN’, ‘WONG’, ‘123222333’, ‘lyan street’, ‘30006’,’5’);


Insert into EMPLOYEE values(‘ALIA’, ‘BHATT’, ‘123444555’, ‘sooner street’, ‘45000’,’4’);
Insert into EMPLOYEE values(‘ZEE’, ‘TANIA ‘122456789’, ‘golden street’, ‘32000’,’4’);

Insert into EMPLOYEE values(‘RONI’, ‘SINGH’, ‘555556789’, ‘york street’, ‘120000’,’5’);

Insert into EMPLOYEE values(‘JOLLY’, ‘TOM’, ‘1987659’, ‘fener street’, ‘45000’,’5’);


Select * from EMPLOYEE;

SQL PERATIONS:

1) BETWEEN,AND:
SELECT FNAME,SALARYF ROME MPLOYEE WHERE SALARY BETWEEN 20000 AND 30000;

2) NOT:
SELECT FNAME FROM EMPLOYEE WHERE DNO NOT IN <1,4,5>;
3)IN:
SELECT FNAME FROM EMPLOYEE WHERE DNO IN <1,4,5>;
4)RENAME:
RENAME EMPLOYEE TO EMPLOYEES;
5)DELETE:
DELETE FROM EMPLOYEES WHERE SSN=123456789;
OUTPUT:

.
Result:

PL/SQL program is executed successfully.


𝐄𝐱.𝐍𝐨 :
USING SEQUENCES AND SYNONYMS
𝐃𝐚𝐭𝐞 :

AIM:
To create a sample table and create sequences and synonym in the table

Procedure:

1. Open SQL plus


2. Create a table
3. Insert rows
4. Create sequences for the tables
5. Insert sequences for the tables
6. View all the data from the tables
7. Create synonym for the table and view it
8. End the procedures and quit

Code:
SQL>Create tableA1(Snonumber(5), Regno number(6), Name
varchar2(20));
Table created

SQL>Describe A1;
Name Null? Type
------------------------------------------------------------------------
SnoNumber(5)
Regno Number(5)
Name varchar2(20)

SQL>Create sequences2 increment by 1 start with 1 nomaxvalue;


Sequence created;

SQL>Insert into A1 values(s2.nextval,200501,’Alan’);


1 row created

SQL>Insert into A1 values(s2.nextval,200502,’Annie’);


1 row created
SQL>Insert into A1 values(s2.nextval,200503,’Banu’);
1 row created
SQL>Insert into A1 values(s2.nextval,200504,’Asha’);
1 row created

SQL>Insert into A1 values(s2.nextval,200505,’Anu’);


1 row created

SQL>Select*fromA1;

Sno Regno Name


--------------------------------------------------------------------------------------
1 200501 Alan
2 200502 Annie
3 200503 Banu
4 200504 Asha
5 200505 Anu

SQL>Alter sequence S2 increment by 2;


Sequence altered.

SQL>Insert into A1 values(S2.nextval,200506,’Roshini’);


1row created.

SQL>Insert into A1 values(S2.nextval,200507,’Rancy’);


1row created.

SQL>Insert into A1 values(S2.nextval,200508,’Ancy’);


1row created.

SQL>Select*from A1;

Sno Regno Name


---------------------------------------------------------------------------------------------
1 200501 Alan
2 200502 Annie
3 200503 Banu
4 200504 Asha
5 200505 Anu
6 200506 Roshini
7 200507 Rancy
8 200508 Ancy
SQL>Create synonym N1 for A1;
Synonym created.

SQL>Select*fromA1;
Sno Regno Name
------------------------------------------------------------------------------------
1 200501 Alan
2 200502 Annie
3 200503 Banu
4 200504 Asha
5 200505 Anu
6 200506 Roshini
7 200507 Rancy
8 200508 Ancy
Output :

Result: PL/SQL program is executed successfully.


𝐄𝐱.𝐍𝐨 :

𝐃𝐚𝐭𝐞 : VIEW CREATION

AIM:
To create view to store employee details and department details.
Procedure:

1. Open SQL plus


2. Create a table
3. Insert rows
4. Create the view with following columns to show details of various
in dept view and emp view.
5. We can replace, group by order by and drop and view.
6. End the process.

CODE:
SQL> CREATE TABLE DEPARTMENT(DEPTID NUMBER(2) PRIMARY KEY,
DEPTNAME VARCHAR2(25), NOOFEMP NUMBER(20), LOC
VARCHAR2(20), PHONENO NUMBER(10));
TABLE CREATED.

SQL> CREATE TABLE EMPLOYEE1(EMPID NUMBER(4) PRIMARY KEY,


ENAME VARCHAR2(25), DESIG VARCHAR2(25), SAL
NUMBER(10,2), DOJ DATE, DEPTID NUMBER(2), CONSTRAINT CC1
FOREIGN KEY(DEPTID) REFERENCES DEPARTMENT(DEPTID));
TABLE CREATED.

SQL> SELECT*FROM DEPARTMENT;


DEPTID DEPTNAME NOOFEMP LOC PHONENO
-----------------------------------------------------------------------------------------------------------------
1 SALES 25CHENNAI 223344
2 MARKETING 30 VELLORE 227788
3 ACCOUNTING 19THANJAVUR 786809
4 MANUFACTURING 50 SALEM 902345
5 PACKING 45 SALEM 789065
SQL> SELECT*FROM EMPLOYEE1;
EMPID ENAME DESIG SAL DOJ DEPTID
----------------------------------------------------------------------------------------------------------
100 ASHA CLERK 5500 12-SEP-04 3
101 ANCY OFFICE STAFF 8970 15-JUN-03 1
102 BANU MANAGER 15000 01-FEB-05 3
103 ANNIE ENGINEER 22000 02-APR-99 4
104 RANCY ASSISTANT 7500 01-JUN-06 5
105 ALAN AREA MANAGER 16800 03-OCT-03 2

SQL> CREATE VIEW VW1 AS SELECT DEPTID, DEPTNAME, NOOFEMP FROM


DEPARTMENT;
VIEW CREATED.

SQL> SELECT*FROM VW1;


DEPTID DEPTNAME NOOFEMP
---------------------------------------------------------------------
1 SALES 25
2 MARKETING 30
3 ACCOUNTING 19
4 MANUFACTURING 50
5 PACKING 45

SQL>INSERT INTO VW1 VALUES(6,’PRODUCTION’,55);


1 ROW CREATED.
SQL>SELECT*FROM VW1;
DEPTID DEPTNAME NOOFEMP
-----------------------------------------------------------------------
1 SALES 25
2 MARKETING 30
3 ACCOUNTING 19
4 MANUFACTURING 50
5 PACKING 45
6 PRODUCTION 55
6 ROWS SELECTED.

SQL>SELECT*FROM VW1 WHERE DEPTNAME LIKE’%G’;


DEPTID DEPTNAME NOOFEMP
----------------------------------------------------------------------
2 MARKETING 30
3 ACCOUNTING 19
4 MANUFACTURING 50
5 PACKING 45
SQL>CREATE VIEW VW2 AS SELECT D.DEPTID,D.DEPTNAME,
EMPID,E.ENAME,E.DESIG FROM DEPARTMENT, EMPLOYEE1 WHERE D.DEPTID;
VIEW CREATED.

SQL>SELECT*FROM VW2;
DEPTID DEPTNAME EMPID ENAME DESIG
----------------------------------------------------------------------------------------------------
3 ACCOUNTING 100 ASHA CLERK
1SALES 101 ANCY OFFICE STAFF
3ACCOUNTING102 BANU MANAGER
4MANUFACTURING 103 ANNIE ENGINEER
5PACKING 104 RANCY ASSISTANT
2MARKETING 105ALAN AREA MANAGER
7 ROWS SELECTED.

SQL>SELECT*FROM VW2 WHWERE DEPTID=3;


DEPTID DEPTNAME EMPID ENAME DESIG
----------------------------------------------------------------------------------
3 ACCOUNTING 100 ASHA CLERK
3 ACCOUNTING 102 BANU MANAGER

SQL> SELECT*FROM VW2 ORDER BY EMPID DESC;


DEPTID DEPTNAME EMPID ENAME DESIG
----------------------------------------------------------------------------------------------------
2 MARKETING 105 ALAN AREA MANAGER
5 PACKING 104 RANCY ASSISTANT
4 MANUFACTURING 103 ANNIE ENGINEER
3 ACCOUNTING 102 BANU MANAGER
1 SALES 101 ANCY OFFICE STAFF
3 ACCOUNTING 100 ASHA CLERK
6 ROWS SELECTED.
Output :

Result:

PL/SQL program is executed successfully.

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy