You are on page 1of 9

kkkkkkkkplsql

kkkkkkkkkkkkkkkkkkkkkkkkksql

1.kpossible kkkkkkkkkkkkkkkkk-combinationkofkcommandskisk kkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkknotkpossiblekinksql

3.kconditionalkchec ing kkkkiterationskallkprogrammingk kkkkkprobabilityk

-->kPl-Sqlkiskakgroupedkstructurekcalledkbloc s. k -->Bloc kofkplsql kdeclare <declarativekstatements> kbegin <executablekstatements> kexception <handlingkexceptions> kend; k-->kBeginkandkEndkarekMandatory kkkkThekuserkcanknamekthekbloc kifkheknameskthekbloc kthenkthatk kkkkkkkkbloc kbecmeskeitherkprocedurekorkfunctions

kkkkkkkkkkkkkkdbms_output.put_line() kkkkkThekabovekstatementkiskusedktokprintkthekoutputkonkthekscreen kkkkkkkinkthiskdbms_outputkiskakpac agekandkput_line()kiskakprocedure kkkkkkkwherekitkta eskakargumentk kkNote:kThekuserkshouldkexplicitlyksayksetkserveroutkonktokseekthekoutputk kkkkkkkkkkkkonkthekoutputdevice -->kTokaddktwokvariables kdeclarek kkkaknumber; kkkbknumber;korkbknumber:=20;korkbknumber:=&b; kkkcknumber; kbegin kkkkkkkkkka:=10; kkkkkkkkkkb:=20; kkkkkkkkkkc:=a+b; kkkdbms_output.put_line(' annan'||c); end; ------------------------------------------------------------------------------------------------------------

kkkkkIfkhekdoesknotkdeclarekanyknameskthenkitkisktreatedkaskanonymouskbloc

2.kNetwor kperformancekkkkkkkkkkkkk-Eachkstatementkwillkbekusedkbyktheknetwor kkksetkofkstatements kkksokthiskincreasektheknetwor k

greaterkofktwoknos kdeclare kkaknumber:=&a; kkbknumber:=&b; kbegin kkkifka>bkthen kkkkdbms_output.put_line('akikgreater'); kkkelsek kkkkdbms_output.put_line('bkiskgreater'); kkendkif; kend;

declare aknumber:=&a; bknumber:=&b; cknumber:=&c; begin ifk(a>bkandka>c)kthen dbms_output.putkline(a||'kiskgreater'); elsifk(b>c)kthen dbms_output.put_line('bkiskgreater'); else dbms_output.put_line('ckiskgreater'); endkif; end;

-----------------------------------------------------------------------------------//nestedkif declare aknumber:=&a; bknumber:=&b; cknumber:=&c; begin ifk(a>b)kthen kkifk(a>c)kthen dbms_output.put_line('akiskgreater'); kkendkif; elsifk(b>c)kthen dbms_output.put_line('bkiskgreater'); else dbms_output.put_line('ckiskgreater'); endkif; end; / -----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------//kselectedkcase

declare aknumber:=&a; bknumber:=&b; cknumber; noknumber:=&a; begin dbms_output.put_line('1.ADD,kk2.SUBkkkk3.DIVkkk4.MUL'); selectkcasekno casek1kkc:=a+b; dbms_output.put_line('Thekresultkisk'||c); casek2kc:=a-b; dbms_output.put_line('Thekresultkisk'||c); casek3kc:=a/b; dbms_output.put_line('Thekresultkisk'||c); casek4kc:=a*b; dbms_output.put_line('Thekresultkisk'||c); endkselect end; ----------------------------------------------------------------------------------------------------------------------------------------------------------------------//kitertions simplekloop loop exitkwhenk<condition?> endkloop; whilekloop whilek<condition> loop ............... endkloop; forkloop =]\ simplekloopkex: //while declare kiknumber:=1; whileki<10 loop dbms_output.put_line(i); i:=i+1; endkloop; end; declare kiknumber:=1; whileki<10 loop dbms_output.put_line(i); i:=i+1; endkloop;

end; ---------------------------------------------------------------------PROCEDURESkANDkFUNCTIONS procedureskandkfunctions declare begin end; iskakanonymouskbloc procedures -kkakbloc kofkstatementskorkinstructionskinkoneksetk -kakprocedurekhasksomeknamek -kwillknotkreturnkanykvalue procedurekwithkoutkarguments createkorkreplacekprocedurek<procedurekname>k is <declarativekstat> begin <executablekstat> exception end; createkorkreplacekprocedurekpp is begin dbms_output.put_line('hai'); end; 1.kcompilekthekprocedure 2.kexecutek<procedurekname>korkcallkinkanykbloc ; uses 1.kreusability 2.keasyktokdebug 3.kthekuserkcankdividekthekbigkprogramkintoknokofkmodulesk (procedureskorkfunctions) 4.kcleankwaykofkprogrammingkwherekthekuserkcankunderstandkthekprogramskeasily -----------------------------------------------------------------------------------//ktokdisplayknamek createkorkreplacekprocedurekpp is nokemp.empno%type:=&no; namekemp.ename%type; salarykemp.sal%type; begin selectkenamekintoknamekfromkempkwherekempno=no; dbms_output.put_line(no||'kkk'||name||'kkkkk'||salary);

end; -----------------------------------------------------------------------------------// createkorkreplacekprocedurekpp(nokinknumber) is namekemp.ename%type; salarykemp.sal%type; begin selectkenamekintoknamekfromkempkwherekempno=no; dbms_output.put_line(no||'kkk'||name||'kkkkk'||salary); end; -----------------------------------------------------------------------------------declare noknumber:=&no; begin pp(no); end; -----------------------------------------------------------------------------------procedurekta eskarguments parameters ink,kout -----------------------------------------------------------------------------------createkorkreplacekprocedurekpp(nokinknumber,dnokinknumber) is namekemp.ename%type; cntknumber; begin no:=7788; selectkenamekintoknamekfromkempkwherekempno=no; dbms_output.put_line(no||'kkk'||name); selectkcount(*)kintokcntkfromkempkwherekdeptno=dno; dbms_output.put_line('theknokofkempskwor ingkinkdept||'kkk'||dno||'rk------'||cn t); end; declare nokemp.empno%type:=&no; dnokemp.deptno%type:=&dno; begin pp(no,dno); end; --------------------------------------------------------------------------------

----createkorkreplacekprocedurekkpr(namekinkvarchar2) is salarykemp.sal%type; begin selectksalkintoksalarykfromkempkwherekename=name; dbms_output.put_line(name||'kkkkkk'||salary); end; DECLARE namekemp.ename%type:='&name'; begin pr(name); end; -----------------------------------------------------------------------------------createkorkreplacekprocedurekkpp(nokinknumber,namekoutkvarchar2,salarykoutknumber ) s begin selectkename,salkintokname,salarykfromkempkwherekempno=no; End; declare namekvarchar2(20); noknumber:=&no; salaryknumber; begin dbms_output.put_line('NOTHINGkkk'||name); pp(no,name,salary); dbms_output.put_line(name,salary); end; -----------------------------------------------------------------------------------//ksendktheknokfindkoutkthekgradek

createkorkreplacekprocedurekpp(nokinkoutknumber) is grkknumber; begin selectkgradekintokgrkfromkemp,salgradekwhereksalkbetweenklosalkandkhisalkwhereke mpno=no; no:=gr; end; declare noknumber:=&no; begin dbms_output.put_line(no); pp(no);

dbms_output.put_line(no); end;

procedurek 1.kwillknotkreturnkanykvalue 2.kcallkbykreference 3.kexecuteskslowly

functions 1.kwillkreturnkthekvalues 2.kcallkbykvalue 3.kfast

//functions createkorkreplacekfunctionkfun(nokinkemp.empno%type,salarykoutknumber)kreturnkva rchar2 is salarykemp.sal%type; namekemp.ename%type; begin selectkename,salkintokname,salarykfromkempkwherekempno=no; returnkname; end; declare salarykemp.sal%type; noknumber; namekvarchar2(20); begin name:=fun(no,salary); dbms_output.put_line(no||salary||name); END;

----------------------------------------------------------------------------------//k createkorkreplacekfunctionkfun(nokinkoutknumber)k returnknumber is salaryknumber; begin selectksalkintoksalarykfromkempkwherekempno=no; no:=salary; returnk1; exception whenkno_data_foundkthenk kkreturnk0; end;

declare noknumber:=&no; foundknumber; begin dbms_output.put_line(no); found:=fun(no); ifkfound=0kthen kkdbms_output.put_line('sorryktherekisknotkemp'); else dbms_output.put_line(no||'kkkk'||found); endkif; end;

-----------------------------------------------------------------------------------//k PACKAGES

-kpac ageskrkcollectionkofkprocedureskandkfunctions -kuses 1.ksimplektokdiferentiate 2.ktheknameskofkthekprocedureskwillknotkbekclashed 1.kdeclarekthekpac agekwithkallkthekdeclarationkofkprocedureskandkfunctions 2.kdeclarekthekpac agekbody createkorkreplacekpac agekpac is procedurekdisplay(nokinknumber); procedurekdisplay(namekinkvarchar2); functionkfun(nokinknumber)kreturnkvarchar2; endkpac ; createkorkreplacekpac agekbodykpac is procedurekdisplay(nokinkNUMBER) is namekemp.ename%type; begin selectkenamekintoknamekfromkempkwherekempno=no; dbms_output.put_line(name); end; procedurekdisplay(namekinkvarchar2) is salarykemp.sal%type; begin selectksalkintoksalarykfromkempkwherekename=name; dbms_output.put_line(salary); end; functionkfun(nokinknumber)kreturnkvarchar2 is namekemp.ename%type; begin

selectkenamekintoknamekfromkempkwherekempno=no; returnkname; end; endkpac ;

overloadedkprocedures samekprocedureknameskbutkwithkdifferentksignatures(arguments)

You might also like