Home » SQL & PL/SQL » SQL & PL/SQL » Predefined Exception
Predefined Exception [message #302775] Wed, 27 February 2008 00:27 Go to next message
spmano1983
Messages: 269
Registered: September 2007
Senior Member
Friends,

Why the oracle Predefined error number between -20000 to -20999?

Any specific reason?

Thanks

Mano
Re: Predefined Exception [message #302779 is a reply to message #302775] Wed, 27 February 2008 00:32 Go to previous messageGo to next message
Michel Cadot
Messages: 64109
Registered: March 2007
Location: Nanterre, France, http://...
Senior Member
Account Moderator
There are not predefined, this is custom range.
You choose to put it want you what you want.

You are a newbie, post in newbie forum.
Read the sticky Read THIS before posting

Regards
Michel
Re: Predefined Exception [message #302788 is a reply to message #302775] Wed, 27 February 2008 00:44 Go to previous messageGo to next message
spmano1983
Messages: 269
Registered: September 2007
Senior Member
Sorry michel

How we can set the our own ranges?

Re: Predefined Exception [message #302796 is a reply to message #302788] Wed, 27 February 2008 00:56 Go to previous messageGo to next message
Michel Cadot
Messages: 64109
Registered: March 2007
Location: Nanterre, France, http://...
Senior Member
Account Moderator
You can't set anything.
You have range -20000 to -20999 for you, other codes are for Oracle.

Regards
Michel
Re: Predefined Exception [message #302803 is a reply to message #302775] Wed, 27 February 2008 01:09 Go to previous messageGo to next message
spmano1983
Messages: 269
Registered: September 2007
Senior Member
My question is
Why this range should be 20000 to -20999?

Re: Predefined Exception [message #302804 is a reply to message #302803] Wed, 27 February 2008 01:13 Go to previous messageGo to next message
pablolee
Messages: 2834
Registered: May 2007
Location: Scotland
Senior Member
spmano1983 wrote on Wed, 27 February 2008 07:09
My question is
Why this range should be 20000 to -20999?



Because that is what Oracle have decreed. Do you understand yet what these numbers represent? Have you read the documentation on exception handling? If not, why not? If you have, what exactly is your confusion? Please be clear.
Thanks
Re: Predefined Exception [message #302805 is a reply to message #302775] Wed, 27 February 2008 01:15 Go to previous messageGo to next message
spmano1983
Messages: 269
Registered: September 2007
Senior Member
Friend,

Can you send me any documentation link?

Thanks
Mano
Re: Predefined Exception [message #302809 is a reply to message #302805] Wed, 27 February 2008 01:19 Go to previous messageGo to next message
pablolee
Messages: 2834
Registered: May 2007
Location: Scotland
Senior Member
spmano1983 wrote on Wed, 27 February 2008 07:15
Friend,

Can you send me any documentation link?

Thanks
Mano

I can, yes. I would first of all say, however, that it is dissappointing that you couldn't SEARCH for it. here is the documentation
Re: Predefined Exception [message #302834 is a reply to message #302775] Wed, 27 February 2008 02:21 Go to previous messageGo to next message
spmano1983
Messages: 269
Registered: September 2007
Senior Member
Still i have confused.

Anybody explain brief about the Ranges. Why should be

(-20000 to -209999).

I hope somebody will clear my doubt.

Re: Predefined Exception [message #302841 is a reply to message #302834] Wed, 27 February 2008 02:38 Go to previous messageGo to next message
Frank
Messages: 7880
Registered: March 2000
Senior Member
Look, there is nothing to understand here. Just remember.
If YOU want to throw a user-defined exception (e.g. the entered number should be between 1 and 4, but the user entered 5), you HAVE to use an exception-number between -20000 and -20999.
Why? Just because.

The rest of the numbers is claimed by Oracle itself.
Re: Predefined Exception [message #302923 is a reply to message #302841] Wed, 27 February 2008 06:21 Go to previous messageGo to next message
Littlefoot
Messages: 20894
Registered: June 2005
Location: Croatia, Europe
Senior Member
Account Moderator
It seems that @spmano1983 doesn't understand what this "range" means.

So: Oracle has created many, and every new version produces several more exceptions. These are all ORA-xxxxx errors (for example, ORA-00942 means that a table or a view does not exist). You can use any of them, but Oracle also allows you to create your own exceptions. These exceptions can not be out of range you've mentioned: the lowest number may be 20000, and the highest 20999. Thousand of them should be enough for you, i.e. you can create 1E3 your own exceptions, such as Frank told you - "valid numbers are 1, 2, 3, 4" or "rabbit may be white but not black", "your head is too square to fit into this helmet" etc.

You may, of course, try to use any other number, not only these between 20000 and 20999. Why not? Even better, here's an example: first, a correct one:
SQL> begin
  2    if to_char(sysdate, 'yyyy') = '2008' then
  3       raise_application_error(-20234, 'Anno Domini MMVIII');
  4    end if;
  5  end;
  6  /
begin
*
ERROR at line 1:
ORA-20234: Anno Domini MMVIII
ORA-06512: at line 3
Now let's change error number to something out of range (I like 9:42, so I'll use that one):
SQL> l3
  3*      raise_application_error(-20234, 'Anno Domini MMVIII');
SQL> c/-20234/-942/
  3*      raise_application_error(-942, 'Anno Domini MMVIII');
SQL> l
  1  begin
  2    if to_char(sysdate, 'yyyy') = '2008' then
  3       raise_application_error(-942, 'Anno Domini MMVIII');
  4    end if;
  5* end;
SQL> /
begin
*
ERROR at line 1:
ORA-21000: error number argument to raise_application_error of -942 is out of range
ORA-06512: at line 3


SQL>
As you can see, no problem with Oracle, but your code might suffer if you don't do it properly.

[EDIT: removed quotes around error number ./fa/1604/0/ ]

[Updated on: Wed, 27 February 2008 07:13]

Report message to a moderator

Re: Predefined Exception [message #302937 is a reply to message #302923] Wed, 27 February 2008 07:05 Go to previous messageGo to next message
pablolee
Messages: 2834
Registered: May 2007
Location: Scotland
Senior Member
raise_application_error('-20234', 'Anno Domini MMVIII');

Just out of interest, why put the error number parameter as a string rather than a number?
Re: Predefined Exception [message #302938 is a reply to message #302937] Wed, 27 February 2008 07:10 Go to previous messageGo to next message
Littlefoot
Messages: 20894
Registered: June 2005
Location: Croatia, Europe
Senior Member
Account Moderator
Good question! ./fa/1600/0/
Even if you torture me, I wouldn't know why. But I'll fix it immediately! Thank you and - sorry! I really don't know what was I thinking/doing at the moment.
Re: Predefined Exception [message #302943 is a reply to message #302938] Wed, 27 February 2008 07:14 Go to previous message
pablolee
Messages: 2834
Registered: May 2007
Location: Scotland
Senior Member
Phew, I thought I'd missed a trick Smile
Previous Topic: Bulk insert
Next Topic: Getting the avarage time pl/sql
Goto Forum:
  


Current Time: Mon Dec 05 08:48:30 CST 2016

Total time taken to generate the page: 0.09272 seconds