473,396 Members | 2,014 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes and contribute your articles to a community of 473,396 developers and data experts.

EXCEPTIONS - 2

debasisdas
8,127 Expert 4TB
Sample Example Of Zero_divide
===============================
Expand|Select|Wrap|Line Numbers
  1. Declare
  2. I Int:=&i;
  3. J Int:=&j;
  4. K Int;
  5. Begin
  6. K:=i/j;
  7. Dbms_output.put_line(k);
  8. Exception
  9. --if j=0 then (dividng the number by zero)
  10. When Zero_divide Then
  11. Raise_application_error(-20002,'cant Divide By Zero.....!');
  12. When Others Then
  13. Raise_application_error(-20003,'some Other Error........!');
  14. End;
  15.  
Zero_divide----This exception is raised when in any number id divided by zero in arithmetic operations.

Sample Example Of No_data_found
==============================
Expand|Select|Wrap|Line Numbers
  1. Declare
  2. Name Varchar2(20);
  3. No Int:=&no;
  4. Begin
  5. Select Ename Into Name From Emp Where Empno=no;
  6. Dbms_output.put_line(name);
  7. Exception
  8. When No_data_found Then
  9. Raise_application_error(-20002,'no Data Is Found For This Record.....!');
  10. When Others Then
  11. Raise_application_error(-20003,'some Other Error........!');
  12. End;
  13.  
No_data_found---This exception is raised whan any select into statment fails to retrive any data from database table. This may create eror in further data processing if left unhandled.

sample example of invalid_cursor
=============================
Expand|Select|Wrap|Line Numbers
  1. DECLARE
  2. CURSOR c1 IS SELECT ename FROM emp WHERE ROWNUM < 11;
  3. name emp.ename%TYPE;
  4. BEGIN
  5. OPEN c1;
  6. LOOP
  7. FETCH c1 INTO name;
  8. EXIT WHEN c1%NOTFOUND;
  9. dbms_output.put_line(c1%ROWCOUNT || '. ' || name);
  10. END LOOP;
  11. --cursor is closed
  12. CLOSE c1;
  13. --again trying to access the cursor variable after cursor is closed ,which raises an exception
  14. dbms_output.put_line(c1%ROWCOUNT); 
  15. exception
  16. when invalid_cursor then
  17. raise_application_error(-20001,'invalid operation in cursor');
  18. END;
  19.  
invalid_cursor--This explanation is self explanatory. Raises if there is any invalid cursor related operations.
Note --In the above example ,it raise the exception because the program tries to access the cursor variable %ROWCOUNT after the cursor is closed.

Sample Example Of DUP_VAL_ON_INDEX
==================================
Expand|Select|Wrap|Line Numbers
  1. create procedure insdept(num  number,name varchar2)
  2. is
  3. begin
  4. insert into dept(deptno,dname) values (num,name);
  5. commit;
  6. dbms_output.put_line('One row inserted...!');
  7. exception
  8. when dup_val_on_index then
  9. raise_application_error(-20001,'duplicate entry...!');
  10. when others then
  11. raise_application_error(-20002,'some other error occured...!');
  12. end;
  13.  
DUP_VAL_ON_INDEX-----This Exception is raised if a duplicate value is inserted on a primary key / unique field . Used to maintain data integrity.


Sample example showing TOO_MANY_ROWS
==================================
Expand|Select|Wrap|Line Numbers
  1. declare
  2. name varchar2(20);
  3. begin
  4. select ename into name from emp where deptno=&deptnumber;
  5. dbms_output.put_line(name);
  6. exception
  7. when NO_DATA_FOUND then
  8. raise_application_error(-20001,'no such data found...1');
  9. when TOO_MANY_ROWS then
  10. raise_application_error(-20002,'more than one matching record found...!');
  11. when OTHERS then
  12. raise_application_error(-20003,'some unexpected error occured...!');
  13. end;
  14.  
  15.  
TOO_MANY_ROWS---This exception is raised when more data is selected than that can be stored in the target variable in a select into statment.


Also check EXCEPTIONS - 3
Jun 2 '07 #1
0 3874

Sign in to post your reply or Sign up for a free account.

Similar topics

16
by: David Turner | last post by:
Hi all I noticed something interesting while testing some RAII concepts ported from C++ in Python. I haven't managed to find any information about it on the web, hence this post. The problem...
21
by: dkcpub | last post by:
I'm very new to Python, but I couldn't find anything in the docs or faq about this. And I fished around in the IDLE menus but didn't see anything. Is there a tool that can determine all the...
26
by: OvErboRed | last post by:
I just read a whole bunch of threads on microsoft.public.dotnet.* regarding checked exceptions (the longest-running of which seems to be <cJQQ9.4419 $j94.834878@news02.tsnz.net>. My personal...
9
by: Gianni Mariani | last post by:
I'm involved in a new project and a new member on the team has voiced a strong opinion that we should utilize exceptions. The other members on the team indicate that they have either been burned...
6
by: RepStat | last post by:
I've read that it is best not to use exceptions willy-nilly for stupid purposes as they can be a major performance hit if they are thrown. But is it a performance hit to use a try..catch..finally...
14
by: dcassar | last post by:
I have had a lively discussion with some coworkers and decided to get some general feedback on an issue that I could find very little guidance on. Why is it considered bad practice to define a...
8
by: cat | last post by:
I had a long and heated discussion with other developers on my team on when it makes sense to throw an exception and when to use an alternate solution. The .NET documentation recommends that an...
1
by: Anonieko | last post by:
Understanding and Using Exceptions (this is a really long post...only read it if you (a) don't know what try/catch is OR (b) actually write catch(Exception ex) or catch{ }) The first thing I...
2
by: Zytan | last post by:
I know that WebRequest.GetResponse can throw WebException from internet tutorials. However in the MSDN docs: http://msdn2.microsoft.com/en-us/library/system.net.webrequest.getresponse.aspx It...
0
RedSon
by: RedSon | last post by:
Chapter 3: What are the most common Exceptions and what do they mean? As we saw in the last chapter, there isn't only the standard Exception, but you also get special exceptions like...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.