Welcome to Scribd, the world's digital library. Read, publish, and share books and documents. See more
Download
Standard view
Full view
of .
Save to My Library
Look up keyword
Like this
30Activity
0 of .
Results for:
No results containing your search query
P. 1
PL SQL Coding

PL SQL Coding

Ratings:

5.0

(1)
|Views: 997 |Likes:
Published by writesmd
Oracle Plsql Coding
Oracle Plsql Coding

More info:

Published by: writesmd on Jul 16, 2008
Copyright:Attribution Non-commercial

Availability:

Read on Scribd mobile: iPhone, iPad and Android.
download as DOC, PDF, TXT or read online from Scribd
See more
See less

03/11/2013

pdf

text

original

 
PL / SQL CodingAmirtharaj.
CURSORSExplicit Cursor Normal - Select
declaredno emp.deptno%type:=&Dept_No;eno emp.empno%type;ename1 emp.ename%type;cursor c1 is select empno,ename from emp where deptno=dno;beginopen c1;loopfetch c1 into eno,ename1;exit when c1%notfound;dbms_output.put_line(eno);dbms_output.put_line(ename1);end loop;dbms_output.put_line(c1%rowcount);close c1;end;
Explicit Cursor Normal -Update
declaredno emp.deptno%type:=&Dept_No;eno emp.empno%type;ename1 emp.ename%type;esal emp.sal%type;cursor c1 is select empno,ename,sal from emp where deptno=dno;beginopen c1;loopfetch c1 into eno,ename1,esal;exit when c1%notfound;if esal<1200 thenupdate emp set comm=sal*.6 where deptno=dno and (sal<1200);elsif esal>1200 and esal<=1500 thenupdate emp set comm=sal*.4 where deptno=dno and (sal>1200 and sal<=1500);elseupdate emp set comm=sal*.5 where deptno=dno and (sal>1500);end if;dbms_output.put_line(eno);dbms_output.put_line(ename1);end loop;commit;dbms_output.put_line(c1%rowcount);close c1;end;
Explicit Cursor Normal -Update - Cursor for Loop
set server output on;declaredno emp.deptno%type:=&Dept_No;cursor c1 is select empno,ename,sal from emp where deptno=dno;r1 c1%rowtype;beginfor r1 in c1loopif r1.sal<1200 thenupdate emp set comm=sal*.06 where deptno=dno and (sal<1200);elsif r1.sal>1200 and r1.sal<=1500 thenupdate emp set comm=sal*.04 where deptno=dno and (sal>1200 and sal<=1500);elseupdate emp set comm=sal*.05 where deptno=dno and (sal>1500);end if;end loop;commit;exceptionwhen no_data_found then
dbms_output.put_line('Nodata');
end;
1
 
PL / SQL CodingAmirtharaj.
Explicit Cursor Normal -Update - Cursor for Loop - Row Count
declaredno emp.deptno%type:=&Dept_No;cursor c1 is select empno,ename,sal from emp where deptno=dno;r1 c1%rowtype;beginfor r1 in c1loopexit when c1%rowcount>1if r1.sal<1200 thenupdate emp set comm=sal*.08 where deptno=dno and (sal<1200);elsif r1.sal>1200 and r1.sal<=1500 thenupdate emp set comm=sal*.09 where deptno=dno and (sal>1200 and sal<=1500);elseupdate emp set comm=sal*.1 where deptno=dno and (sal>1500);end if;end loop;commit;exceptionwhen no_data_found thendbms_output.put_line('Nodata');when invalid_number thendbms_output.put_line('Nodata');end;
Implicit Cursor - sql%rowcount , sql%notfound
declaredno emp.deptno%type:=&Dept_No;esal emp.sal%type:=&Esal;beginupdate emp set sal=sal+esal where deptno=dno;dbms_output.put_line(sql%rowcount);if sql%notfound thendbms_output.put_line('No Data');end if;end;
Cursor – Parameterized
set serveroutput on;declarea dept.deptno%type:=&Deptno;b dept.dname%type;cursor c1(d1 dept.deptno%type) is select dname from dept where deptno=d1;beginopen c1(a);fetch c1 into b;if c1%notfound thendbms_output.put_line('No');elsedbms_output.put_line(b);end if;close c1;end;
2
 
PL / SQL CodingAmirtharaj.
EXCEPTION – ERROR HANDLINGException - Predefined
declarea dept.deptno%type:=&DEPT_NO;b emp.empno%type;beginselect empno into b from emp where deptno=a;dbms_output.put_line(b);exceptionwhen no_data_found thendbms_output.put_line('No Depts' );when too_many_rows thendbms_output.put_line('More Employees' );end;
Exception - when dup_val_on_index and when others
begininsert into dept(deptno,dname,loc) values(&a,'&b','&c');dbms_output.put_line(SQL%rowcount);exceptionwhen dup_val_on_index thendbms_output.put_line('Duplicate Depts' );when others thendbms_output.put_line('Invalid Depts Insers' );end;
Exception - User Defined
declarea dept.deptno%type:=&Deptno;b dept.dname%type:='&Dept_Name';c exception;beginupdate dept set dname=b where deptno=a;if sql%notfound thenraise c;end if;exceptionwhen c thendbms_output.put_line(' Depts should be exists' );when others thendbms_output.put_line(' Depts should be numeric' );end;
Exception - SQL Code , SQL Errm
begininsert into dept(deptno,dname,loc) values(&a,'&b','&c');dbms_output.put_line(SQL%rowcount);exceptionwhen dup_val_on_index thendbms_output.put_line('Duplicate Depts' );dbms_output.put_line(SQLerrm );dbms_output.put_line(SQLcode);when others thendbms_output.put_line('Invalid Depts Inserts' );end;
3

Activity (30)

You've already reviewed this. Edit your review.
1 hundred reads
1 thousand reads
Dragan liked this
Hari2905 liked this
shrunash liked this
titun8723 liked this
gangadhar1310 liked this
TEJASKO liked this
Amit Kasana liked this
gangadhar1310 liked this

You're Reading a Free Preview

Download
/*********** DO NOT ALTER ANYTHING BELOW THIS LINE ! ************/ var s_code=s.t();if(s_code)document.write(s_code)//-->