0% found this document useful (0 votes)
7 views4 pages

EXp 6

The document outlines SQL procedures for managing a CUSTOMER table, including inserting, updating, deleting, and selecting customer records. It also includes functions for calculating the total number of customers and the percentage of marks for a student. Each procedure and function is accompanied by execution examples demonstrating their usage.

Uploaded by

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

EXp 6

The document outlines SQL procedures for managing a CUSTOMER table, including inserting, updating, deleting, and selecting customer records. It also includes functions for calculating the total number of customers and the percentage of marks for a student. Each procedure and function is accompanied by execution examples demonstrating their usage.

Uploaded by

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

STORED PROCEDURE:

BASE TABLE:

CREATE TABLE CUSTOMER (NAME VARCHAR2(20),GENDER


VARCHAR2(7),ADDRESS VARCHAR2(100));

PROCEDURE For Insert customer

CREATE OR REPLACE PROCEDURE INSERTcustomer (


p_name CUSTOMER.NAME%TYPE,
p_gender CUSTOMER.GENDER%TYPE,
p_address CUSTOMER.ADDRESS%TYPE)
IS
BEGIN
INSERT INTO CUSTOMER (NAME, GENDER, ADDRESS)
VALUES (p_name, p_gender, p_address);
COMMIT;
END;

EXECUTION
execute insertcustomer('ramesh','male','nagaptnam');

PROCEDURE For Update customer

CREATE OR REPLACE PROCEDURE UPDATEcustomer (


p_name IN CUSTOMER.NAME%TYPE,
p_gender IN CUSTOMER.GENDER%TYPE,
p_address IN CUSTOMER.ADDRESS%TYPE)
IS
BEGIN
UPDATE CUSTOMER SET GENDER=p_gender,
ADDRESS=p_address WHERE NAME=p_name;
COMMIT;
END;
EXECUTION:

execute updatecustomer('raja','female','chennai');

PROCEDURE For Delete customer:

CREATE OR REPLACE PROCEDURE DELETEcustomer(


p_name IN CUSTOMER.NAME%TYPE)
IS
BEGIN
DELETE FROM CUSTOMER WHERE NAME=p_name;
END;

EXECUTION:

execute deletecustomer('raja');

PROCEDURE For Select customer

CREATE OR REPLACE PROCEDURE SELECTcustomer (


p_name IN CUSTOMER.NAME%TYPE)
IS
p_address varchar(20);
BEGIN
SELECT ADDRESS into p_address FROM CUSTOMER WHERE
NAME=p_name;
dbms_output.put_line('pname='||p_name);
dbms_output.put_line('p_address='||p_address);
END;

EXECUTION:

execute selectcustomer('raja');
FUNCTION PROGRAM

FUNCTION for Finding total customer:

CREATE OR REPLACE FUNCTION totalCustomers


RETURN number IS
total number(2) := 0;
BEGIN
SELECT count(*) into total
FROM cus;
RETURN total;
END;

EXECUTION:

select totalcustomers() from dual;


(OR)
DECLARE
c number(2);
BEGIN
c := totalCustomers();
dbms_output.put_line('Total no. of Customers: ' || c);
END;

FUNCTION for finding percentage Mark

CREATE OR REPLACE FUNCTION pmark(name char)


RETURN number
IS
m1 number(3);
m2 number(3);
m3 number(3);
m4 number(3);
total number(3);
percentage number(3);
begin
select mark1 into m1 from stdmark where sname=name;
select mark2 into m2 from stdmark where sname=name;
select mark3 into m3 from stdmark where sname=name;
select mark4 into m4 from stdmark where sname=name;
total := m1 + m2 + m3 + m4;
percentage := total / 4;
return percentage;
end;

EXECUTION:

select pmark('ramesh') from dual;


(OR)
DECLARE
p number(2);
BEGIN
p := pmark('ramesh');
dbms_output.put_line('percentage of ramesh is: ' || p);
END;

You might also like