Download - Systems Lab
-
8/10/2019 Systems Lab
1/39
Manual For
SYSTEMS LAB
Submitted in partial fulllment ofthe requirements for the award of the degree of
Master of TechnologyIn
Computer Science & Engineering
Submitted byNAME ROLL NUM
DEPARTMENT O COMP!TER SCIENCE & EN"INEERIN"
"AND#I$I INSTIT!TE O SCIENCE AND
TEC#NO%O"
(Approved By AICTE, Afliated to NTU!"
#attu B$imavaram, a%%ayyapet& ') )*+
eb-ite. ///0%i-te1$01o0i2
-
8/10/2019 Systems Lab
2/39
UNIX COMMANDS
1. CAL:
Sytax: $calDescription: Cal displays a simple calendar. If arguments are not specified,the current month is displayed.Eg:[cs4!localhost chandus"$ calcal #oem%er &'Su (o )u *e )h +r Sa & - 4 / 0 '
1 & - 4 / 0 ' 1 & & &&&- &4 & &/ &0 &' &1-
2. DATE:
Syntax: $ date 23option5m displays numerical form of month of date5n displays name of the month5( displays the current minutes56 displays current hours57 displays full name of the month
DESC8I9)I# Display the current time in the gien +8(;), or set the systemdate.Eg:.[cs4!localhost chandus"$ date date (on #o &4 :4:4 IS) &'
&.[cs4!localhost chandus"$ date 2
-
8/10/2019 Systems Lab
3/39
=(an> formats and displays the on?line manual pages. r 6elp ofcommands.
4.BC:
Syntax: $ %c
DESC8I9)I# =7c> is a language that supports ar%itrary precision calculatorlanguage.
5. WHO:
Syntax: $ @hoDESC8I9)I# @ho ? sho@ @ho is logged onEg:
[cs4!localhost chandus"$ @horoot : &'?? :&root ptsA &'?? :-cs4 ptsA& &'??&4 :/ B0&./'.&.1
6. UNAME:
Syntax: $ uname
DESC8I9)I# 9rint certain system information.Eg:[cs4!localhost chandus"$ unameinux
7. LOGOUT:
Syntax: $ logout Bor 9ress 3ctrl2d8. LOGIN:
DESC8I9)I# )his commands are used to enter a user into the #IF
enironment %y proiding the user @ith a login and logout id @ith apass@ord proided to him.Eg:login: cs4
9ass@ord: pass&-4ast login: (on #o &4 :/:-0 from 0&./'.&.1[cs4!localhost G"$
-
8/10/2019 Systems Lab
4/39
DIRECTORY COMMANDS:
9. WD:
Syntax: $ p@dDESC8I9)I# 9rint the full filename of the current @orHing directory.Eg:[cs4!localhost chandus"$ p@dAhomeAcs4Achandus
1!.M"DIR:
Syntax: $ mHdir 3directory nameDESC8I9)I# Create the DI8EC)8Bies, if they do not already exist.
Eg: [cs4!localhost chandus"$ mHdir chandu
; ne@ directory @ith specified name is created.
11.LS:
Syntax: $ lsDESC8I9)I# ist information a%out the +IEs Bthe current directory %ydefault.Eg:[cs4!localhost chandus"$ lsls;op copyrename Jist matrixmul noof@ords time&
%alu fileordir Hiran mulfileintodir po@er upper%uKKi findthefileindir lineremoe multa%le rematrix uprcase%uKKi greatest logon nooflines time
12.CD:
Syntax: $ cd 3directory name
DESC8I9)I# LcdM command is used to create a ne@ directory @ith specifiedname. )he user can Heep tracH of all the @orH programs he did in thedirectory he created.Eg:[cs4!localhost G"$ cd chandus#cs4!localhost chandus"$
-
8/10/2019 Systems Lab
5/39
13.CD ..:
Syntax: $ cd ..DESC8I9)I# LCd ..M command is used to exist out of the current displayingdirectory into the home directory.Eg:[cs4!localhost chandus"$ cd ..[cs4!localhost G"$
14.RMDIR:
Syntax: $ rmdir 3directory nameDESC8I9)I# 8emoe the DI8EC)8Bies, if they are empty.
Eg: [cs4!localhost G"$ rm chandu
rm: cannot remoe NchanduO: Is a directory
[cs4!localhost G"$ cd chandu
[cs4!localhost chandu"$ ls@hoislogon[cs4!localhost chandu"$ rm @hoislogon
[cs4!localhost chandu"$ cd ..
[cs4!localhost G"$ rmdir chandu
[cs4!localhost G"$
15.C:
Syntax: $ cp 3present file 3ne@ fileDESC8I9)I# Copy S8CE to DES), or multiple S8CEBs toDI8EC)8.
Eg:[cs4!localhost chandus"$ cp Jist Jist[cs4!localhost chandus"$
-
8/10/2019 Systems Lab
6/39
16.M$:
Syntax: $ mDESC8I9)I# 8ename S8CE to DES), or moe S8CEBs toDI8EC)8.Eg:[cs4!localhost chandus"$ m Jist Jist&m Jist Jist&[cs4!localhost chandus"$
17.CAT:
Syntax: $ cat Jist&DESC8I9)I# Concatenate +IEBs, or standard input, to standard output.Eg:
[cs4!localhost chandus"$ cat Jist&this is JistIt hae so many colleges)he colleges contain so many %ranches
9ress C)82F[cs4!localhost chandus"$ cat Jist&
this is JistIt hae so many colleges)he colleges contain so many %ranches
18.COMM:
Syntax: $ comm. 7uKKi JistDESC8I9)I# Compare sorted files +IE and +IE& line %y line.Eg:[cs4!localhost chandus"$ comm %uKKi Jistcomm %uKKi Jist
this is gist this is Jist It hae so many colleges )he colleges contain so many %ranches
-
8/10/2019 Systems Lab
7/39
19.DI%%:
Syntax: $ diff %uKKi Jist
DESC8I9)I# diff ? find differences %et@een t@o files
2!.WC:
Syntax: $ @c 3+ile name
DESC8I9)I# 9rint ne@line, @ord, and %yte counts for each +IE, and a totalline if more than one +IE is specified.
Eg:[cs4!localhost chandus"$ @c %uKKi@c %uKKi - - %uKKi
L?lM )o gie num%er of lines L?cM )o gie num%er of characters L?@M )o gie num%er of @ords
21.CHMOD:
Syntax: $ chmod 3alue 3filename
DESC8I9)I# Chmod changes the permissions of each gien file according to mode,Eg:$ chmod 3file ? seless file
22.UMAS":
Syntax: $ umasHDESC8I9)I# 7y using this command @e can change the default file
permission for an existing file.Eg: [cs4!localhost chandus"$ umasHmasH&
-
8/10/2019 Systems Lab
8/39
23.%IND:
Syntax: $ find 3filename
DESC8I9)I# find ? search for files in a directory hierarchyEg: [cs4!localhost chandus"$ find %uKKifind %uKKi
%uKKi
24.S:
Syntax: $ ps
DESC8I9)I# ps displays information a%out a selection of the actie processes.
Eg:
[cs4!localhost chandus"$ ps 9ID )) )I(E C(D&/'1 ptsA& :: %ash&// ptsA& :: man&//- ptsA& :: sh&//4 ptsA& :: sh&//1 ptsA& :: less&/// ptsA& :: man&///- ptsA& :: sh&///4 ptsA& :: sh
25.DU:
Syntax: $ du
DESC8I9)I# SummariPe disH usage of each +IE.Eg:
[cs4!localhost chandus"$ du4 .AHiran&-&
-
8/10/2019 Systems Lab
9/39
26.D%:
Syntax: $ df
DESC8I9)I# df displays the amount of disH space aaila%le on the file systemcontaining each file name argument.Eg
[cs4!localhost chandus"$ df+ilesystem Q?%locHs sed ;aila%le se5 (ounted onAdeAhda- -00/00/ /1/'4 &''&/1& &5 AAdeAhda '/ 1-0 '/41& 5 A%oottmpfs &&/' &&/' 5 AdeAshm
27.MOUNT:Syntax: $mount
DESC8I9)I# ;ll files accessi%le in a nix system are arranged in one %ig tree,the file hierarchy, rooted at A. )hese files can %e spread out oerse? eral deices. )he mount command seres to attach the file systemfound on some deice to the %ig file tree.Eg:[cs4!localhost chandus"$ mountmountAdeAhda- on A type ext- Br@
proc on Aproc type proc Br@sysfs on Asys type sysfs Br@depts on AdeApts type depts Br@,gidR,modeR/&AdeAhda on A%oot type ext- Br@
tmpfs on AdeAshm type tmpfs Br@none on AprocAsysAfsA%infmtmisc type %infmtmisc Br@sunrpc on AarAli%AnfsArpcpipefs type rpcpipefs Br@automountBpid1- on Anet type autofsBr@,fdR4,pgrpR1-,minprotoR&,maxprotoR4
-
8/10/2019 Systems Lab
10/39
28.ULIMIT:
Syntax: $ ulimit
DESC8I9)I# )he ulimit call @ill get or set some limit for the current
processes.Eg:[cs4!localhost chandus"$ ulimitulimitunlimited
29.%INGER:
Syntax: $ fingerDESC8I9)I# )he finger displays information a%out the system users.
Eg:[cs4!localhost chandus"$ fingerogin #ame )ty Idle ogin )ime ffice ffice 9honecs4 ptsA& #o & 1:4 B0&./'.&.1root root T: #o :&root root ptsA d #o :-
3!.CUT:
Syntax: $ cut 3file name
DESC8I9)I# 9rint selected parts of lines from each +IE to standard output.Eg:[cs4!localhost chandus"$ cut ?c ? gistthisIt ha)he c
31.AST:
Syntax : $ [?dls" 3filename
DESC8I9)I#: (erge lines of the files, @rite lines consisting of theseUuentially corresponding lines from each file, separated %y ta%s tostandard A9.
-
8/10/2019 Systems Lab
11/39
32.SORT:
Syntax: $ sort [options" V[output file" 3file name.
ptions:?d ;lphanumeric sort?f folder uppercase into lo@ercase?% ignores loading %lanH spaces?n numeric sort?c checH if files are soled?r reerse sort order ?Hn sorts according to Hey al i.e. fields?u remoes repeated lines?tchar sorts according to delimiter
DESC8I9)I# *rite sorted concatenation of all +IE.Eg:[cs4!localhost chandus"$ sort ?d gistIt hae so many colleges)he colleges contain so many %ranchesthis is gist
33.GRE:
Syntax: $ grep 3file name
DESC8I9)I# Jrep searches the named input +IEsEg: [cs4!localhost chandus"$ grep ? gist gist&this is JIS)It maintains alues and standards.
-
8/10/2019 Systems Lab
12/39
SHELL ROGRAMS
1.TO %IND THE BIGGEST O% THREE NUMBERS.
&'(&)*
echo =Enter - alues>read aread %read cif[$a Vgt $%"thenif[$a Vgt $c"thenecho $a is %igelse
echo $c is %igfielif[$% Vgt $c"thenecho $% is %igelseecho $c is %igfi
O+,-+,:
$ chmod 2r@x %ig$ .A%igEnter - alues41-1 is %ig.
-
8/10/2019 Systems Lab
13/39
2.TO %IND THE %ACTORIAL O% THE GI$EN NUMBER.
&'(&)*
echo =Enter a num%er>read nfactRtempR$n@hile[$n Vgt "dofactRMexpr $nWT $factMnRMexpr $n ?Mdoneecho factorial of $temp isecho $fact
utput:$ chmod 2r@x$ .AfactEnter a num%er+actorial of is &.
-
8/10/2019 Systems Lab
14/39
3.TO %IND THE RIME NUMBERS U TO A GI$EN RANGE.
&'(&)*
echo =enter range>read necho =prime num%ers till $n are>echo iR&@hile[$i Vle $n"docR
KR@hile[$K Vle $i"doif[Lexpr $i WT $KM VeU "
thencRMexpr $c 2Mfi
KRMexpr $K2Mdoneif[$c VeU &"thenfcho $ifiiRMexpr $i2Mdone
O+,-+,:$chmod 2r@x prime$ .AprimeEnter range9rime num%ers till are
&-0
-
8/10/2019 Systems Lab
15/39
4.TO %IND THE %IBONACCI NUMBERS U TO A GI$EN RANGE.
&'(&)*
echo =enter a alue>read nfRf&Recho =+i%onacci series is>echo $f&iR@hile [$i Vlt $n"dof-RMexpr $f 2 $f&Mfcho $f-iRMexpr $i2M
iR$f&i&R$f-done
O+,-+,:
$chnod 2r@x fi%o$.Afi%oEnter a alue/
+i%onacci series is&-
-
8/10/2019 Systems Lab
16/39
5.TO %IND WHETHER THE GI$EN NUMBER IS ALINDROME
OR NOT.
&'(&)*:
echo =enter a num%er>read numnumR$num
palR@hile [$num Vgt "dodigRMexpr $num 5 M
palRMexpr $pal WT 2$digMnumRMexpr $num A Mdoneif [$numR$ pal"
thenecho $num is palindromeelseecho $num is not a palindromefi
O+,-+,:
$ chmod 2r@x pal
$ .ApalEnter a num%er&& is palindrome.$.ApalEnter a num%er&-&- is not a palindrome.
-
8/10/2019 Systems Lab
17/39
6.TO %IND A MULTILICATION TABLE.
&'(&)*
echo =enter the num%er>read necho =enter the range>read rmulRiR@hile[$i Vle $r"domulRMexpr $n WT $iMif[$i Vlt "then
echo $n =T> $i =R> $mulelseecho $i =T> $n>R> $mulfiiRMexpr $i2Mdone
O+,-+,:
$ chmod 2r@x mul$ .AmulEnter the num%er1Enter the range1TR11T&R'1T-R&01T4R-/1TR41T/R41T0R/-1T'R0&1T1R'1TR1
-
8/10/2019 Systems Lab
18/39
7.TO DISLAY THE TRANSOSE O% A 22 MATRIX.
&'(&)*
echo enter num%er of ro@sread mecho enter num%er of columnsread nsiPe RMexpr $m WT $nMecho enter $siPe elements
KR@hile [$K Vle $siPe"doread %[$K"
KRMexpr $K2M
donepRtRURrR$necho the alues after transpose@hile [$p Vlt $n"dosRMexpr $r WT $U 2 $tMecho $[%[$s""URMexpr $U 2M
pRMexpr $p2MdonelR@hile [$p Vlt $siPe"dosRMexpr $r WT $lMecho $[%[$s""lRMexpr $l2M
pRMexpr $p2Mdone
-
8/10/2019 Systems Lab
19/39
O+,-+,:
$chmod 2r@x tran$.Atran
Enter num%er of ro@s&Enter num%er of columns&Enter 4 elements&-4)he alues after transpose are
&4-
-
8/10/2019 Systems Lab
20/39
8.TO COUNT THE NUMBER O% LINES AND NUMBER O% WORDS
IN A GI$EN TEXT %ILE.
&'(&)*
echo enter filenameread fileif [?f $file"thenif [?s $file"thenecho =num%er of lines:>@c Vl $fileecho =num%er of @ords:>@c V@ $file
else =file is empty>fielseecho =not a alid filename>fi
O+,-+,:
$ chmod 2r@x countl@
$ .Acountl@Enter filenameQnl
#um%er of lines:- Hnl
#um%er of @ords:& Hnl.
-
8/10/2019 Systems Lab
21/39
9.WRITE A /C0 ROGRAM TO ILLUSTRATE THE CAT UNIX
COMMAND.
&'(&)*
Xinclude3stdio.hXinclude3fcntl.hmainBYfile TfpZchar cZfpRfopenB=fil>,>r>Z@hileBBcRfgetcBfpReofY
printfB=5c>,cZ\
fcloseBfpZ\
O+,-+,:
$ cat fil6ello %oys and girls6ae a good day)hanH u
$ cc cat.c$ .Aa.out6ello %oys and girls6ae a good day)hanH u.
-
8/10/2019 Systems Lab
22/39
1!.WRITE A /C0 ROGRAM THAT ILLUSTRATE THE CREATIONO% CHILD ROCESS USING /%OR"0.
&'(&)*
Xinclude3stdio.hXinclude3stdli%.hXinclude3sysAtypes.hint mainBoidY
pidt pidZpid RforHBZ
s@itchBpidYcase ?:printfB=forH error>ZexitBZcase ?:printfB=Wn child process created.WnWn>Z
printfB=the pid of child is 5d Wn>,getpidBZprintfB=the parent pid of child is 5d WnWn>,getpidBZ\\
O+,-+,:
$ cc forH.c$ .Aa.outChild process created)he 9id of child is &'/1)he parent 9ID of child is &'/'1
-
8/10/2019 Systems Lab
23/39
DBMS ROGRAMS
. Jet )he Description f Emp )a%le.
S]desc empZ
Name Null? Type
EMPNO NOT NULL NUMBER(4)
ENAME VARCHAR2(10)
JOB VARCHAR2(9)
MGR NUMBER(4)
HIREDATE DATE
SAL NUMBER(7,2)
COMM NUMBER(7,2)DEPTNO NUMBER(2)
&.ist ;ll Employee Details.
S]select T from empZ
EMPNO ENAME JOB MGR HIREDATE SAL COMM DEPTNO
7369 SMITH CLER 7902 17!DEC!"0 "00 20
7499 ALLEN SALESMAN 769" 20!#EB!"1 1600 300 30
7$21 %ARD SALESMAN 769" 22!#EB!"1 12$0 $00 30
7$66 JONES MANAGER 7"39 02!APR!"1 297$ 20
76$4 MARTIN SALESMAN 769" 2"!SEP!"1 12$0 1400 30
769" BLAE MANAGER 7"39 01!MA&!"1 2"$0 30
77"2 CLAR MANAGER 7"39 09!JUN!"1 24$0 10
77"" SCOTT ANAL&ST 7$66 19!APR!"7 3000 20
7"39 ING PRESIDENT 17!NOV!"1 $000 10
7"44 TURNER SALESMAN 769" 0"!SEP!"1 1$00 0 30
7"76 ADAMS CLER 77"" 23!MA&!"7 1100 20
7900 JAMES CLER 769" 03!DEC!"1 9$0 30
7902 #ORD ANAL&ST 7$66 03!DEC!"1 3000 207934 MILLER CLER 77"2 23!JAN!"2 1300 10
4 ro@s selected.
&. ist ;ll o%s ;aila%le In Employee )a%le.
-
8/10/2019 Systems Lab
24/39
S]select distinct Ko% from empZ
JOB
ANAL&ST
CLER
MANAGER
PRESIDENT
SALESMAN
. ist ;ll Employees *ho 7elongs )o )he Department r &.
I#9) S]select ename from emp @here deptno in B,&Z
ENAME
SMITH
JONES
CLAR
SCOTT
ING
ADAMS
#ORD
MILLER
' ro@s selected.
/. ist ;ll Employee #ames , Salary ;nd 5 8ise In Salary.
I#9) S]select ename , sal , sal2.T sal from empZ
ENAME SAL SAL+0.15SAL
SMITH "00 920
ALLEN 1600 1"40
%ARD 12$0 1437'$
JONES 297$ 3421'2$
MARTIN 12$0 1437'$
BLAE 2"$0 3277'$
CLAR 24$0 2"17'$
SCOTT 3000 34$0
ING $000 $7$0
TURNER 1$00 172$
-
8/10/2019 Systems Lab
25/39
ADAMS 1100 126$
JAMES 9$0 1092'$
#ORD 3000 34$0
MILLER 1300 149$
4 ro@s selected.
0. ist (inimum , (aximum , ;erage Salaries f Employee.
S]select minBsal,maxBsal,agBsal from empZ
MIN!SAL" MA#!SAL" A$G!SAL"
"00 $000 2073'21429
'. +ind 6o@ (any ^o% )itles ;re ;aila%le In Employee )a%le.
S]select count Bdistinct Ko% from empZ
CO%NT!DISTINCTJOB"
$
1. *hat is the difference %et@een maximum and minimum salaries ofemployees in the organiPation_
I#9) S]select maxBsal?minBsal from empZ
MA#!SAL"&MIN!SAL"
4200
.ist all employee names and their salaries, @hose salary lies %et@een
A? and -A? %oth inclusie.
I#9)S]select ename from emp @here sal %et@een and -Z
ENAME
ALLEN
-
8/10/2019 Systems Lab
26/39
JONES
BLAE
CLAR
SCOTT
TURNER
#ORD
0 ro@s selected.
. +ind ho@ much amount the company is spending to@ards salaries.
I#9) S]select sum Bsal from empZ
S%M!SAL"
2902$
&. Display name of the dept. @ith deptno &.
I#9) S]select ename from emp @here deptno R &Z
ENAME
SMITH
JONES
SCOTT
ADAMS
#ORD
-. ist ename @hose commission is #.I#9) S]select ename from emp @here comm is nullZ
ENAME
SMITHJONES
BLAE
CLAR
SCOTT
ING
ADAMS
JAMES
-
8/10/2019 Systems Lab
27/39
#ORD
MILLER
ro@s selected.
4. +ind no.of dept in employee ta%le.
I#9) S]select count Bdistinct ename from empZCO%NT!DISTINCTENAME"
14
. ist ename @hose manager is not #.I#9) S]select ename from emp @here mgr is not nullZ
ENAME
SMITH
ALLEN
%ARD
JONES
MARTIN
BLAE
CLAR
SCOTT
TURNER
ADAMS
JAMES
#ORD
MILLER
- ro@s selected.
/. Display total salary spent for each Ko% category.I#9) S]select Ko%,sum Bsal from emp group %y Ko%Z
JOB S%M!SAL"
ANAL&ST 6000CLER 41$0
MANAGER "27$
PRESIDENT $000
SALESMAN $600
0. Display lo@est paid employee details under each manager.
-
8/10/2019 Systems Lab
28/39
I#9) S]select ename, sal from emp @here sal in Bselect minBsal fromemp group %y mgrZ
ENAME SAL
SMITH "00
JAMES 9$0
ADAMS 1100
MILLER 1300
CLAR 24$0
SCOTT 3000
#ORD 3000
ING $000
' ro@s selected.
'. Display num%er of employees @orHing in each department and theirdepartment name.
I#9) S] select dname, count Bename from emp, dept @hereemp.deptnoRdept.deptno group %y dnameZ
DNAME CO%NT!ENAME"
ACCOUNTING 3
RESEARCH $
SALES 6
CREATING TABLE %OR $ARIOUS RELATIONSIN SL.
.S]create ta%le studentsBno num%erB,name archar&B&,rnoarchar&B& primary HeyZ)a%le created.&.S]desc studentsZ
Name Null? Type
NO NUMBER($)
NAME VARCHAR2(20)
-
8/10/2019 Systems Lab
29/39
RNO NOT NULL VARCHAR2(20)
-. S]desc marHsZName Null? Type
RNO VARCHAR2(20)
ADS NUMBER(3)
M#CS NUMBER(3)
CO NUMBER(3)
DBMS NUMBER(3)
OS NUMBER(3)
JAVA NUMBER(3)
TOTAL NUMBER(4)
4.S]select T from studentsZNO NAME RNO
1 *+ -./14
2 . -./12
3 5- -./0$
4 -./01
$ 8- -./02
6 + -./03
7 -./04
" 8/ -./06
" 58 -./07
9 + -./13
10 58+ -./1$ ro@s selected.
.S]update students set nameROarmaO @here noRZ
ro@ updated.
/.S]delete from students @here nameROsiaOZ ro@ deleted.
0.S]select T from studentsZ
NO NAME RNO
1 *+ -./14
-
8/10/2019 Systems Lab
30/39
2 . -./12
3 5- -./0$
$ 8- -./02
6 + -./03
7 -./04
" 8/ -./06" 58 -./07
9 + -./13
10 58+ -./1$
ro@s selected.
IMLEMENTING SINGLE ROW %UNCTIONS
S( &' +,';:
1.S;, ;
-
8/10/2019 Systems Lab
31/39
COS!0"
1
5.''&=
SL>;, ''&34.7 &'* ?+)=
/LOOR!*-."
34
6.=
SL>;, 34.3 &'* ?+)=
CEIL!*-.*"
3$
7.);=
SL>;, );7 &'* ?+)=
ABS!&"
7
WRITING LSL BLOC" %OR INSERTION INTO A
TABLE.
1. TO WRITE A LSL BLOC" TO CHEC" WHETHER A
GI$EN NUMBER IS E$EN OR ODD.
ROGRAM:
DECLARE
NUM NUMBER5=
REM NUMBER5=
-
8/10/2019 Systems Lab
32/39
BEGIN
NUM:NUM=
REM:MODNUM@2=
I% REM!THEN
DBMSFOUTUT.UTFLINENUM IS E$EN=
ELSEDBMSFOUTUT.UTFLINENUM IS ODD=
END I%=
END=
OUTUT:ENTER $ALUE %OR NUM: 3
OLD 6: NUM:NUM=
NEW 6: NUM:3=
NUMBER 3 IS ODD
LSL ROCEDURE SUCCESS%ULLY COMLETED.
2.TO WRITE A LSL ROGRAM TO IMLEMENT THE SCOE
O% THE $ARIABLE.
ROGRAM:DECLARE
X REAL:2!5=
BEGIN
DBMSFOUTUT.UTFLINETHE $ALUE O% OUTER X:X=
DECLARE
X REAL:4!5=BEGIN
DBMSFOUTUT.UTFLINETHE $ALUE O% INNER X:X=
END=
DBMSFOUTUT.UTFLINETHE $ALUE O% OUTER X:X=
END=
OUTUT:THE $ALUE O% OUTER X:2!5
THE $ALUE O% INNER X:4!5
THE $ALUE O% OUTER X:2!5
3.WRITE LSL BLOC" TO CHEC" WHETHER GI$EN
NUMBER IS ARMSTRONG OR NOT.
ROGRAM:
-
8/10/2019 Systems Lab
33/39
DECLARE
NUM NUMBER5=
REM NUMBER5=
S NUMBER5:!=NUM1 NUMBER5=
BEGIN
NUM:NUM=
NUM1:NUM=
WHILENUM>!
LOO
REM:MODNUM@1!=
S:SOWERREM@3=
NUM:TRUNCNUM1!=
END LOO=
I%SNUM1THENDBMSFOUTUT.UTFLINENUM1IS ARMSTRONG NUMBER=
ELSE
DBMSFOUTUT.UTFLINENUM1IS NOT ARMSTRONG NUMBER=
END I%=
END=
OUTUT:ENTER $ALUE %OR NUM: 153
OLD 7: NUM:NUM=
NEW 7: NUM:153=
153 IS ARMSTRONG NUMBERLSL ROCEDURE SUCCESS%ULLY COMLETED.
SL>
ENTER $ALUE %OR NUM: 123
OLD 7: NUM:NUM=
NEW 7: NUM:123=
123 IS NOT ARMSTRONG NUMBERLSL ROCEDURE SUCCESS%ULLY COMLETED.
4.TO WRITE A LSL BLOC" TO CHEC" THE GI$EN STRING
IS ALINDROME OR NOT.
-
8/10/2019 Systems Lab
34/39
ROGRAM:
DECLARE
NAME1 $ARCHAR22!=
NAME2 $ARCHAR22!=L NUMBER5=
BEGIN
NAME1:NAME1=
L:LENGTHNAME1=
WHILE L>! LOO
NAME2:NAME2SUBSTRNAME1@L@1=
L:L1=
END LOO=
DBMSFOUTUT.UTFLINERE$ERSE O% STRING IS:NAME2=
I%NAME1NAME2 THEN
DBMSFOUTUT.UTFLINENAME1IS ALINDROME=ELSE
DBMSFOUTUT.UTFLINENAME1IS NOT ALINDROME=
END I%=
END=
OUTUT:ENTER $ALUE %OR NAME1: MADAM
OLD 6: NAME1:NAME1=
NEW 6: NAME1:MADAM=
RE$ERSE O% STRING IS:MADAM
MADAM IS ALINDROME
5.TO WRITE A LSL BLOC" TO %IND SUM O% DIGITS O% A
GI$EN NUMBER.
ROGRAM:
DECLARENUM NUMBER5=
REM NUMBER5=
SM NUMBER5:!=
NUM1 NUMBER5=
BEGIN
NUM:NUM=
NUM1:NUM=
-
8/10/2019 Systems Lab
35/39
WHILENUM>!
LOO
REM:MODNUM@1!=
SM:SMREM=
NUM:TRUNCNUM1!=
END LOO=DBMSFOUTUT.UTFLINENUM1 SUM O% DIGITS O% A GI$EN
NUMBERIS: SM=
END=
OUTUT:ENTER $ALUE %OR NUM: 123
OLD 7: NUM:NUM=
NEW 7: NUM:123=
SUM O% DIGITS O% 123 IS: 6
LSL ROCEDURE SUCCESS%ULLY COMLETED.
6.TO WRITE A LSL BLOC" TO GENERATE %IBONACCI
SERIES
ROGRAM:
DECLARENUM NUMBER5=
%1 NUMBER5:!=
%2 NUMBER5:1=
%3 NUMBER5=
I NUMBER5:3=
BEGIN
NUM:NUM=
-
8/10/2019 Systems Lab
36/39
DBMSFOUTUT.UTFLINETHE %IBONACCI SERIES IS:=
DBMSFOUTUT.UTFLINE%1=
DBMSFOUTUT.UTFLINE%2=
WHILEIJNUM
LOO
%3:%1%2=DBMSFOUTUT.UTFLINE%3=
%1:%2=
%2:%3=
I:I1=
END LOO=
END=
OUTUT:ENTER $ALUE %OR NUM: 1!
OLD 8: NUM:NUM=
NEW 8: NUM:1!=THE %IBONACCI SERIES IS:
!
1
1
2
3
5
8
13
21
34LSL ROCEDURE SUCCESS%ULLY COMLETED.
7. WRITE LSL ROGRAM TO %IND %ACTORIAL $ALUE
USING RE$ERSE %OR LOO
ROGRAM:
DECLARE
$FNUM%ACT NUMBER:GI$ENNUMBER=
$F%ACTORIAL NUMBER:1=
BEGIN
%OR INDEXI IN RE$ERSE 1..$FNUM%ACT LOO
-
8/10/2019 Systems Lab
37/39
$F%ACTORIAL:$F%ACTORIALINDEXI=
DBMSFOUTUT.UTFLINETHE INDEXI NUMBER IS INDEXI=
END LOO=
DBMSFOUTUT.UTFLINETHE %ACTORIAL O% $FNUM%ACTIS :
$F%ACTORIAL=
END=
OUTUT:GI$EN NUMBER 8
OLD 2: $FNUM%ACT NUMBER:GI$ENNUMBER=
NEW 2: $FNUM%ACT NUMBER:9=
THE INDEXI NUMBER IS 8
THE INDEXI NUMBER IS7
THE INDEXI NUMBER IS6
THE INDEXI NUMBER IS5
THE INDEXI NUMBER IS4
THE INDEXI NUMBER IS3THE INDEXI NUMBER IS2
THE INDEXI NUMBER IS1
THE %ACTORIAL O% 9 IS 5184!
LSL ROCEDURE SUCCESS%ULLY COMLETED.
8.TO WRITE A TRIGGER TO ENSURE THAT DET TABLE
DOESN0T CONTAIN DULICATE O% NULL $ALUES IN DETNO
COLUMN.
ROGRAM:
CREATE OR RELACE TRIGGER TRIG1 BE%ORE INSERT ON DET %OR
EACH ROW
DECLARE
A NUMBER=
BEGIN
I%:NEW.DETNO IS NULLTHEN
-
8/10/2019 Systems Lab
38/39
RAISEFALICATIONFERROR2!!!1@ERROR::DETNO CANNOT BE
NULL=
ELSE
SELECT COUNT INTO A %ROM DET WHERE DETNO:NEW.DETNO=
I%A1 THEN
RAISEFALICATIONFERROR2!!!2@ERROR:: CANNOT HA$EDULICATE DETNO=
END I%=
END I%=
END=
OUTUT:
TRIGGER CREATED.
SL>SELECT %ROM DET=
DEPTNO DNAME LOC
10 ACCOUNTING NE% &OR
20 RESEARCH DALLAS
30 SALES CHICAGO
40 OPERATIONS BOSTON
SL>INSERT INTO DET $ALUESDETN@DNAME@LOC=
OLD 1: INSERT INTO DET $ALUESDETN@DNAME@LOC
NEW 1: INSERT INTO DET $ALUES5!@MAR"ETING@HYDERABAD
1 ROW CREATED.
SL>SELECT %ROM DET=
DEPTNO DNAME LOC
10 ACCOUNTING NE% &OR
20 RESEARCH DALLAS
30 SALES CHICAGO
40 OPERATIONS BOSTON
$0 MARETING H&DERABAD
-
8/10/2019 Systems Lab
39/39
9.WRITE A LSL TRIGGER TO TRANSATIONAL AUDITING ON
SALARY COLUMN IN EM TABLE
ROGRAM:
CREATE OR RELACE TRIGGER CH"SALARY
BE%ORE UDATE O% SAL ON EM
%OR EACH ROW
WHENNEW.SALJOLD.SAL
BEGIN
RAISEFALICATIONFERROR2!5!!@SALARY CANNOT BE
DECREASED..=
END=
OUTUT:
TRIGGER CREATED.
UDATE EM54 SET SAL7!!! WHERE SAL8!!!=
SALARY CANNOT BE DECREASED