Raise Application Error Call
Contents |
Kyte � Last updated: August 28, 2013 - 7:31 pm UTC Category: Database � Version: 8.1.7 Whilst you are here, check out some content from the AskTom team: Are your SQL Plus raise_application_error oracle scripts going to hell? Latest Followup You Asked Tom 1. I have
Raise_application_error Vs Raise
a procedure, where in I drop partitions every day and add partitions. My question is about the exception section. raise_application_error(-20001 Do I have to give specific exception conditions to handle the erros which are possible while dropping and adding partitions, or should I leave it by just giving the when others then oracle raise exception, or should I leave it alone by not giving the exception section at all. what are the possible erros which can occur while trying to create a partition and trying to drop a partition. 2. The use of pragma exception init is very clear, but Why do you have to use a raise application error. Can I just use a regular exception, and
Pragma Exception_init And Raise Application Error
raise it when I require to. I dont see the specific use of raise application error. what is the advantage of raise application error over a regular exception which you declare in the exception section and use it. (the only advantage seems to be that you can assign a number(20001 to 20999) to the error.) correct me if Iam wrong. and we said... 1) A when others is almost always a BUG unless it is immediately followed by a RAISE. The point of an exception block is to catch exceptional conditions you are EXPECTING, handle them gracefully and continue. For example, lets say you have a procedure that will either INSERT a new record or UPDATE an existing one depending on whether or not it exists. You could code: begin insert into t ( columns.... ) values ( values ..... ); exception when dup_val_on_index then -- record already exists, lets update it update t set .... = .... where ....; end; Now, if that was coded: begin insert into t ( columns.... ) values ( values ..... ); exception when dup_val_on_index then -- record already exists, lets update i
SQL TuningSecurityOracle UNIXOracle LinuxMonitoringRemote supportRemote plansRemote servicesApplication Server ApplicationsOracle FormsOracle PortalApp UpgradesSQL ServerOracle ConceptsSoftware SupportRemote Support Development Implementation Consulting StaffConsulting PricesHelp Wanted! Oracle PostersOracle Books Oracle Scripts Ion Excel-DB raise_application_error parameters Don Burleson Blog
raise application error in sql server RAISE_APPLICATION_ERROR tips Oracle Database Tips by Burleson Consulting March 3, 2015 Question: What does the PL/SQLRaise_application_error Number Range
raise_application_error code do? Answer: The raise_application_error is actually a procedure defined by Oracle that allows the developer to raise an exception and associate an error number and message with the procedure. https://asktom.oracle.com/pls/apex/f?p=100:11:0::::P11_QUESTION_ID:1155066278457 This allows the application to raise application errors rather than just Oracle errors. Error numbers are defined between -20,000 and -20,999. Oracle provides the raise_application_error procedure to allow you to raise custom error numbers within your applications. You can generate errors and their associated text starting with -20000 and proceeding through -20999 (a grand total of 1,000 error numbers that you http://www.dba-oracle.com/t_raise_application_error.htm can use). Below we illustrate the use of the raise_application_error procedure. Using the raise_application_error procedure: DECLARE Balance integer := 24; BEGIN IF (nBalance <= 100) THEN Raise_Application_Error (-20343, 'The balance is too low.');END IF;END; In this example, error number -20343 is raised if the value of nBalance isn't greater than 100, yielding a message that looks like this: ORA-20343: The balance is too low. All other numbers belong to Oracle for its own errors. The message can be anything that will fit in a varchar2(2000). The final parameter passed to the procedure is a Boolean(true/false) that tells the procedure to add this error to the error stack or replace all errors in the stack with this error. Passing the value of 'True' adds the error to the current stack, while the default is 'False'. SQL> create or replace procedure test_var2 (n_test IN number := 0,3 n_result OUT number)4 as5 begin 6 if n_test > 100 then7 raise_application_error(-20010,'Number Too Large');8 end if;9 n_result := n_test;10 end; 11 / Procedure created. SQL> declare2 n_numb number := &Number;3 n_2 number := 0;4 begin5 test_var(n_numb,
here for a quick overview of the site Help Center Detailed answers to any questions you might have Meta Discuss the workings and policies of this site About Us Learn more about Stack Overflow http://stackoverflow.com/questions/1760596/oracle-what-is-the-situation-to-use-raise-application-error the company Business Learn more about hiring developers or posting ads with us Stack Overflow Questions Jobs Documentation Tags Users Badges Ask Question x Dismiss Join the Stack Overflow Community Stack Overflow is a community of 6.2 million programmers, just like you, helping each other. Join them; it only takes a minute: Sign up Oracle: what is the situation to use RAISE_APPLICATION_ERROR? up vote 13 down vote favorite 5 We can use RAISE raise application to fire an exception. What particular situations do we need to use RAISE_APPLICATION_ERROR? Thanks. oracle share|improve this question asked Nov 19 '09 at 2:56 Ricky 8,3982762100 I found a useful link for similar question. toadworld.com/platforms/oracle/b/weblog/archive/2010/07/14/… –gmail user Feb 6 '14 at 16:30 add a comment| 4 Answers 4 active oldest votes up vote 23 down vote accepted There are two uses for RAISE_APPLICATION_ERROR. The first is to replace generic Oracle raise application error exception messages with our own, more meaningful messages. The second is to create exception conditions of our own, when Oracle would not throw them. The following procedure illustrates both usages. It enforces a business rule that new employees cannot be hired in the future. It also overrides two Oracle exceptions. One is DUP_VAL_ON_INDEX, which is thrown by a unique key on EMP(ENAME). The other is a a user-defined exception thrown when the foreign key between EMP(MGR) and EMP(EMPNO) is violated (because a manager must be an existing employee). create or replace procedure new_emp ( p_name in emp.ename%type , p_sal in emp.sal%type , p_job in emp.job%type , p_dept in emp.deptno%type , p_mgr in emp.mgr%type , p_hired in emp.hiredate%type := sysdate ) is invalid_manager exception; PRAGMA EXCEPTION_INIT(invalid_manager, -2291); dummy varchar2(1); begin -- check hiredate is valid if trunc(p_hired) > trunc(sysdate) then raise_application_error (-20000 , 'NEW_EMP::hiredate cannot be in the future'); end if; insert into emp ( ename , sal , job , deptno , mgr , hiredate ) values ( p_name , p_sal , p_job , p_dept , p_mgr , trunc(p_hired) ); exception when dup_val_on_index then raise_application_error (-20001 , 'NEW_EMP::employee called '||p_name||' already exists' , true); when invalid_manager then raise_application_error (-20002 , 'NEW_EMP::'||p_mgr ||' is not a valid manager'); end; / How it looks: SQL> exec new_emp ('DUGGA