Académique Documents
Professionnel Documents
Culture Documents
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.
Run
Table created.
0.00 seconds
Run
1 row(s) inserted.
Run
1 row(s) inserted.
Run
1 row(s) inserted
Run
1 row(s) inserted
Displaying the values of department table
select * from dept;
Run
2 ece sristece
3 eee sristeee
4 civil sristcivil
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.
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.
Run
Query 2
Calculate hra,da,gross and net by using PL/SQL program.
Updating the values HRA,DA,GROSS,DEDUCTION,NET
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;
Query 3
Whenever salary is updated and its value becomes less than 5000 a trigger has to be raised
preventing the operation.
Run
Query 4
The percentage of hra and da are to be stored separately.
hra number(4),
da number(4)
);
Run
Table created.
Run
10 row(s) inserted.
Run
HRA DA
750 3750
550 2750
650 3250
650 3250
850 4250
900 4500
1000 5000
850 4250
680 3400
- -
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;
END IF;
END;
OUTPUT:
No data found..
Query 6
Run
Table created.
Generating empno automatically by using SEQUNCE
MINVALUE 1
START WITH 1
INCREMENT BY 1
CACHE 10
Run
Sequence created.
0.00 seconds
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
Run
EMPNO DEPTNO
1 -
2 -
3 -
4 -
Query 7
STEP1:
STEP 2:
DECLARE
ag number;
en varchar2(20);
BEGIN
ag := :old.age;
END;
DECLARE
Ag number(4);
a number(2);
b number;
BEGIN
FOR a in 1 .. b LOOP
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
Run
Displaying table
Run
Run
Run
AVG(BASIC)
7380
Query 11
Display the average salary department wise.
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.
Run
DEPTNO MAX(BASIC)
1 6500
2 7500
4 8500
3 10000
4 rows returned in 0.04 CSV
seconds Expor
Query 13:
4 rollback
Query 14:
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
NULL;
END;
END LOOP;
END;
SELECT sql_text,
executions
FROM v$sql
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.
1 row(s) updated.
0.00 seconds
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:
SELECT empname
FROM EMPLOY
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:
*******no output*********
output:
0 row(s) deleted.
Query19:
output:
output
EM ENO
rafi 201
brahmi 301
mahi 401
Query 20:
Query 21:
output
Query 22:
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.
QUERY 24:
The retirement age is 60 years. Display the retirement day of all the employees.
STEP 1 :
EMPNO DEPTNO EMPNAME BASIC HRA DA DEDUCTIONS GROSS NET DATE_OF_BIRTH AGE DATE_OF_JOIN
STEP 2:
DECLARE
Ag number;
a number;
b number;
name varchar2(10);
retire_age number;
BEGIN
FOR a in 1 .. b LOOP
retire_age:=60-ag;
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:
use :
use:
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.
declare
y number;
b number;
a number;
name VARCHAR2(10);
begin
FOR a in 1 .. b
LOOP
else
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:
declare
a number;
b number;
name VARCHAR2(10);
d number;
m char(4);
begin
FOR a in 1 .. b
loop
else
end if;
end loop;
end;
Output:
Find the departments where the salary of atleast one employee is more than 20000.
Step 1:
Step 2:
Step 3:
select deptname,empname
from emp,dept
output:
DEPTNAME EMPNAME
civil Mahi
Query 29:
Find the departments where the salary of all the employees is less than 20000.
Step1:
Step 2:
Step 3:
select deptname,empname
from emp,dept
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.
Query 31:
As a designer identify the views that may have to be supported and create views.
Creating a view:
SELECT empno,empname
FROM emp;
Output
View created.
Projecting a view:
output
EMPNO EMPNAME
201 rafi
301 brahmi
401 mahi
Droping a view
output:
View dropped.
Query:32
As a designer identify the PL/SQL procedures necessary and create them using cursors.
C:\oraclexe\app\oracle\product\10.2.0\server\BIN> sqlplus
Connected to:
3 r_emp c_emp%ROWTYPE;
4 begin
5 open c_emp;
6 loop
10 end loop;
11 close c_emp;
12 end;
13 /
Procedure created.
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.
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 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.
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
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
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.