Professional Documents
Culture Documents
Dbms
Dbms
EX:NO: 01
SINGLE LINE QUERY AND GROUP FUNCTION
DATE: 19.02.2023
AIM
To create a single line query and group function using simple queries.
E-R DIAGRAM
DESCRIPTION
CREATE
Syntax:
INSERT into table-name values(data1,data2,..);
GROUP FUCTION
The GROUP BY statement groups rows that have the same values into
summary rows, ( COUNT() , MAX() , MIN() , SUM() , AVG() ). The types of group
functions (also called aggregate functions).
AVG()
Average returns average value after calculating from values in a numeric
column.
Syntax:
SELECT AVG(column_name) from table_name
COUNT()
Count returns the number of rows present in the table either based on some
condition or without condition.
Its general Syntax is,
SELECT COUNT(column_name) from table-name
MAX()
MAX function returns maximum value from selected column of the table.
Syntax of MAX function is,
SELECT MAX(column_name) from table-name
MIN()
MIN function returns minimum value from a selected column of the table.
Syntax for MIN function is,
SELECT MIN(column_name) from table-name
SUM()
SUM function returns total sum of a selected columns numeric values.
Syntax for SUM is,
SELECT SUM(column_name) from table-name
Table created.
INSERTION
insert into custo values(1,’Ramesh’,’Chennai’,4000);
1 row(s) inserted.
ID N AM E AD D R E S S S AL AR Y
1 Ramesh Chennai 4000
2 Krishna Delhi 1500
3 Keerthi Mumbai 4500
4 Chaitali Indore 10000
AVG()
selectavg(salary) from custo;
AV G ( S AL AR Y)
5000
MAX()
select max(salary) from custo;
M AX ( S AL AR Y)
10000
MIN()
select min(salary) from custo;
M IN( S AL AR Y)
1500
SUM()
SU M( S AL AR Y)
20000
COUNT()
C OU N T(S AL AR Y )
4
RESULT
EX:NO: 02
DDL COMMANDS
DATE: 27.01.2023
AIM
To create and execute a DDL commands using query.
E-R DIAGRAM
DESCRIPTION
DDL changes the structure of the table like creating a table, deleting a table,
altering a table, etc.
o All the command of DDL are auto-committed that means it permanently save
all the changes in the database.
DDL COMMANDS
o CREATE
o ALTER
o DROP
o TRUNCATE
CREATE
It is used to create a new table in the database.
Syntax: Java Program for Beginners
CREATE TABLE TABLE_NAME (COLUMN_NAME DATATYPES[,....]);
DROP
It is used to delete both the structure and record stored in the table.
Syntax:
DROP TABLE table_name;
ALTER
It is used to alter the structure of the database. This change could be either to
modify the characteristics of an existing attribute or probably to add a new attribute.
Syntax:
TRUNCATE
It is used to delete all the rows from the table and free the space containing the
table.
Syntax:
2. DDL COMMANDS
TABLE CREATION
create table emp(Empid number(10),Name varchar(20), Address varchar(20),
Designation varchar(20),Salary number(10),pf number(10));
Table created.
TABLE DESCRIPTION
desc emp;
NAME Varchar2 20 - - -
ADDRESS Varchar2 20 - - -
DESIGNATION Varchar2 20 - - -
SALARY Number - 10 - -
PF Number - 10 - -
ALTER
Modify:
NAME Varchar2 20 - - -
ADDRESS Varchar2 30 - - -
DESIGNATION Varchar2 20 - - -
SALARY Number - 10 - -
PF Number - 10 - -
Add:
NAME Varchar2 20 - - -
ADDRESS Varchar2 30 - - -
DESIGNATION Varchar2 20 - - -
SALARY Number - 10 - -
PF Number - 10 - -
DA Number - 10 - -
INSERTION
EM P ID N AM E AD D R E S S DE S IG N AT I ON S AL AR Y PF
101 Anbu 2 car st,Chennai Manager 15000 1200
102 Baby 2/4 Nehru st,Delhi Asst.Manager 19500 1350
103 Chintu Temple st,Noida Designer 12000 900
104 Durga Koil st,Kovai Clerk 9000 750
105 Ezhil 15/3 Krish,Mumbai Gen Manager 25000 1800
ALTER
Add:
alter table emp add(da number(10));
Table altered.
EM P ID N AM E AD D R E S S DE S IG N AT I ON S AL AR Y PF DA
101 Anbu 2 car st,Chennai Manager 15000 1200 -
102 Baby 2/4 Nehru st,Delhi Asst.Manager 19500 1350 -
103 Chintu Temple st,Noida Designer 12000 900 -
104 Durga Koil st,Kovai Clerk 9000 750 -
105 Ezhil 15/3 Krish,Mumbai Gen Manager 25000 1800 -
RENAME
rename emp to emp1;
Statement processed.
EM P ID N AM E AD D R E S S DE S IG N AT I ON S AL AR Y PF DA
101 Anbu 2 car st,Chennai Manager 15000 1200 -
102 Baby 2/4 Nehru st,Delhi Asst.Manager 19500 1350 -
103 Chintu Temple st,Noida Designer 12000 900 -
104 Durga Koil st,Kovai Clerk 9000 750 -
105 Ezhil 15/3 Krish,Mumbai Gen Manager 25000 1800 -
Truncate
no data found.
Drop
RESULT
EX:NO: 03
DML COMMANDS
DATE: 02.02.2023
AIM
To create and execute a DML commands using query.
E-R DIAGRAM
DESCRIPTION
DML COMMANDS
o INSERT
o UPDATE
o DELETE
o SELECT
INSERT
It is used to insert data into the row of a table.
Syntax
INSERT INTO TABLE_NAME (col1, col2,.. col N) VALUES (value1, value2,.. valueN);
Or
INSERT INTO TABLE_NAME VALUES (value1, value2, value3, .... valueN);
UPDATE
It is used to update or modify the value of a column in the table.
Syntax
UPDATE table_name SET [col_name1= value1,...col_nameN = valueN] [where condition];
DELETE
It is used to remove one or more row from a table.
Syntax
DELETE FROM table_name [WHERE condition];
3.DML COMMANDS
TABLE CREATION
create table emp(Empid number(10),Name varchar(20), Address varchar(20),
Designation varchar(20),Salary number(10),pf number(10));
Table created.
TABLE DESCRIPTION
desc emp;
NAME Varchar2 20 - - -
ADDRESS Varchar2 20 - - -
DESIGNATION Varchar2 20 - - -
SALARY Number - 10 - -
PF Number - 10 - -
INSERTION
EM P ID N AM E AD D R E S S DE S IG N AT I ON S AL AR Y PF
101 Anbu 2 car st,Chennai Manager 15000 1200
102 Baby 2/4 Nehru st,Delhi Asst.Manager 19500 1350
103 Chintu Temple st,Noida Designer 12000 900
104 Durga Koil st,Kovai Clerk 9000 750
105 Ezhil 15/3 Krish,Mumbai Gen Manager 25000 1800
SELECT
SINGLE ROW
N AM E
Anbu
Baby
Chintu
Durga
Ezhil
Select where IN
select * from emp where salary in 15000;
EM P ID N AM E AD D R E S S DE S IG N AT I ON S AL AR Y PF
103 Chintu Temple st,Noida Designer 13000 900
104 Durga Koil st,Kovai Clerk 10000 750
UPDATION
update emp set salary=salary+1000;
4 row(s) updated.
EM P ID N AM E AD D R E S S DE S IG N AT I ON S AL AR Y PF
101 Anbu 2 car st,Chennai Manager 16000 1200
102 Baby 2/4 Nehru st,Delhi Asst.Manager 20500 1350
103 Chintu Temple st,Noida Designer 13000 900
104 Durga Koil st,Kovai Clerk 10000 750
105 Ezhil 15/3 Krish,Mumbai Gen Manager 26000 1800
DELETION
delete from emp where empid='103';
1 row(s) deleted.
EM P ID N AM E AD D R E S S DE S IG N AT I ON S AL AR Y PF
101 Anbu 2 car st,Chennai Manager 16000 1200
102 Baby 2/4 Nehru st,Delhi Asst.Manager 20500 1350
104 Durga Koil st,Kovai Clerk 10000 750
105 Ezhil 15/3 Krish,Mumbai Gen Manager 26000 1800
RESULT
EX:NO: 04
DCL AND TCL COMMANDS
DATE: 10.02.2023
AIM
To create and execute a DCL and TCL commands using query.
E-R DIAGRAM
DESCRIPTION
TCL commands can only use with DML commands like INSERT, DELETE and
UPDATE only. These operations are automatically committed in the database that's
why they cannot be used while creating tables or dropping them.
o COMMIT
o ROLLBACK
o SAVEPOINT
Commit
Syntax
COMMIT;
Rollback
Rollback command is used to undo transactions that have not already been
saved to the database.
Syntax
ROLLBACK;
SAVEPOINT
It is used to roll the transaction back to a certain point without rolling back the
entire transaction.
Syntax
SAVEPOINT SAVEPOINT_NAME;
TABLE CREATION
desc emp;
Tabl e Colu mn Da ta Typ e Le ng th Pr eci sion Prim ary K ey Null abl e De f aul t
DOB Number - 6 - -
mobile Number - 10 - -
Email Varchar 20 - - -
INSERTION
1 row inserted
1 row inserted
1 row inserted
1 row inserted
EM PNA M E DO B MOB I LE EM AI L
Joe 04493 464525655 joe@gmail.com
DCL
Grant
GRANT SELECT, UPDATE ON employee TO System;
TCL
1 row(s) deleted.
EM PNA M E DO B MOB I LE EM AI L
Joe 04493 464525655 joe@gmail.com
viji 120493 9965231256 viji@gmail.com
commit;
Commit statement not applicable. All statements are automatically committed.
EM PNA M E DO B MOB I LE EM AI L
Joe 04493 464525655 joe@gmail.com
viji 120493 9965231256 viji@gmail.com
ROLLBACK;
Sql > Rollback statement not applicable. All statements are automatically committed
RESULT
EX:NO: 05
NESTED QUERIES
DATE: 17.02.2023
AIM
E-R DIAGRAM
DESCRIPTION
NESTED QUERIES
The output of inner query is put in the condition of the outer query.
(i)in
The in connective tests for set membership, where the set is a collection of
values produced by a select clause.
(ii)not in
CORRELATED QUERY
SOME
EXISTS
ALL
ALL operator, in contrast to ANY operator, returns the maximum value from a
given set of values.
NOT EXISTS
5. NESTED QUERIES
TABLE CREATION:1
create table bk(bkid number(10)primary key,Titlevarchar(20),Author varchar(20),Price
number(20),Year number(20));
Table created.
INSERTION
insert into bk values(101,'DBMS','Rajesh Narang',450,2008);
1 row(s) inserted.
TABLE CREATION:2
OR ID BK ID QU AN T IT Y
11 101 25
12 102 50
13 105 45
IN
selecttitle,author,price from bk where year in('2005');
T IT L E AU T H OR PR IC E
OS Silberscath 350
NOT IN
selecttitle,author,price from bk where year not in('2005');
T IT L E AU T H OR PR IC E
DBMS Rajesh Narang 450
Artificial Narang 200
Designer Basu 400
SOME
select distinct title from bk where price>some (select price from bk where year='2005');
T IT L E
Designer
DBMS
ALL
select distinct title from bk where price>all (select price from bk where year='2010');
T IT L E
DBMS
EXISTS
select title from bk where exists (select *from ord_dt where bk.bkid=ord_dt.bkid);
T IT L E
DBMS
OS
NOT EXISTS
select title from bk where not exists (select *from ord_dt where bk.bkid=ord_dt.bkid);
T IT L E
Artificial
Designer
RESULT
EX:NO: 06
JOIN OPERATIONS
DATE: 22.02.2023
AIM
E-R DIAGRAM
DESCRIPTION
Joins are used to combine columns from different tables. The tables can be
connected using WHERE clause.
Types of Joins are:
1. Equi Join
2. Cross Joins
3. Outer Joins
4. Self-Join
Syntax of a Join is:
SELECT <select-list>FROM <tablel>, <table 2>, ...<table n>
WHERE ctable 1, column 1> = <table 2, column 2> AND
<table n-1, column i> = <table n, column j>
Equi-Join
Equi-Join joins two tables on the basis of equality of one or more columns.
Syntax
SELECT column-name-list from table-name1 INNER JOIN (or) JOIN table-name2
WHERE table-name1.column-name = table-name2.column-name;
Natural Join
Natural Join is a type of Inner join which is based on column having same
name and same data type present in both the tables to be joined.
Syntax
SELECT * from table-name1 NATURAL JOIN table-name2;
Cross Join
If WHERE Clause is not specified in a SELECT statement then each row of one
table is joined to all the rows of another table. The result is a Cartesian product of the
tuples(rows) of two tables.
Syntax is,
SELECT column-name-list from table-name1 CROSS JOIN table-name2;
Outer Join
Outer Join is based on both matched and unmatched data. Outer Joins
subdivide further into,
Self-Join
It is an equi-join on the same table. Suppose we want to get a list of titles
which have same price in table title.
INSERTION
insert into t1 values(11,'Anu');
1 row(s) inserted.
ID N AM E
11 Anu
12 Baby
13 Chintu
TABLE CREATION: 2
create table t2 (id number(20),Address varchar(20));
Table created.
INSERTION
insert into t2 values(11,'Delhi');
1 row(s) inserted.
ID AD D R E S S
11 Delhi
13 Mumbai
14 Chennai
INNER JOIN
selectid,address from t2 inner join t1 using(id);
ID AD D R ESS
11 Delhi
13 Mumbai
NATURAL JOIN
selectid,address from t1 natural join t2;
ID AD D R ESS
11 Delhi
13 Mumbai
11 Anu 11 Delhi
13 Chintu 13 Mumbai
12 Baby - -
11 Anu 11 Delhi
13 Chintu 13 Mumbai
- - 14 Chennai
11 Anu 11 Delhi
13 Chintu 13 Mumbai
12 Baby - -
- - 14 Chennai
CROSS JOIN
selectname,address from t1 cross join t2;
N AM E AD D R ESS
Anu Delhi
Anu Mumbai
Anu Chennai
Baby Delhi
Baby Mumbai
Baby Chennai
Chintu Delhi
Chintu Mumbai
Chintu Chennai
SELF JOIN
selecta.name,b.address from t1 a,t2 b where a.id<b.id;
N AM E AD D R ESS
Anu Mumbai
Anu Chennai
Baby Mumbai
Baby Chennai
Chintu Chennai
THETA JOIN
selectname,address from t1 a,t2 b where a.id<=b.id;
N AM E AD D R ESS
Anu Delhi
Anu Mumbai
Anu Chennai
Baby Mumbai
Baby Chennai
Chintu Mumbai
Chintu Chennai
RESULT
EX:NO: 07
VIEW
DATE: 02.03.2023
AIM
E-R DIAGRAM
DESCRIPTION
VIEW CREATION
A view is nothing more than a SQL statement that is stored in the database
with an associated name. A view is actually a composition of a table in the form of a
predefined SQL query.
A view can contain all rows of a table or select rows from a table. A view can be
created from one or many tables which depends on the written SQL query to create a
view.
Creating Views
Database views are created using the CREATE VIEW statement. Views can be
created from a single table, multiple tables or another view.
To create a view, a user must have the appropriate system privilege according
to the specific implementation.
Syntax
CREATE VIEW view_name AS
SELECT column1, column2..... FROM table_name WHERE [condition];
Updating a View
A view can be updated under certain conditions which are given below −
Rows of data can be inserted into a view. The same rules that apply to the
UPDATE command also apply to the INSERT command.
Rows of data can be deleted from a view. The same rules that apply to the
UPDATE and INSERT commands apply to the DELETE command.
[[
Dropping Views
7. VIEW CREATION
TABLE CREATION
create table cu(id number(10)primary key,namevarchar(20),address varchar(20),
salary number(10));
Table created.
INSERTION
insert into custo values(1,’Ramesh’,’Chennai’,2000);
1 row(s) inserted.
ID N AM E AD D R E S S S AL AR Y
1 Ramesh Chennai 2000
2 Krishna Delhi 1500
3 Keerthi Mumbai 2000
4 Chaitali Indore 6500
VIEW
create view cu_view asselect name, address from cu;
N AM E AD D R E S S
Ramesh Chennai
Krishna Delhi
Keerthi Mumbai
Chaitali Indore
Hardik Bhopal
UPDATION
updatecu_view set address = bangalorewhere name = 'ramesh';
ID N AM E AD D R E S S S AL AR Y
1 Ramesh Bangalore 2000
2 Krishna Delhi 1500
3 Keerthi Mumbai 2000
4 Chaitali Indore 6500
DELETION
delete from cu_view where address = ‘delhi’;
ID N AM E AD D R E S S S AL AR Y
1 Ramesh Bangalore 2000
3 Keerthi Mumbai 2000
4 Chaitali Indore 6500
RESULT
EX:NO: 08
LOCKS
DATE: 13.03.2023
AIM
E-R DIAGRAM
DESCRIPTION
To lock a table using the MySQL LOCK TABLES Statement you need have the
TABLE LOCK and SELECT privileges.
These locks are used to solve the concurrency problems. There are two kinds of
MYSQL table locks −
READ LOCK − If you apply this lock on a table the write operations on it are
restricted. i.e., only the sessions that holds the lock can write into this table.
WRITE LOCK − This lock allows restricts the sessions (that does not possess
the lock) from performing the read and write operations on a table.
8.LOCKS
CREATION
create table stu(name varchar(3),mark int);
INSERT
insert into stu values('abi',50);
1 row(s) inserted.
LOCKING A TABLE
The following statement locks the stu table in exclusive mode but
does not wait if another user already has locked the table:
LOCK TABLE stu
IN EXCLUSIVE MODE
NO WAIT;
Statement processed.
The following statement locks the remote stu table that is accessible
through the database link remote:
LOCK TABLE stu@remote
IN SHARE MODE;
Connection description forremote database not found.
RESULT
EX:NO: 09
EXCEPTION HANDLING
DATE: 21.03.2023
AIM
To create a table for exception handling using PL/SQL.
E-R DIAGRAM
DESCRIPTION
Exception Handling
o System-defined Exceptions
o User-defined Exceptions
Syntax
DECLARE
<declarations section>
BEGIN
<executable command(s)>
EXCEPTION
<exception handling goes here >
WHEN exception1 THEN
exception1-handling-statements
WHEN exception2 THEN
exception2-handling-statements
WHEN exception3 THEN
exception3-handling-statements
........
WHEN others THEN
exception3-handling-statements
END;
PRE-DEFINED EXCEPTIONS:
Exception Description
9.EXCEPTION HANDLING
TABLE CREATION
INSERTION
insert into cu values(1,'Ramesh',23,'Chennai',2000);
1 row(s) inserted.
PREDEFINED FUNCTIONS
DECLARE
c_id cu.id%type := 8;
c_name cu.name%type;
c_addr cu.address%type;
BEGIN
SELECT name,address INTO c_name, c_addr FROM cu WHERE id = c_id;
DBMS_OUTPUT.PUT_LINE ('Name: '|| c_name);
DBMS_OUTPUT.PUT_LINE ('Address: ' || c_addr);
EXCEPTION
WHEN no_data_found THEN
dbms_output.put_line('No such customer!');
WHEN others THEN
dbms_output.put_line('Error!');
END;
No such customer!
PL/SQL procedure successfully completed.
EXCEPTION
DECLARE
c_id cu.id%type := 5;
c_name cu.name%type;
c_addr cu.address%type;
BEGIN
SELECT name,address INTO c_name, c_addr FROM cu WHERE id = c_id;
DBMS_OUTPUT.PUT_LINE ('Name: '|| c_name);
DBMS_OUTPUT.PUT_LINE ('Address: ' || c_addr);
EXCEPTION
WHEN no_data_found THEN
dbms_output.put_line('No such customer!');
WHEN others THEN
dbms_output.put_line('Error!');
END;
Name :Alex
Address :Paris
PL/SQL procedure successfully completed.
RESULT
EX:NO: 10
CURSOR
DATE: 31.03.2023
AIM
E-R DIAGRAM
DESCRIPTION
CURSOR
A cursor is a pointer to this context area. PL/SQL controls the context area
through a cursor. A cursor holds the rows (one or more) returned by a SQL statement.
The set of rows the cursor holds is referred to as the active set.
We can name a cursor so that it could be referred to in a program to fetch and
process the rows returned by the SQL statement, one at a time.
1. Open cursor
2. Fetch cursor
3. Close cursor
ATTRIBUTES
Attribute Description
10. CURSOR
TABLE CREATION
create table cu(id number(10),name varchar(20),address varchar(20),salary
number(20));
Table created.
INSERTION
insert into cu values(1,'Ramesh','Chennai',2000);
1 row(s) inserted.
ID N AM E AD D R E S S S AL AR Y
1 Ramesh Chennai 2000
2 Krishna Delhi 1500
3 Keerthi Mumbai 2000
4 Chaitali Indore 6500
CURSOR
declare
totalrows number(20);
begin
update cu set salary=salary+500;
ifsql%notfound then
dbms_output.put_line('No customers updated');
elsifsql%found then
totalrows:=sql%rowcount;
dbms_output.put_line(totalrows||'customers updated');
end if;
end;
/
5 customers updated
Statement processed.
ID N AM E AD D R E S S S AL AR Y
1 Ramesh Chennai 2500
2 Krishna Delhi 2000
3 Keerthi Mumbai 2500
4 Chaitali Indore 7000
EXPLICIT CURSOR
declare
c_idcu.id%type;
c_namecu.name%type;
c_addresscu.address%type;
cursorc_cu is select id,name,address from cu;
begin
openc_cu;
loop
fetchc_cu into c_id,c_name,c_address;
exit
whenc_cu%notfound;
dbms_output.put_line(c_id||''||c_name||''||c_address);
end loop;
closec_cu;
end;
/
ID N AM E AD D R E S S
1 Ramesh Chennai
2 Krishna Delhi
3 Keerthi Mumbai
4 Chaitali Indore
5 Hardik Bhopal
RESULT
EX:NO: 11
PROCEDURE AND FUNCTION
DATE: 06.04.2023
AIM
E-R DIAGRAM
DESCRIPTION
Procedure
The PL/SQL stored procedure or simply a procedure is a PL/SQL block which
performs one or more specific tasks. A procedure may or may not return any value.
The procedure contains a header and a body.
1. Header: The header contains the name of the procedure and the
parameters or variables passed to the procedure.
2. Body: The body contains a declaration section, execution section and
exception section similar to a general PL/SQL block.
Syntax
Function
A function must always return a value. A standalone function is created using
the CREATE FUNCTION statement.
Table created.
INSERTION
insert into cu values(1,'Ramesh','Chennai',2000);
1 row(s) inserted.
ID N AM E AD D R E S S S AL AR Y
1 Ramesh Chennai 2000
2 Krishna Delhi 1500
3 Keerthi Mumbai 2000
PROCEDURE
createor replace procedure pp(id in number,name in
varchar,addressinnumber,salary in number) is
begin
insert into cu values(id,name,Address,Salary);
end;
/
Procedure created.
begin
pp(4,'Chaitali','Indore',6500);
pp(5,'Hardik','Bhopal',8500);
dbms_output.put_line('Record inserted Successfully');
end;
/
Record inserted successfully
Statement processed.
ID N AM E AD D R E S S S AL AR Y
1 Ramesh Chennai 2000
2 Krishna Delhi 1500
3 Keerthi Mumbai 2000
4 Chaitali Indore 6500
declare
a number;
b number;
c number;
procedurefindmin(x in number, y in number, z out number) is
begin
if x< y then
z:=x;
else
z:=y;
end if;
end;
begin
a:=23;
b:=45;
findmin(a,b,c);
dbms_output.put_line('Minimum of (23,45):'||c);
end;
/
OUTPUT
Minimum of (23,45):23
Statement processed.
FUNCTION CREATION
declare
c number(2);
begin
c:=totalcustomer();
dbms_output.put_line('Total No.Of.Customers:'||c);
end;
/
OUTPUT
Total No.Of.Customers:3
Statement processed.
declare
a number;
b number;
c number;
functionfindmax(x in number, y in number) return number is z number;
begin
if x>y then
z:=x;
else
z:=y;
end if;
return z;
end;
begin
a:=23;
b:=45;
c:=findmax(a,b);
dbms_output.put_line('Maximum of (23,45):'||c);
end;
/
OUTPUT
Maximum of (23,45):45
Statement processed.
RESULT
EX:NO: 12
PACKAGES
DATE: 02.05.2022
AIM
E-R DIAGRAM
DESCRIPTION
PACKAGES
Packages are schema objects that groups logically related PL/SQL types,
variables, and subprograms.
A package will have two mandatory parts −
1. Package specification
2. Package body or definition
Package Specification
The specification is the interface to the package. It just DECLARES the types,
variables, constants, exceptions, cursors, and subprograms that can be referenced
from outside the package. In other words, it contains all information about the content
of the package, but excludes the code for the subprograms.
Package Body
The package body has the codes for various methods declared in the package
specification and other private declarations, which are hidden from the code outside
the package.
The package elements (variables, procedures or functions) are accessed with the
following syntax −
package_name.element_name;
12. PACKAGES
TABLE CREATION
create table cu(id number(10),name varchar(20),address varchar(20),salary
number(20));
Table created.
INSERTION
insert into cu values(1,'Ramesh','Chennai',2000);
1 row(s) inserted.
ID N AM E AD D R E S S S AL AR Y
1 Ramesh Chennai 2000
2 Krishna Delhi 1500
3 Keerthi Mumbai 2000
4 Chaitali Indore 6500
PACKAGE SPECIFICATION
Package created.
PACKAGE BODY
create or replace package body cust_sal as
procedurefind_sal(c_idcustomers.id%type) is
c_salcustomers.salary%type;
begin
select salary into c_sal from customers where id = c_id;
dbms_output.put_line('salary: '|| c_sal);
endfind_sal;
endcust_sal;
/
Package Body created.
declare
codecustomers.id%type := &cc_id;
begin
cust_sal.find_sal(code);
end;
/
RESULT