Lab Answers
Lab Answers
Lab Answers
1
II i'il 111111 II
I I
Question l:
(a) Create a table called Empl~yee with the following structure.
Empno (Number), Ename (Varchar2(20)), Job (Varchar2(20) ), Sal (Number)
(i) Add a column DoJ (DATE) with the Employee table.
(ii) Insert any five records into the table.
(iii) Update the column details of job
(iv) Rename the column Sal as Emp_Salary of Employee table using alter
(v) Delete the employee whose empno is 101.
(b) Write a PL/SQL program to demonstrate Exceptioris.
2022.11.13 13:53
ur · ~ie Ja~aDase 11g Express Edition Release 11. 2 . 0 . 2 . 0 - 64bit Production
SQL> create table employee1(empno numbe r ,ename varchar2(20) ,job var char2(20),sal number);
Table created.
Null? Type
vivo V1~fJJ
Perfect Shot 2022.11.13 13:Li
<'
~ I.\ ~ ~ v,
w ., '~ ,0 ~
r-
\111
,ti-S
r-
a V a V
i E ~
:,
~- .....
:, I-'•
.,n .,n ~., .,n :,
ti) '-'' Ill
l'O ffl l'1) I'\) re,
~ ~
., c:u
~ rt r+
..,
ft) fl) 11)
r+
0.. .... Q. C. ....
I :, I I
....::::, ::,
rt rt rt
0 0 0
l'D 11) 11)
a a 3
"tJ "'O "'C
..... ..., ...,
0 0 0
'< '< '<
l'D l't) l't)
t1) l't) 11)
t- t- ~
<
Q) Q)
..., Q)
...,< ...,<
C C: C:
l'D l't) 11)
11'1 IJ'I IJ'I
;-..,.
""'
.... t-
'"' Ii-\
a, CS) CS)
w ~ ..,.:.
". ". "" .
Q)
..,.< 0-
a ::r
a n Q)
C ~
. '< <
Q)
". . .
n ". "" .
:r .., IJ'I
l'D
..,. 0 11)
0- .
~ 0
. ""
"~ ..,.rt (S)
.
n CS)
a, 11'1 (S)
(S) . (S)
u, (S)
N "~ (S)
~ (S)
(S) (S) "" .
u, N
(S)
".
"-l
N (S) I
~ (S) w
u• ". l>
2
N I
~ w I\.)
I ~
I\.)
'
m '-" t'-l
1\,:1
N t •
I\.) I
., N
~·
~ "~
... CD
N
I"-"
.._...."
...
EMPNO ENAME JOB SAL DOJ
101 bhava 10000 00 22-JA N-22
102 vicky 10050 00 23-JA N-22
103 ammu 10052 00 24-JA N-22
SQL> upda te empl oyeel set job= 'driv er' where (enam e='vi cky') ;
1 row upda ted.
ERROR at line 1:
ORA.-00923: FROM keyword not found where expected
----------
vivo V19
Perfect Shot 2022.11.13 1'4:17
SQL> update department set deptno=103 where (location='korattur');
1 rm-.1 updated .
0 rows deleted.
1 row deleted.
SQL> select-from,:deP.ar.tment;
-.:·,:;;
..,;;,.·
OEPTNO -DEs,NAME l!OCATION DESIGNAliION
:j!·~·-,
---------- ~-- -~--------
19l)jr.obotics avai:Ji ctieif.
102· liostP.ital!
;;_ I
annanur. <ioctor.
;,., .
Ques tion No. 3
A). Create a table called Custo mer table
Name Type
Cust name V arcbar2(20)
Cust street Varcb ar2(20)
Cust city V arcba r2(20)
1 row created .
CUST_NAME CUST_CITV .
~henn~i~£;.: :,.:.: . "',,.. _. _;,_, :, , .
viclcy avadi
paldcaa .tiruvallur.
pettai salem
~- .. ,r;;,_:.;f-~
SQL> alter table custaer add(sa,}-arY. niaiber);
\.-►.-.ii.~
Table a ltered. ., ..
SQL> selectS-froa . ... ) .. ,~ :~-
l : : ::::~
SQL> del ete custo11er whe re
cus t_c ity= 'sal em' ;;
cus<ooer: .
V1 9 C.UST NAME CUST _S:tREET
' ect Sh a~~..~-- ---- ---- 20 22 .11.
.- ---- _~~;;,i:~.~~~::~}~----- I
Question No. 4
A) Create a table called branch table.
Name Type
Branch name V archar2(20)
Branch city V archar2(20)
asserts Number
Table altered.
ERROR at line 1:
ORA-00903: invalid table name
Table altered.
1 row crea---LE:d.
1 ro11 created.
1 l'OII created.
~ _err, ASSERTS
indi__a) ct.ennai
state -t:beni
hdfc aaaurai
vivo V1%lr!t.> update fw.ancb set brand)_n~nion where a~ser.ts=~01;
Perfect, S~9:1§,.. ~ set branch naae=union where asser,ts,:::~0!. 2022.11.13 16: 26
SQL> upd ate branch set branch_name= 'union' 1~here assertse101;
1 r oH updated.
union chennai
state theni
hdfc madurai
SQL> delete branch column assert=101;
delete branch column assert=101
ERROR at line 1:
ORA-88933: SQL command not properly ended
Trigger created.
SQL> insert into empt values(t3.
2 insert into empt values(13.'bha'.1000);
insert into empt values(13.'bha".1000)
ERROR at line 2:
ORA-08936: lli.ssing expression
1 row ,: upd~ed.
ot .:.'"
SQL> set serveroutput on;
SQL > declare
23 begin cursor ce is select eno,ename,salary from emp1;
for x in ce
loop
6
7
dbms_0,u"t;p9t i:, i ~ ~t.
1
1
Procedure created ..
SQL> declare
2 x nlaber;
3 y 11111mer;
4
5 x:=&x;
6 y:=&.y;
7 SUll(X,.y) ;
8 end;
g /
J:ntr-o.- value for x:
old 5: x:=&x;
successful!~ c~letecf.
SQl.f. ~
L> set se rve r out put on·
L> DECLAR E '
2 s_rollno students.rollno%type ·- &s_rollno;
3 s_name students.name%type;
4 s_address students.address%type·
5 e x_invalid_rollNo EXCEPTION; ,
6 BEGIN
7 IF s_rollno <= 0 THEN
8 RAISE ex_invalid_rollNo;
9 ELSE
10 select name~address INTO s_name~s_address FROM students
11 WHERE s rollno=rollno;
12 dbms_output.put_line(s_rollNo 11 • • 11 s_name 11 • • 11 s_address);
13 END IF;
14 EXCEPTION
15 WHEN ex invalid rollNo THEN
16 dbms_output.put:line( 'rollNc;> _.~u~t zero!•);
17 WHEN no data found THEN <}•, ,.
18 dbms output.put_linet•~~:,ri sucl, student!' •)';
19 WHEN-others THEN 1!:i:_
20 dbms_output. pu~~~_ine~ • Er.r.or. ! • ) ;
21 END; .. _··
22 / <.. :.-
Enter value fQ~ ~si 5ollno: 10f e := &s_r.ollno;
ld 2· s r.ollno students.rolino%tY.P.
~ew 2;
:S=~_o llno stu<ients. r.ollno%tyP.e . - 101;
101 bhava · av adi
... ~.i
15 end loop ;
16 /
vivo V19
Funcf:J;:; c
Perfect Shot 2022.11 .1Li 06:02
.. l r I mu t1set
PL/SQL r.oc·'"