PRACTICAL NO.

1
AIM: To apply insertion, deletion, modification, database operation and queries on the table. SQL*Plus: Release 9.0.1.0.1 - Production on Thu Sep 10 09:54:38 2009 (c) Copyright 2001 Oracle Corporation. All rights reserved. Connected to: Oracle9i Enterprise Edition Release 9.0.1.1.1 - Production With the Partitioning option JServer Release 9.0.1.1.1 - Production SQL> create table stud 2 (rollno varchar(20) primary key,name varchar(20),age varchar(20)); Table created. SQL> desc stud; Name Null? Type ----------------------------------------- -------- ---------------------ROLLNO NOT NULL VARCHAR2(20) NAME VARCHAR2(20) AGE VARCHAR2(20) SQL> insert into stud values(&rollno,&name,&age); Enter value for rollno: '1' Enter value for name: 'abc' Enter value for age: '21' old 1: insert into stud values(&rollno,&name,&age) new 1: insert into stud values('1','abc','21') 1 row created. SQL> / Enter value for rollno: '2' Enter value for name: 'def' Enter value for age: '22' old 1: insert into stud values(&rollno,&name,&age) new 1: insert into stud values('2','def','22') 1 row created.

1

SQL> / Enter value for rollno: '3' Enter value for name: 'ghi' Enter value for age: '23' old 1: insert into stud values(&rollno,&name,&age) new 1: insert into stud values('3','ghi','23') 1 row created. SQL> select * from stud; ROLLNO NAME AGE -------------------- -------------------- -------------------1 abc 21 2 def 22 3 ghi 23 SQL> select distinct * from stud; ROLLNO NAME AGE -------------------- -------------------- -------------------1 abc 21 2 def 22 3 ghi 23 SQL> update stud set age='24' where rollno=3; 1 row updated. SQL> select * from stud; ROLLNO NAME AGE -------------------- -------------------- -------------------1 abc 21 2 def 22 3 ghi 24 SQL> select * from stud; ROLLNO NAME AGE -------------------- -------------------- -------------------1 abc 21 2 def 22 3 ghi 24

2

Table altered. Table altered. Table renamed. SQL> desc student. Name Null? Type ----------------------------------------. Name Null? Type ----------------------------------------.-------.SQL> rename stud to student.---------------------ROLLNO NOT NULL VARCHAR2(20) NAME VARCHAR2(20) AGE VARCHAR2(5) PHN_NO VARCHAR2(10) SQL> select rollno from student where age<23.---------------------ROLLNO NOT NULL VARCHAR2(20) NAME VARCHAR2(20) AGE VARCHAR2(20) PHN_NO VARCHAR2(10) SQL> alter table student modify(age varchar(5)). ROLLNO -------------------1 2 SQL> select name from student where age between 21 and 25. NAME -------------------abc def ghi 3 . SQL> desc student.-------. SQL> alter table student add(phn_no varchar(10)).

ERROR: ORA-04043: object student does not exist 4 .-------------------. Table dropped. SQL> desc student.----.----.--------2 def 22 3 ghi 24 SQL> drop table student.SQL> select * from student order by name desc. ROLLNO NAME AGE PHN_NO -------------------.--------3 ghi 24 2 def 22 1 abc 21 SQL> delete from student where age =21.---------3 ghi 24 2 def 22 1 abc 21 SQL> select * from student order by name desc.-------------------.----. SQL> select * from student. 1 row deleted. ROLLNO NAME AGE PHN_NO -------------------. ROLLNO NAME AGE PHN_NO -------------------.-------------------.

&no_of_proj.&no_of_proj.2.&no_of_proj.PRACTICAL NO.'def'.20000.&proj_name.'abc'.&sal. SQL> / 5 .&proj_loc) new 1: insert into emp1 values('2'.proj_name varchar(20). SQL> desc emp1. no rows selected SQL> insert into emp1 values(&empno.no_of_proj varchar(10).&proj_name. SQL> / Enter value for empno: '2' Enter value for ename: 'def' Enter value for sal: 15000 Enter value for no_of_proj: 1 Enter value for proj_name: 'C++' Enter value for proj_loc: 'bangalore' old 1: insert into emp1 values(&empno.'delhi') 1 row created. SQL> create table emp1 (empno varchar(15).&ename. Enter value for empno: '1' Enter value for ename: 'abc' Enter value for sal: 20000 Enter value for no_of_proj: 2 Enter value for proj_name: 'java' Enter value for proj_loc: 'delhi' old 1: insert into emp1 values(&empno.&proj_name.---------------------EMPNO VARCHAR2(15) ENAME VARCHAR2(26) SAL VARCHAR2(24) NO_OF_PROJ VARCHAR2(10) PROJ_NAME VARCHAR2(20) PROJ_LOC VARCHAR2(10) SQL> select * from emp1.&proj_loc).'java'.sal varchar(24).1.'bangalore') 1 row created.15000.proj_loc varchar(10)).&sal.-------.&sal.&ename. Name Null? Type ----------------------------------------.&ename.ename varchar(26). Table created.&proj_loc) new 1: insert into emp1 values('1'.'C++'. 2 AIM: Create a view to display details of employees working on more than one project.

-----------.'ghi'. SQL> / Enter value for empno: '4' Enter value for ename: 'jkl' Enter value for sal: 17000 Enter value for no_of_proj: 3 Enter value for proj_name: 'Smalltalk' Enter value for proj_loc: 'noida' old 1: insert into emp1 values(&empno.'noida') 1 row created.17000.------------------1 3 4 abc 20000 java delhi ghi 12000 C pune jkl 17000 Smalltalk noida 6 . SQL> select * from vw.'Smalltalk'.12000.proj_loc from emp1 where no_of_proj>1.------.&proj_loc) new 1: insert into emp1 values('4'.&sal.---------.&ename.---------1 abc 20000 2 java delhi 2 def 15000 1 C++ bangalore 3 ghi 12000 4 C pune 4 jkl 17000 3 Smalltalk noida PROJ_LOC SQL> create view vw as select empno.-------------.4.----.&sal.&no_of_proj.Enter value for empno: '3' Enter value for ename: 'ghi' Enter value for sal: 12000 Enter value for no_of_proj: 4 Enter value for proj_name: 'C' Enter value for proj_loc: 'pune' old 1: insert into emp1 values(&empno.3.'C'.&proj_name.'pune') 1 row created. SQL> select * from emp1.&proj_name.'jkl'. EMPNO ENAME SAL PROJ_NAME PROJ_LOC -------. View created.------.proj_name.ename. EMPNO ENAME SAL NO_OF_PROJ PROJ_NAME ----.&ename.&proj_loc) new 1: insert into emp1 values('3'.sal.---------.&no_of_proj.

&proj_loc) new 1: insert into emp1 values('1'.&proj_loc).2. Enter value for empno: '1' Enter value for ename: 'abc' Enter value for sal: 20000 Enter value for no_of_proj: 2 Enter value for proj_name: 'java' Enter value for proj_loc: 'delhi' old 1: insert into emp1 values(&empno.&ename. no rows selected SQL> insert into emp1 values(&empno.'delhi') 1 row created.&no_of_proj. Name Null? Type ----------------------------------------.&proj_loc) new 1: insert into emp1 values('2'.sal varchar(24).---------------------EMPNO VARCHAR2(15) ENAME VARCHAR2(26) SAL VARCHAR2(24) NO_OF_PROJ VARCHAR2(10) PROJ_NAME VARCHAR2(20) PROJ_LOC VARCHAR2(10) SQL> select * from emp1.'abc'.-------.proj_loc varchar(10)). SQL> create table emp1 (empno varchar(15).20000.&sal.1.15000.&proj_name.ename varchar(26).&ename. SQL> / Enter value for empno: '2' Enter value for ename: 'def' Enter value for sal: 15000 Enter value for no_of_proj: 1 Enter value for proj_name: 'C++' Enter value for proj_loc: 'bangalore' old 1: insert into emp1 values(&empno.&no_of_proj.&ename.'bangalore') 7 .&no_of_proj.proj_name varchar(20). Table created.'C++'.&sal.&sal.PRACTICAL NO.&proj_name.'def'.&proj_name.'java'.no_of_proj varchar(10). SQL> desc emp1. 3 AIM: Create a view to display details of employees not working on any project.

&ename. SQL> / Enter value for empno: '3' Enter value for ename: 'ghi' Enter value for sal: 12000 Enter value for no_of_proj: 4 Enter value for proj_name: 'C' Enter value for proj_loc: 'pune' old 1: insert into emp1 values(&empno.'delhi') 1 row created.'java'.&proj_name.&proj_loc) new 1: insert into emp1 values('5'.&proj_loc).&proj_loc) new 1: insert into emp1 values('4'. SQL> / Enter value for empno: '6' Enter value for ename: 'pqr' Enter value for sal: 21000 Enter value for no_of_proj: ‘null’ 8 .&sal. Enter value for empno: '5' Enter value for ename: 'mno' Enter value for sal: 19000 Enter value for no_of_proj: ‘null’ Enter value for proj_name: 'java' Enter value for proj_loc: 'delhi' old 1: insert into emp1 values(&empno.&no_of_proj.&no_of_proj.&sal.&sal.4.'ghi'.3.&ename.'C'.'jkl'.17000.&sal.&no_of_proj.'Smalltalk'.null.&proj_name.'pune') 1 row created.'noida') 1 row created.'mno'. SQL> insert into emp1 values(&empno.&ename.12000.&proj_name.&proj_name.&ename.&no_of_proj.&proj_loc) new 1: insert into emp1 values('3'.19000.1 row created. SQL> / Enter value for empno: '4' Enter value for ename: 'jkl' Enter value for sal: 17000 Enter value for no_of_proj: 3 Enter value for proj_name: 'Smalltalk' Enter value for proj_loc: 'noida' old 1: insert into emp1 values(&empno.

-------5 mno 6 pqr -----------------19000 java 21000 C++ 9 .----------.----------.'pqr'.null.'pune') 1 row created.sal. SQL> create view vw5 as select empno. SQL> select * from emp1. EMPNO ENAME SAL NO_OF_PROJ PROJ_NAME PROJ_LOC -----.&proj_name.Enter value for proj_name: 'C++' Enter value for proj_loc: 'pune' old 1: insert into emp1 values(&empno.21000.&sal.&no_of_proj. SQL> select * from vw5. EMPNO ENAME SAL PROJ_NAME -----------delhi pune PROJ_LOC -----.proj_loc from emp1 where no_of_proj='null'.---------1 2 3 4 5 6 abc def ghi jkl mno pqr 20000 2 15000 1 12000 4 17000 3 19000 null 21000 null java delhi C++ bangalore C pune Smalltalk noida java delhi C++ pune 6 rows selected.------. View created.proj_name.&ename.----------.'C++'.&proj_loc) new 1: insert into emp1 values('6'.ename.

'&name'.'&age') new 1: insert into company values('17'. SQL>create table company(ssn varchar2(10) primary key.PRACTICAL NO. SQL> insert into company values('&ssn'.'&age') new 1: insert into company values('19'.'&name'.name varchar2(10).'james'.'25') 1 row created.'19') 1 row created. 10 .'&name'.'22') 1 row created.'&age') new 1: insert into company values('11'.'&age').'john'.'&name'.age varchar2(10)).'19') 1 row created SQL> / Enter value for ssn: 19 Enter value for name:james Enter value for age: 25 old 1: insert into company values('&ssn'. SQL> / Enter value for ssn: 23 Enter value for name:jack Enter value for age: 22 old 1: insert into company values('&ssn'. Table created.'&age') new 1: insert into company values('23'. Enter value for ssn: 11 Enter value for name:smith Enter value for age: 19 old 1: insert into company values('&ssn'.'&name'. 4 AIM: Create a view to display employees name and project name for employees working on projects <p1 and p3> or <p2 and p4>.'smith'. SQL> / Enter value for ssn: 17 Enter value for name: john Enter value for age: 19 old 1: insert into company values('&ssn'.'jack'.

Table created.'20') 1 row created. SQL> select * from company.'&age') new 1: insert into company values('87'.'tom'.'&age') new 1: insert into company values('29'.'michael'.'&name'.SQL> / Enter value for ssn: 29 Enter value for name:tom Enter value for age: 20 old 1: insert into company values('&ssn'. SQL> / Enter value for ssn:91 Enter value for name:michael Enter value for age:42 old 1: insert into company values('&ssn'.'&age') new 1: insert into company values('91'.project_no varchar2(10).'&name'.---------11 smith 19 17 john 19 19 james 25 23 jack 22 29 tom 20 87 daniel 47 91 michael 42 7 rows selected.'80') 1 row created.'91') 1 row created. SSN NAME AGE ---------. SQL>create table project(ssn varchar2(10) references company. SQL> / Enter value for ssn: 87 Enter value for name:daniel Enter value for age: 47 old 1: insert into company values('&ssn'. 11 .'sagita'.---------.project_name varchar2(10)).'&name'.

'programming') 1 row created.'&project_no'.'1'.'&project_name') new 1: insert into project values('19'.'&project_no'.SQL> insert into project values('&ssn'.'gaming') 1 row created.'hacking') 1 row created. 12 .'gaming') 1 row created.'&project_no'.'3'.'security') 1 row created. SQL> / Enter value for ssn: 19 Enter value for project_no: 3 Enter value for project_name: gaming old 1: insert into project values('&ssn'.'&project_no'.'3'.'&project_no'.'&project_no'. SQL> / Enter value for ssn: 29 Enter value for project_no: 2 Enter value for project_name: programming old 1: insert into project values('&ssn'.'&project_name') new 1: insert into project values('29'.'&project_name') new 1: insert into project values('17'.'&project_name') new 1: insert into project values('29'. SQL> / Enter value for ssn: 17 Enter value for project_no: 3 Enter value for project_name: gaming old 1: insert into project values('&ssn'.'&project_name') new 1: insert into project values('11'. Enter value for ssn: 11 Enter value for project_no: 1 Enter value for project_name: security old 1: insert into project values('&ssn'. SQL> / Enter value for ssn: 29 Enter value for project_no: 4 Enter value for project_name: hacking old 1: insert into project values('&ssn'.'2'.'4'.'&project_name').

'gaming') 1 row created. SSN project_no project_name ---------.'security') 1 row created.'3'.SQL> / Enter value for ssn: 29 Enter value for project_no: 3 Enter value for project_name: gaming old 1: insert into project values('&ssn'.project_name from company. SQL> / Enter value for ssn: 19 Enter value for project_no: 1 Enter value for project_name: security old 1: insert into project values('&ssn'.'&project_name') new 1: insert into project values('19'.----------------------11 1 security 29 2 programming 17 3 gaming 29 4 hacking 19 3 gaming 29 3 gaming 19 1 security SQL>create view working1 as select name.'1'.project where project_no=(1 AND 2) OR (3 AND 4). NAME -----------James James Tom Tom PROJECT_NAME -----------------------gaming security programming hacking 13 .-------------.'&project_name') new 1: insert into project values('29'. View created.'&project_no'. SQL> select * from working1.'&project_no'. SQL> select * from project.

---------------------PROJID VARCHAR2(10) PROJNAME VARCHAR2(20) SQL>create table emp41(empname varchar2(20) .---------abc 1 1 def 2 2 14 . 1 row created.projectid varchar2(10)). EMPNAME EMPID PROJECTID -------------------.2). 1 row created.3). SQL> desc emp41. SQL> desc project41. Name Null? Type ----------------------------------------.-------. SQL> select * from emp41.01. 5 AIM: Using two tables create view which shall perform equijoin. Name Null? Type ----------------------------------------. SQL>create table project41(projid varchar2(10) .02.projname varchar2(20)).---------.1).empid varchar2(10). 1 row created. Table created. SQL> insert into emp41 values('def'. SQL> insert into emp41 values('ghi'.-------.----------------------EMPNAME VARCHAR2(20) EMPID VARCHAR2(10) PROJECTID VARCHAR2(10) SQL> insert into emp41 values('abc'.PRACTICAL NO. Table created.03.

PROJID PROJNAME ---------.-------------------abc a 1 def c PROJECTID ---------2 15 . EMPNAME PROJNAME -------------------.empname.projname.'a').emp41.projectid from project41. 1 row created. SQL> insert into project41 values(2.ghi 3 3 SQL> insert into project41 values(1.'c').project41. SQL> insert into project41 values(7. 1 row created. 1 row created.'b').projid. SQL> select * from project41.projec tid=project41.emp41 where emp41.-------------------1 a 7 b 2 c SQL> select emp41.

6 AIM: Create trigger for before and after insertion. SQL> insert into students1 values('nitin'.--------. Before SQL> create table students1(name varchar2(20). 1 row created.'195'). SQL> insert into students1 values('rahul'.---------------------. 1 row created. NAME ROLL_NO BALANCE -------------------.'156'). 1 row created.'1207239'.'1207215'. SQL> insert into students1 values('neeraj'.balance varchar2(10)). SQL> desc students1. SQL> select * from students1.'400'). Name Null? Type --------------------------.'1207233'. SQL> insert into students1 values('pradeep'.'250'). 1 row created.---------------------NAME VARCHAR2(20) ROLL_NO NOT NULL VARCHAR2(9) BALANCE VARCHAR2(10) SQL> insert into students1 values('pradeep'.roll_no varchar2(9) not null primary key. 1 row created. Table created.'1207223'.'450').'1207234'.PRACTICAL NO.---------pradeep 1207234 156 pradeep 1207233 250 16 .

balance varchar2(3)).'salary can not be less than zero'). After SQL> create table students2(name varchar2(9).'250'). 6 end.---------.rahul neeraj nitin 1207239 195 1207215 400 1207223 450 SQL> create or replace trigger tri before insert or update on students1 for each row 2 begin 3 if :new. SQL> insert into students1 values 2 ('rohit'.----------------------NAME VARCHAR2(9) ROLL_NO NOT NULL VARCHAR2(8) BALANCE VARCHAR2(3) SQL> insert into students2 values('pradeep'.TRI' SQL> commit.TRI".'1207938'. line 3 ORA-04088: error during execution of trigger 'SCOTT. 1 row created.'1207234'. Name Null? Type --------------------------------------. Table created. Commit complete. 17 .roll_no varchar2(8) primary key. SQL> desc students2.balance<=0 then 4 raise_application_error(-20000. 5 end if. insert into students1 values * ERROR at line 1: ORA-20000: salary can not be less than zero ORA-06512: at "SCOTT. 7 / Trigger created.'-256').

'600'). 8 end if.-------.----------------------. NAME ROLL_NO BAL --------.'200'). 5 begin 6 if updating then 7 operator:='update'.operator varc har2(10)). Table created. SQL> insert into students2 values('rahul'. SQL> insert into students2 values('nitin'.'1207233'.NAME VARCHAR2(9) ROLL_NO VARCHAR2(9) BALANCE VARCHAR2(8) OPERATOR VARCHAR2(10) SQL> create or replace trigger tri6 after insert or delete or update on students2 2 for each row 3 declare 4 operator varchar2(10).balance varchar2(8). SQL> desc new_student.'1207223'. 9 if inserting then 18 . 1 row created. 1 row created. 1 row created.'600').-------.--pradeep 1207234 250 pradeep 1207233 200 rahul 1207239 600 nitin 1207223 600 SQL> create table new_student(name varchar2(9).'1207239'.SQL> insert into students2 values('pradeep'. SQL> select * from students2.roll_no varchar2(9). Name Null? Type ----------------------------------------.

end.10 11 12 13 14 15 16 17 operator:='insert'. if deleting then operator:='delete'.balance.---------1207239 rahul 600 update 1207234 pradeep 250 delete 19 .-------. SQL> update students2 set balance='700' where name='rahul'.operator).--pradeep 1207233 200 rahul 1207239 700 nitin 1207223 600 SQL> select * from new_student. NAME ROLL_NO BALANCE OPERATOR --------. 1 row updated. SQL> select * from students2. 1 row deleted. end if. SQL> delete from students2 where roll_no='1207234'.--------.:old.:old. / Trigger created.name.roll_no.-------. insert into new_student values(:old. NAME ROLL_NO BAL --------. end if.

Type VARCHAR2(9) VARCHAR2(10) VARCHAR2(10) VARCHAR2(18) VARCHAR2(10) VARCHAR2(10) 20 . salary in varchar. DA in varchar. 7 if projid=p1 then 8 t_salary:=salary+HRA+DA+inc. SQL> create table server1 (name varchar(9). SQL> desc server1.projid.3).DA.HRA varchar(10). 10 salary:=t_salary.incentive). 15 end if.HRA.DA varchar(18). 14 salary:=t_salary. 13 incentive:=0. Table created.projid varchar(10). Name Null? ----------------------------------.salary. projid in varchar) 2 is 3 incentive number(10.buf 1 create or replace procedure inc(name in varchar. 18 / Procedure created. HRA in varchar. 17 end.PRACTICAL NO.----------------.salary varchar(10). 4 t_salary number(100. 16 insert into server1 values(name. 11 else 12 t_salary:=salary+HRA+DA. 7 AIM: Write a procedure to give incentive to employees working on project p1. 9 incentive:=inc.incentive varchar(10)). 5 begin 6 inc:=2000.--------------------NAME SALARY HRA DA PROJID INCENTIVE SQL> ed Wrote file afiedt.

’120’.--------------pradeep 30000 8000 5000 p1 rahul 47357 1234 123 p2 vishal 31010 890 120 p3 0 INCENTIVE 2000 0 21 .----------.’46000’. PL/SQL procedure successfully completed.’p2’).’123’. NAME SALARY HRA DA PROJID ----------.----------.SQL> execute inc(‘pradeep’.’p3’).----------.’30000’.’5000’.----------. SQL> select * from server1.’8000’.’1234’.’p1’). PL/SQL procedure successfully completed.’15000’. SQL> execute inc(‘vishal’. SQL> execute inc(‘rahul’. PL/SQL procedure successfully completed.’890’.

270).units. 3 bill number(12. NAME PH_NO UNITS BILL ---------------.bill number(10.ph_no.units number(9).2).---------.bill). 11 end if.ph_no number(10). 6 unit:=units-105.ph_no in number.80). SQL> select * from telephbill.PRACTICAL NO. PL/SQL procedure successfully completed.9994372140.---------sumit 9994372140 270 337 22 . 13* end. 9 else 10 bill:=bill+(unit*1. 12 insert into telephbill values(name. SQL> / Procedure created.---------.20). SQL> ed Wrote file afiedt. 7 if unit>50 and unit<500 then 8 bill:=bill+(unit*0. SQL> exec pr35('sumit'.2)). 8 AIM: Write a procedure for computing amount of telephone bill.units in number)is 2 unit number(12).buf 1 create procedure pr35(name in varchar. SQL> create table telephbill(name varchar(16). Table created. 4 begin 5 bill:=205.

PRACTICAL NO. 15 end if.DA.HRA in varchar2. 21 / 23 .--------------NAME VARCHAR2(9) SALARY VARCHAR2(10) HRA VARCHAR2(10) DA VARCHAR2(18) TAX NUMBER(10) SQL> ed Wrote file afiedt.---------------. 9 AIM: Write a procedure for creating view on income tax.HRA.HRA varchar2(10).3).salary in varchar2. 4 t_salary number(10). 19 insert into server values(name. 18 end if. 13 if(t_salary>60000 and t_salary<=100000) then 14 tax:=(20*t_salary)/100. SQL> desc server1. 5 begin 6 t_salary:=salary+HRA+DA.DA in varchar2) 2 is 3 tax number(10. 10 if(t_salary>40000 and t_salary<=60000) then 11 tax:=(10*t_salary)/100.salary. 20 end.buf 1 create or replace procedure inc_tax(name in varchar2. 9 end if. 7 if(t_salary<=40000) then 8 tax:=0. Name Null? Type ----------------------------------------.000.DA varchar2(18).tax number(10)). 16 if(t_salary>100000) then 17 tax:=(30*t_salary)/100. Table created. SQL> create table server1(name varchar2(9). 12 end if.tax).salary varchar2(10).

PL/SQL procedure successfully completed.'890'.----------.'46000'. SQL> execute inc_tax('pradeep'.'123').Procedure created.--------------------pradeep 150000 8000 5000 rahul 46000 1234 123 pradeep 30000 890 120 TAX 48900 4736 0 24 .----------------. SQL> execute inc_tax('rahul'. NAME SALARY HRA DA ----------.'150000'. SQL> select * from server1. SQL> execute inc_tax('pradeep'.'1234'.----------.'5000').'120'). PL/SQL procedure successfully completed.'8000'.'30000'. PL/SQL procedure successfully completed.

--------------EID ENAME VARCHAR2(20) ESAL SQL> insert into employee values(1.---------------1 aaa 2 bbb 3 ccc 4 ddd 5 eee SQL> set serveroutput on.4000).’bbb’. SQL> insert into employee values(4.’ddd’. 1 row created.’ccc’. SQL> insert into employee values(2. Table created.----------------.2)). 1 row created. Display appropriate message based on the existence of records in the table. SQL> create table employee(eid number(10).’aaa’. SQL> insert into employee values(5.ename varchar(20). SQL> select * from employee. SQL> desc employee. 10 AIM: The hr manager has decided to raise the salary of employees by 15%. EID ENAME ----------------.3000).esal number(9.----------------. & update the salary of the employees. Name Null? Type ----------------------------------------. ESAL 3000 4000 5000 6000 7000 NUMBER(10) NUMBER(9. 1 row created.7000).2) 25 .PRACTICAL NO.’eee’.5000). 1 row created. SQL> insert into employee values(3. Write a pl/sql block to accept the employee no. 1 row created.6000).

put_line(‘Salary updated’).15. x number.put_line(‘Updation failed’). Enter the value for empid: 1 Salary updated PL/SQL procedure successfully completed.----------------. SQL> select * from employee. EXCEPTION WHEN INVALID_NUMBER THEN dbms_output. end. EID ENAME ----------------. x:=a*0.---------------1 aaa 2 bbb 3 ccc 4 ddd 5 eee ESAL 3450 4000 5000 6000 7000 26 . dbms_output. begin update employee set salary=salary*x where empid between 1 and 5.SQL> ed empsal1 declare a number.

4 begin 5 bal:=bal-200.cname in varchar. Table created.----------------.--------------ACCNUM CNAME VARCHAR2(20) BALANCE SQL> set serveroutput on.-------------------1 aa SQL> execute db(‘2’. 7 dbms_output. SQL> execute db(‘1’.balance number(9. SQL> desc customer. 11 AIM: Create a procedure that debits certain amount from customer account if minimum balance constraint is preserved.900).balance in number) 2 is 3 bal number=1000. ACCNUM CNAME ----------------------. PL/SQL procedure successfully completed.put_line(‘amount deducted due to minimum balance’).’aa’.2)). Name Null? Type ----------------------------------------.cname varchar(20). SQL> create table customer(accnum number(10).PRACTICAL NO. 9/ Procedure created.2) 27 .----------------------. 8 end. BALANCE 1100 NUMBER(10) NUMBER(9. 6 update customer set balance=bal where balance<1000. SQL> select * from customer. SQL> ed cust 1 create procedure db(accnum in number.’bb’.1100).

-------------------1 aa 2 bb 3 cc BALANCE 1100 700 300 28 .PL/SQL procedure successfully completed. PL/SQL procedure successfully completed. ACCNUM CNAME ----------------------.’cc’.500). SQL> select * from customer.----------------------. SQL> execute db(‘3’.

Sign up to vote on this title
UsefulNot useful