CREATE TABLE contact_details(emp_id NUMBER(3),
first_name VARCHAR2(40),
contact_num NUMBER(10),
email VARCHAR(40),
Join_dt DATE DEFAULT SYSDATE
);
BEGIN
INSERT INTO contact_details VALUES(100,'Senthil', 9953090687, 'senthil.k@oracle.com',SYSDATE);
INSERT INTO contact_details VALUES(101,'Raja', 9953090688, 'raja.m@oracle.com',SYSDATE);
INSERT INTO contact_details VALUES(102,'Karthi', 9953090689, 'karthi.s@oracle.com',SYSDATE);
INSERT INTO contact_details VALUES(103,'Janani', 9953090690, 'janani.h@oracle.com',SYSDATE);
INSERT INTO contact_details VALUES(104,'Bharathi Raja', 9953090691, 'bharathi.raja@oracle.com',SYSDATE);
END;
/
SELECT * FROM contact_details;
CREATE OR REPLACE PROCEDURE contact_rep_sp
AS
/* *-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
Creating procedure to generate report for contact details
Author : Murugappan Annamalai
Date : 02-MAY-14 06.04.20.859955000 PM +05:30
*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-* */
v_count NUMBER(10);
v_report_name VARCHAR(30) := 'Contact Details';
v_header VARCHAR(300);
v_data VARCHAR2(1000);
CURSOR all_data
IS
SELECT *
FROM contact_detailS;
BEGIN
--getting total number of records in table
SELECT COUNT(*) INTO v_count FROM contact_details;
--printing header details
dbms_output.put_line('Report_name : '||v_report_name);
dbms_output.put_line('No of Records : '||v_count);
dbms_output.put_line('Generated Time : '||SYSTIMESTAMP);
--generating header
v_header := LPAD('Employee Id',10,' ')||' '||
RPAD('Name',20,' ')||' '||
RPAD('Contact Number',16,' ')||' '||
RPAD('Email id',25,' ')||' '||
RPAD('Hire Date',20,' ');
dbms_output.put_line('-----------------------------------------------------------------------------------------------------------');
--printing header
dbms_output.put_line(v_header);
dbms_output.put_line('-----------------------------------------------------------------------------------------------------------');
--cursor for loop to fetch data and to print
FOR req_data IN all_data
LOOP
v_data := LPAD(TO_CHAR(req_data.emp_id),10,' ')||' '||
RPAD(req_data.first_name,20,' ')||' '||
RPAD(TO_CHAR(req_data.contact_num),14,' ')||' '||
RPAD(req_data.email,25,' ')||' '||
RPAD(req_data.join_dt,20,' ');
--printing data
dbms_output.put_line(v_data);
END LOOP;
--end of cursor for loop
dbms_output.put_line('-----------------------------------------------------------------------------------------------------------');
EXCEPTION
WHEN others THEN
dbms_output.put_line('Error : '||SQLERRM);
END contact_rep_sp;
/
--Executing contact_rep_sp proc
BEGIN
contact_rep_sp;
END;
/
--sample output for your reference
--sample output end
DROP TABLE contact_details;
DROP PROCEDURE contac t_rep_sp;
No comments:
Post a Comment