Vous êtes sur la page 1sur 37

Query 1

Create two tables employee and department. Employee consists of columns empno, empname,
basic, hra, da, deductions, gross, net, date-of-birth. The calculation of hra,da are as per the rules of
the college. Apply the Constraints. Initially only the few columns (essential) are to be added. Add
the remaining. Add constraint that basic should not be less than 5000. hra should not be less than
10% of basic and da should not be less than 50% of basic.

Creating Department table


create table dept(deptno number(10),deptname varchar(20),primary key(deptno));

Run

Table created.

0.00 seconds

Inserting values into dept table


insert into dept values(1,'cse','sristcse');

Run

1 row(s) inserted.

insert into dept values(2,'ece','sristece');

Run

1 row(s) inserted.

insert into dept values(3,'eee','sristeee');

Run

1 row(s) inserted

insert into dept values(4,'civil','sristcivil');

Run

1 row(s) inserted
Displaying the values of department table
select * from dept;

Run

DEPTNO DEPTNAME DESCRI PTION


1 cse sristcse

2 ece sristece

3 eee sristeee

4 civil sristcivil

4 rows returned in 0.04 seconds CSV Export

Creating Employe table


create table employ(empno number(5),deptno number(7),empname varchar(20),basic
number(10)NOT NULL,hra number(4),da number(4),deductions number(4),date_of_birth date,gross
number(8),net number(10),primary key(empno),foreign key(deptno)references
dept(deptno),check(basic>=5000));

Run

Table created.
Inserting values into employ table
insert into employ(empno,deptno,empname,basic,date_of_birth) values(501,1,'azeema',5500,'22-
mar-1998');

Run

1 row(s) inserted.

insert into employ(empno,deptno,empname,basic,date_of_birth) values(502,1,'priyanka',6500,'21-


mar-1998');

Run

1 row(s) inserted.
insert into employ(empno,deptno,empname,basic,date_of_birth) values(503,2,'swathi',7500,'21-
aug-1998');

Run

1 row(s) inserted.
insert into employ(empno,deptno,empname,basic,date_of_birth) values(508,2,'mounika',6500,'20-
aug-1998');

Run

1 row(s) inserted.
insert into employ(empno,deptno,empname,basic,date_of_birth) values(510,3,'rehana',8500,'12-
aug-1998');

Run

1 row(s) inserted.
insert into employ(empno,deptno,empname,basic,date_of_birth) values(521,3,'shailaja',10000,'2-
nov-1998');

Run

1 row(s) inserted.
insert into employ(empno,deptno,empname,basic,date_of_birth) values(540,4,'jagadeesh',8500,'1-
nov-1998');

Run

1 row(s) inserted.
insert into employ(empno,deptno,empname,basic,date_of_birth) values(541,4,'praveen',6800,'1-
nov-1998');

Run

1 row(s) inserted.

Displaying the values of employ table


select * from employ;

Run

EMPN DEPTN EMPNA BASI HR D DEDUCTIO DATE_OF_BIR GROS NE


O O ME C A A NS TH S T
503 2 swathi 7500 - - - 21-AUG-98 - -
501 1 azeema 5500 - - - 22-MAR-98 - -
502 1 priyanka 6500 - - - 21-MAR-98 - -
508 2 mounika 6500 - - - 20-AUG-98 - -
510 3 rehana 8500 - - - 12-AUG-98 - -
511 3 aruna 9000 - - - 02-AUG-98 - -
521 3 shailaja 10000 - - - 02-NOV-98 - -
540 4 jagadeesh 8500 - - - 01-NOV-98 - -
541 4 praveen 6800 - - - 01-NOV-98 - -
9 rows returned in CSV
0.01 seconds Export

Query 2
Calculate hra,da,gross and net by using PL/SQL program.
Updating the values HRA,DA,GROSS,DEDUCTION,NET

update employ set hra=basic*0.10;

Run

9 row(s) updated.
update employ set da=basic*0.50;

Run

9 row(s) updated.
update employ set gross=basic+da+hra;

Run

9 row(s) updated.
update employ set deductions=0.02*gross;

Run

9 row(s) updated.
update employ set net=gross-deductions;

Run

9 row(s) updated.
Displaying the values of employ table
select * from employ;

EMPN DEPTN EMPNA BASI HR D DEDUCTIO DATE_OF_BIR GROS NE


O O ME C A A NS TH S T
375 1176
503 2 swathi 7500 750 240 21-AUG-98 12000
0 0
275
501 1 azeema 5500 550 176 22-MAR-98 8800 8624
0
325 1019
502 1 priyanka 6500 650 208 21-MAR-98 10400
0 2
325 1019
508 2 mounika 6500 650 208 20-AUG-98 10400
0 2
425 1332
510 3 rehana 8500 850 272 12-AUG-98 13600
0 8
450 1411
511 3 aruna 9000 900 288 02-AUG-98 14400
0 2
500 1568
521 3 shailaja 10000 1000 320 02-NOV-98 16000
0 0
425 1332
540 4 jagadeesh 8500 850 272 01-NOV-98 13600
0 8
340 1066
541 4 praveen 6800 680 218 01-NOV-98 10880
0 2
9 rows returned in
CSV Export
0.00 seconds

Query 3
Whenever salary is updated and its value becomes less than 5000 a trigger has to be raised
preventing the operation.

insert into employ(empno,deptno,empname,basic,date_of_birth) values(545,4,'jagadeesh',4000,'1-


nov-1998');

Run

ORA-02290: check constraint (SYSTEM.SYS_C004060) violated

Query 4
The percentage of hra and da are to be stored separately.

Creating a table empp2


create table empp2(

hra number(4),

da number(4)
);
Run

Table created.

Transfer values from old table employ to new table empp2


insert into empp2 select hra,da from employ;

Run

10 row(s) inserted.

Displaying empp2 table


select * from empp2;

Run

HRA DA
750 3750
550 2750
650 3250
650 3250
850 4250
900 4500
1000 5000
850 4250
680 3400
- -

10 rows returned in 0.02 CSV


seconds Export

Query 5
DECLARE

DAID empp.da%TYPE;

BASVAL empp.basic%TYPE;

vda number(5);

vbas NUMBER(5);

BEGIN
SELECT da,basic into DAID,BASVAL FROM empp WHERE da=basic;

IF SQL%FOUND THEN

VDA :=DAID;

VBAS:=BASVAL;

VDA:= VDA+DAID;

DBMS_OUTPUT.PUT_LINE('Number of rows: ' || SQL%ROWCOUNT);

UPDATE EMPP SET BASIC = VDA WHERE DA=VDA;

DBMS_OUTPUT.PUT_LINE(' '||'DA IS MERGED INTO BASIC');

END IF;

END;

OUTPUT:

No data found..

Query 6

Empno should be unique and has to be generated automatically


Creating a table
create table employe(empno number(5),deptno number(7);

Run

Table created.
Generating empno automatically by using SEQUNCE

CREATE SEQUENCE seq

MINVALUE 1

START WITH 1

INCREMENT BY 1

CACHE 10

Run
Sequence created.

0.00 seconds

INSERT INTO employe(empno)VALUES(seq.nextval)

Run

1 row(s) inserted.
INSERT INTO employe(empno)VALUES(seq.nextval)

Run

1 row(s) inserted.
INSERT INTO employe(empno)VALUES(seq.nextval)

Run

1 row(s) inserted.

Displaying table

select * from employe;

Run

EMPNO DEPTNO
1 -
2 -
3 -
4 -

4 rows returned in 0.02 CSV


seconds Export

Query 7
STEP1:

UPDATE THE DATE_OF_BIRTH COLUMN:

UPDATE empp SET date_of_birth='2-may-1932' WHERE empno=2;

STEP 2:

Creating a TRIGGER for a retiring employee

CREATE TRIGGER retire_60 after UPDATE ON empp

FOR EACH ROW


WHEN (old.age > 60)

DECLARE

ag number;

en varchar2(20);

BEGIN

ag := :old.age;

select empname into en from empp where age=ag;

dbms_output.put_line('THE EMPLOYEE'|| en ||' WILL RETIRE IN THIS MONTH');

END;

Updating table with the age:

DECLARE

Ag number(4);

a number(2);

b number;

BEGIN

select count(*)into b from empp;

FOR a in 1 .. b LOOP

select round(MONTHS_BETWEEN(to_date(date_of_birth,'DD-MON-YY'),sysdate)/12,1) into Ag


from empp where empno = a;

UPDATE empp SET age = ag WHERE empno=a;

END LOOP;

end;

output:
Query 8
The default value for date-of-birth is 1 jan, 1970.

Creating table
create table empployee(empno number(5),deptno number(7),date_of_birth date DEFAULT date
'1999-1-1');

Run

Table created.
Inserting values
insert into empployee(empno,deptno)values(1,2);

Run

1 row(s) inserted

Displaying table

select * from employee;

Run

EMPNO DEPTNO DAT E_OF_BI RTH


1 2 01-JAN-99

insert into empployee(empno,deptno)values(1,3);

Displaying table

select * from employee

EMPNO DEPTNO DAT E_OF_BI RTH


1 2 01-JAN-99
1 3 01-JAN-99
Query 9
Display the information of the employees and departments with description of the fields.

select employ.empname,dept.deptname,dept.description from employ inner join dept on


employ.deptno=dept.deptno;

Run

EMPNAME DEPTNAME DESCRI PTION


swathi ece sristece
azeema cse sristcse
priyanka cse sristcse
mounika ece sristece
rehana eee sristeee
aruna eee sristeee
shailaja eee sristeee
jagadeesh civil sristcivil
praveen civil sristcivil
jagadeesh civil sristcivil
10 rows returned in 0.01
seconds

select empno,empname,deptno,basic,date_of_birth from employ;

Run

MPNO EMPNAME DEPTNO BASIC DATE_OF_BIRTH


503 swathi 2 7500 21-AUG-98
501 azeema 1 5500 22-MAR-98
502 priyanka 1 6500 21-MAR-98
508 mounika 2 6500 20-AUG-98
510 rehana 3 8500 12-AUG-98
511 aruna 3 9000 02-AUG-98
521 shailaja 3 10000 02-NOV-98
540 jagadeesh 4 8500 01-NOV-98
541 praveen 4 6800 01-NOV-98
545 jagadeesh 4 5000 01-NOV-98
10 rows returned in 0.00
CSV Export
seconds
Query 10
Display the average salary of all the departments

Displaying the average salary


select avg(basic) from employ;

Run

AVG(BASIC)
7380

1 rows returned in 0.00 CSV


seconds Exp

Query 11
Display the average salary department wise.

select avg(basic) from employ group by deptno;

Run

AVG(BASIC)
6000
7000
6766.66666666666666666666666666666666667
9166.66666666666666666666666666666666667

CSV
4 rows returned in 0.00 seconds Export

Query 12
Display the maximum salary of each department and also all departments put together.

select deptno,max(basic) from employ group by deptno;

Run

DEPTNO MAX(BASIC)

1 6500

2 7500

4 8500

3 10000
4 rows returned in 0.04 CSV
seconds Expor

Query 13:

Commit the changes whenever required and rollback if necessary.

Step 1: Remove the Auto commit checkbox

Commit will work as a save or commit the data_base

Roll back will work as undo like action

Do the following to check how commit and rollback will work:

1 select * from empp;


output:

EMPNO DEPTNO EMPNAME BASI C HRA DA DEDUCTIONS GROSS NET


1 1 Guru 10000 1000 4500 310 15500 15190
2 1 Tulasi 20000 1000 9000 600 30000 29400

2 delete from empp where empno=2;


3 rollback

4 select * from empp;


output:

EMPNO DEPTNO EMPNAME BASI C HRA DA DEDUCTIONS GROSS NET


1 1 Guru 10000 1000 4500 310 15500 15190
2 1 Tulasi 20000 1000 9000 600 30000 29400

IF u involve the commit in between step 2 and 3 in the above sequence

rollback cannot work

1 select * from empp;


output:

EMPNO DEPTNO EMPNAME BASI C HRA DA DEDUCTIONS GROSS NET


1 1 Guru 10000 1000 4500 310 15500 15190
2 1 Tulasi 20000 1000 9000 600 30000 29400

2 delete from empp where empno=2;


3 commit

4 rollback

5 select * from empp;


output:

Query 14:

Use substitution variables to insert values repeatedly.

Step 1: First run the below code :

DECLARE

l_dummy dual.dummy%TYPE;

BEGIN

FOR i IN 1 .. 10 LOOP

BEGIN

EXECUTE IMMEDIATE 'SELECT dummy FROM dual WHERE dummy = ''' || TO_CHAR(i) || ''''

INTO l_dummy;

EXCEPTION

WHEN NO_DATA_FOUND THEN

NULL;

END;
END LOOP;

END;

Step 2: Follow to run the below code

SELECT sql_text,

executions

FROM v$sql

WHERE INSTR(sql_text, 'SELECT dummy FROM dual WHERE dummy') > 0

AND INSTR(sql_text, 'sql_text') = 0

AND INSTR(sql_text, 'DECLARE') = 0

ORDER BY sql_text

Output:

Query 15:

Assume some of the employees have given wrong information about date-of-birth. Update the
corresponding tables to change the value.

update employ set date_of_birth=date '1990-1-1' where empno=1;

1 row(s) updated.

0.00 seconds

select *from employ;


EMPN DEPTN EMPNA BASI HR D DEDUCTIO DAT E_OF_BI R GROS NE
O O ME C A A NS TH S T
1 2 Hari 5000 - - 500 02-JAN-90 - -
2 2 Hram 8000 - - 500 03-MAY-88 - -
3 3 Ram 9000 - - 500 03-MAY-87 - -

Query 16:

Find the employees whose salary is between 5000 and 10000 but not exactly 7500.

select empname,basic from employ where basic BETWEEN 5000 AND 10000 OR basic!=7500;

EMPNAME BASI C
hari 5000
hram 8000
ram 9000

Query 17:

Find the employees whose name contains en.

SELECT empname

FROM EMPLOY

WHERE empname LIKE 'ra%';

EMPNAME
Ram
1 rows returned in 0.00
seconds

Query 18:
Try to delete a particular deptno. What happens if there are employees in it and if there are no
employees.

Before:
EMPNO DEPTNO EMPNAME BASIC HRA DA DEDUCTIONS GROSS NET
1 1 Guru 10000 1000 4500 310 15500 15190
delete from empp where deptno=1;

output:
1 row(s) deleted.

After:

select * from empp;


output:

*******no output*********

delete from empp where deptno=1;

output:
0 row(s) deleted.

Query19:

Create alias for columns and use them in queries.

select * from emp;

output:

EMPN DEPTN EMPNA BASI HR DEDUCTIO DAT E_OF_BI R GROS NE


O O ME C A DA NS TH S T
100 270 950
201 1 Rafi 6000 194 - 9700
0 0 6
100 225 808
301 2 Brahmi 5000 165 11-MAY-10 8250
0 0 5
401 3 Mahi 8000 - - - - - -

Creating aliases for columns

SELECT empname AS em, empno AS eno FROM emp;

output

EM ENO
rafi 201
brahmi 301
mahi 401

Query 20:

List the employees according to ascending order of salary.

select * from employ ORDER BY basic;

EMPN EMPNA BASI HR D DEDUCTIO DAT E_OF_BI R GROS NE DEPTN


O ME C A A NS TH S T O
1 hari 5000 - - 500 02-JAN-90 - - 1
2 hram 8000 - - 500 03-MAY-88 - - 2

Query 21:

List the employees according to ascending order of salary in each department.

select * from emp ORDER BY deptno;

output

EM P DEPT EM PNA B ASI HR D DEDUCTI DATE_OF_BI GRO NE


NO NO ME C A A ONS RTH SS T
270
201 1 Rafi 6000 1000 194 - 9700 9506
0
225
301 2 Brahmi 5000 1000 165 11-MAY-10 8250 8085
0
401 3 Mahi 8000 - - - - - -

3 rows returned in 0.00 CSV


seconds Export

Query 22:

Use && wherever necessary.

select * from emp;

EMP DEPT EMPN BAS HR D DEDUCTI DATE_OF_ GRO NE YE


NO NO AME IC A A ONS BIRTH SS T AR
100 27 950
201 1 rafi 6000 194 - 9700 2000
0 00 6
100 22 808
301 2 brahmi 5000 165 11-MAY-10 8250 -
0 50 5
401 3 mahi 8000 - - - - - - -

select * from emp

where deptno=1 AND da=2800;

output:

no data found.

Query 23:
Amount 6000 has to be deducted as CM relief fund in a particular month which has to be accepted
as input from the user. Whenever the salary becomes negative it has to be maintained as 1000
and the deduction amount for those employees is reduced appropriately.
select * from empp;

Pl/sql program:

declare
cm_fund number;
net_amt number;
a number;
b number;
begin
cm_fund:=6000;
select count(*)into b from empp;
FOR a in 1 .. b LOOP
select net into net_amt from empp where empno = a;
net_amt:=net_amt-cm_fund;
if(net_amt<0) then
net_amt:=1000;
update empp set net=net_amt where empno=a;
dbms_output.put_line(' CM relief fund of rupees'||net_amt||' is deducted from ur a/c
in the current month');
else
update empp set net=net_amt where empno=a;
dbms_output.put_line(' CM relief fund of rupees'||net_amt||' is deducted from ur a/c
in the current month');
end if;
END LOOP;
end;
Output:
CM relief fund of rupees9190 is deducted from ur a/c in the current month
CM relief fund of rupees23400 is deducted from ur a/c in the current month
CM relief fund of rupees23400 is deducted from ur a/c in the current month
CM relief fund of rupees2085 is deducted from ur a/c in the current month
CM relief fund of rupees2085 is deducted from ur a/c in the current month

Statement processed.

Select * from empp;

QUERY 24:

The retirement age is 60 years. Display the retirement day of all the employees.

STEP 1 :

select * from empp;


OUTPUT :

EMPNO DEPTNO EMPNAME BASIC HRA DA DEDUCTIONS GROSS NET DATE_OF_BIRTH AGE DATE_OF_JOIN

1 1 guru 10000 1000 4500 310 15500 15190 01-JAN-70 55 01-JAN-12


2 201 RAMESH 20000 1000 9000 600 30000 29400 02-MAY-75 60 01-JUN-10
3 301 RAMESH 20000 1000 9000 600 30000 29400 01-JAN-70 55 01-JAN-12
4 301 bhrami 5000 1000 2250 165 8250 8085 02-JUN-80 65 01-JUN-10
5 301 bb 5000 1000 2250 165 8250 8085 02-JUN-70 55 15-DEC-11

STEP 2:

DECLARE

Ag number;

a number;

b number;

name varchar2(10);

retire_age number;
BEGIN

select count(*) into b from empp;

FOR a in 1 .. b LOOP

select empname into name from empp where empno=a;

select AGE into Ag from empp where empno = a;

retire_age:=60-ag;

if(retire_age=0) then

dbms_output.put_line(' The employee '||name||' will retire in This current Year');

else if(retire_age>0) then

dbms_output.put_line(' The employee '||name||' will retire in '|| retire_age || ' years');

else

dbms_output.put_line(' The employee '||name||' not yet retired in the current year');

end if;

END IF;

END LOOP;

end;

output:
The employee guru will retire in 5 years
The employee RAMESH will retire in This current Year
The employee RAMESH will retire in 5 years
The employee bhrami not yet retired in the current year
The employee bb will retire in 5 years

Statement processed.

QUERY 25:
If salary of all the employees is increased by 10% every year, what is the salary of all the
employees at retirement time.
STEP 1:
Alter table empp by adding a column date_of_join :
Use:

alter table empp add date_of_join date;

use :

update empp set date_of_join = '15-dec-2011'

use:

select * from empp;

PL/SQL PROGRAM:

DECLARE
n number;
b number;
a number;
amt number;
name VARCHAR(10);
net number;
BEGIN
select count(*) into b from empp;
FOR a in 1 .. b
LOOP
select basic into amt from empp where empno=a;
select net into net from empp where empno=a;
select empname into name from empp where empno=a;
select (age-(EXTRACT(year FROM date_of_join)-EXTRACT(YEAR FROM
DATE_OF_birth))) into n from empp where empno=a;
amt:=amt*0.1*n;
amt:=net+amt;
dbms_output.put_line('AT time of retirement '||name ||' will get an amount
of salary in rupees '|| amt);
END LOOP;
END;
Output:
AT time of retirement guru will get an amount of salary in rupees
28190
AT time of retirement RAMESH will get an amount of salary in
rupees 79400
AT time of retirement RAMESH will get an amount of salary in
rupees 55400
AT time of retirement bhrami will get an amount of salary in rupees
25585
AT time of retirement bb will get an amount of salary in rupees 15085

Query26:
Find the employees who are born in leap year.

Check the values of date_of_birth field:


select * from empp;

Run the below pl/sql program:

declare

y number;
b number;

a number;

name VARCHAR2(10);

begin

select count(*)into b from empp;

FOR a in 1 .. b

LOOP

SELECT empname into name from empp where empno=a;

select EXTRACT(YEAR FROM date_of_birth) into y from empp where empno=a;

if y mod 4 =0 and y mod 100 <>0 or y mod 400=0 then

dbms_output.put_line('The Employee '|| name || ' is born in a leap year');

else

dbms_output.put_line('The Employee '|| name || ' is not born in a leap year');

end if;

end loop;

end;

output:
The Employee guru is not born in a leap year
The Employee RAMESH is not born in a leap year
The Employee RAMESH is not born in a leap year
The Employee bhrami is born in a leap year

Statement processed.

Query 27:

Find the employees who are born on feb 29.

select * from empp;


Next run the below pl/sql program:

declare

a number;

b number;

name VARCHAR2(10);

d number;

m char(4);

begin

select count(*)into b from empp;

FOR a in 1 .. b

loop

select empname into name from empp where empno=a;

select EXTRACT(day FROM date_of_birth) into d from empp where empno=a;

select EXTRACT(month FROM date_of_birth) into m from empp where empno=a;

if d = 29 and m='feb' then

dbms_output.put_line('The employee '||name ||'is born in 29 feb');

else

dbms_output.put_line('The employee '||name ||'is not born in 29 feb');

end if;

end loop;

end;

Output:

The employee guruis not born in 29 feb


The employee RAMESHis not born in 29 feb
The employee RAMESHis not born in 29 feb
The employee bhramiis not born in 29 feb
Statement processed.
Query 28:

Find the departments where the salary of atleast one employee is more than 20000.

Step 1:

select * from dept

DEPTNO DEPTNAM E DESCRIPTION


1 cse cse avishkar
2 me mechanical dept
3 civil mechanical dept

Step 2:

select * from emp

EMP DEPT EMPN BAS HR D DEDUCTI DATE_OF_ GRO NE YE


NO NO AME IC A A ONS BIRTH SS T AR
100 27 950
201 1 rafi 6000 194 - 9700 2000
0 00 6
100 22 808
301 2 brahmi 5000 165 11-MAY-10 8250 -
0 50 5
401 3 mahi 21000 - - - - - - -

Step 3:

select deptname,empname

from emp,dept

where emp.deptno=dept.deptno AND basic>20000;

output:

DEPTNAME EMPNAME
civil Mahi
Query 29:

Find the departments where the salary of all the employees is less than 20000.

Step1:

select * from dept

DEPTNO DEPTNAM E DESCRIPTION


1 cse cse avishkar
2 me mechanical dept
3 civil mechanical dept

Step 2:

select * from emp

EMP DEPT EMPN BAS HR D DEDUCTI DATE_OF_ GRO NE YE


NO NO AME IC A A ONS BIRTH SS T AR
100 27 950
201 1 rafi 6000 194 - 9700 2000
0 00 6
100 22 808
301 2 brahmi 5000 165 11-MAY-10 8250 -
0 50 5
401 3 mahi 21000 - - - - - - -

Step 3:

select deptname,empname

from emp,dept

where emp.deptno=dept.deptno AND basic<20000;

output:

DEPTNAM E EM PNAME
Cse Rafi
Me Brahmi
2 rows returned in 0.00
seconds
QUERY 30:

On first January of every year a bonus of 10% has to be given to all the employees. The amount
has to be deducted equally in the next 5 months. Write procedures for it.

alter table empp add current_status varchar(10);

UPDATE EMPP SET current_status='WORKING' WHERE EMPNO=1;

UPDATE EMPP SET current_status='RELIEVED' WHERE EMPNO=2;

UPDATE EMPP SET current_status='WORKING' WHERE EMPNO=3;

UPDATE EMPP SET current_status='RELIEVED' WHERE EMPNO=4;

UPDATE EMPP SET current_status='WORKING' WHERE EMPNO=3;

select * from empp;

Query 31:

As a designer identify the views that may have to be supported and create views.

Creating a view:

CREATE VIEW details AS

SELECT empno,empname

FROM emp;

Output

View created.

Projecting a view:

select * from details;

output
EMPNO EMPNAME
201 rafi
301 brahmi
401 mahi

Droping a view

drop VIEW details;

output:

View dropped.

Query:32

As a designer identify the PL/SQL procedures necessary and create them using cursors.

Go to start menu RUN type cmd

C:\Documents and Settings\Administrator>cd C:\oraclexe\app\oracle\product\10.2.0\server\BIN\

Type sqlplus at command prompt:

C:\oraclexe\app\oracle\product\10.2.0\server\BIN> sqlplus

SQL*Plus: Release 10.2.0.1.0 - Production on Wed Apr 22 11:37:13 2015

Copyright (c) 1982, 2005, Oracle. All rights reserved.

Enter user-name: system

Enter password: ******

Connected to:

Oracle Database 10g Express Edition Release 10.2.0.1.0 - Production

SQL> create or replace procedure p_printEmps is

2 cursor c_emp is select * from employee;

3 r_emp c_emp%ROWTYPE;

4 begin

5 open c_emp;

6 loop

7 fetch c_emp into r_emp;

8 exit when c_emp%NOTFOUND;


9 DBMS_OUTPUT.put_line(r_emp.empname);

10 end loop;

11 close c_emp;

12 end;

13 /

Procedure created.

SQL> call p_printEmps();

Call completed.

Query:33

Use appropriate Visual programming tools like oracle forms and reports, visual basic etc to create
user interface screens and generate reports.

Steps to Create Report in Oracle Reports Builder 10g


In Oracle Reports, you have two options for building a paper report. The first one is to use the wizards
and editors in Reports Builder. The second one is to define the data model and/or layout for your paper report in
XML.
Here we will discuss the steps to build a paper report using the Report Wizard.

Step 1: Invoking Reports Builder and the Report Wizard

When you invoke Reports Builder, the Welcome dialog box gives you the option of using the Wizard
to build a new report. The Report Wizard provides an easy step-by-step interface to create a new report.
The Report Wizard opens with a Welcome page. To suppress this page, clear the Display at startup check box.
You can reinstate this page in the same way as the Welcome dialog box in Reports Builder; select the Wizard
tab in the Preferences dialog box and then select Report Wizard Welcome Page.
Each page of the Report Wizard asks you for information to help you create your initial report. Step through the
wizard pages, selecting Next and Back, until you are satisfied with the initial information that you have entered.
On the last page, select Finish.
Welcome to Reports Builder

Report Wizard
Step 2: Choosing the Layout Type

Here you have to specify the type of layout you want the Wizard to generate. The available options are:
Web and Paper Layout
Web Layout only
Paper Layout only

Report Layout Type


Step 3: Choosing a Report Style
This page of the Report Wizard shows the various styles of reports. Select Tabular and then click Next.

Report Style
Step 4: Selecting the Data Source Type

Next, you have to define the data source type for your report. Through the implementation of the
Pluggable Data Source (PDS) feature in Oracle Reports, the data for your report can come from any source you
choose. Reports Builder provides interface definitions that act as a translator between Reports Builder and a
PDS by redefining Reports Builders requests in terms your data source uses.
Oracle Express Server, OLAP, JDBC, Text and XML pluggable data sources are shipped with Oracle Reports.
You can also define your own data source.

Data Source Type


Step 5: Building a Query using Query Builder

Building your query with the Query Builder GUI saves you time and increases the ease of use for
developers not familiar with building SQL statements or with the application tables.
To build a query using Query Builder:
1. Select Query Builder from the Query page in the Report Wizard.
2. Enter your username, password, and alias in the Connect dialog box that appears if you have not already
connected to the database.
3. Select the data tables to build the query.
4. Click Include. The tables appear in the selection area.
5. Click Close to close the Select Data Tables window.
6. In each table, double-click the column names that you want in the query, or use the check boxes. To select
all columns, double-click the Table title bar.
7. Click OK.
Query Builder copies the query syntax into the Report Wizard. You can modify the query by reentering Query
Builder or by modifying the SQL query statement text.
Note: If you prefer to write your own SQL statement, enter the syntax directly in the SQL query statement area
of the Query page. Alternatively, you can import the contents of a file by clicking Import SQL Query.

Query Builder

Step 6: Selecting Displayed Fields

In the Field page, select each field from the Available Fields list and click >. The selected fields move
to the Displayed Fields list. To display all fields, click >>.
You can alter the sequence of displayed fields by dragging one field above or below another in the list. The
sequence of fields in this list determines how the fields appear in the report output. In a tabular report, the fields
appear in sequence from left to right across the page.
Fields that remain in the Available Fields list are available for you to reference in your report definition as
hidden fields or in PL/SQL trigger code.
In the report output, the user sees only those fields that you transfer to the Displayed Fields list.
Displayed Fields
Step 7: Totals and Labels

In the next two pages of the Report Wizard, you can create totals based on any of the displayed fields
and modify the labels and width of the displayed fields.
Totals: Standard SQL aggregate functions are provided for creating totals in your report.

Total Fields
Labels: The field label is displayed on one or more lines in the report output. In a tabular report, the labels
appear above the field values.
If the initial label is wider than the field, Reports Builder allows enough space for the label, or displays it on
multiple lines.
If you increase the number of characters in the label text in the reentrant Wizard, the label can appear
truncated in the report output.
Labels

Step 8: Selecting a Report Template

Report Templates enforce corporate standards as well as create professional-looking paper reports
easily.
Select a template from the list of predefined template names. In a template, the fonts, styles, and colors
are already selected for designated objects. A variety of templates are available with the standard Reports
installation.
To select a predefined template:
1. Select the Predefined Template option button, if it is not already selected.
2. Select a template from the Template list.
3. Click Finish.

Report Template
Step 9: Viewing the Paper Report Output

When you finish creating your report in the Report Wizard, the output appears in the Paper Design view of the
Report Editor.
Magnifying the Output
The Paper Design view contains a Magnify tool in the vertical toolbar. This provides a view of the area of layout
you want to see. You can also use the View menu to magnify or reduce the size of the output. Select View >
Zoom to see your options.
Viewing Different Pages
The Paper Design toolbar contains four buttons, and the specific page option, with which you can scroll through
the pages of your report.

Report Output
Step 10: Saving the Report Definition

Remember to save the report frequently by selecting Save in the toolbar, or by using the File > Save
menu option. The recommended format for storing paper reports is with an .rdf extension.
If you want to make a copy of the report definition in a different filename, use the menu option File > Save As.
There is no toolbar button for the Save As option.

Vous aimerez peut-être aussi