Perform Exception Handling with User-Defined Errors

On occasion, some of Brewbean’s customers mistakenly leave an item out of a basket already checked out, therefore they create a new basket containing the missing items. Though they request that the baskets be combined and hence they are not charged extra shipping. The screen has been developed to permit an employee to modify the basket id of items in the BB_BASKETITEM table to another existing basket to merge the baskets. The block has been constructed to support this screen and can be found at the end of this question. Though an exception requires to be added to trap the condition in which an invalid basket id is entered for original basket. In this situation, the UPDATE affects no rows however does not raise an Oracle error. The handler must display a message stating “invalid original basket id”. Employ a host variable named G_OLD with a value of 30 and a host variable named G_NEW with a value of 4 to give the values to the block. First confirm that no item rows exist in the BB_BASKETITEM table with a basket id of 30.
 
BEGIN
  UPDATE bb_basketitem
   SET idBasket = :g_new
   WHERE idBasket = :g_old;
END;
/

E

Expert

Verified

create or replace function "BOB_UPDATE"
(g_old in NUMBER,
g_new in NUMBER)
return VARCHAR2
is
OID NUMBER;
state_missing EXCEPTION;
begin
SELECT count(IDBASKET) INTO OID FROM BB_BASKETITEM WHERE IDBASKET=G_OLD GROUP BY  IDBASKET ;
IF OID IS NULL THEN
  RAISE state_missing;
ELSE
   UPDATE bb_basketitem SET idBasket =g_new WHERE idBasket =g_old;
END IF;
RETURN 'UPDATED SUCCESSFULLY';
EXCEPTION
   WHEN state_missing THEN
      RETURN 'INVALID BASKET ID';
   WHEN OTHERS THEN
      RETURN 'INVALID BASKET ID';
end;


Testing Code:   
SELECT BOB_UPDATE(30,4) from dual;

   Related Questions in Programming Languages

  • Q : CPU programming When a process enters

    When a process enters the CPU, your program must now "fork"and "exe" a stand alone child process. You MUST use "glxgears" for the child process.                            When a context switch occurs

  • Q : What is First in-first out First in,

    First in, first out: It is FIFO semantics of the queue data structure. Items are eliminated in the order in which they arrived in the queue; therefore older items are always eliminated before newer ones.

  • Q : Features of WordPress Normal 0 false

    Normal 0 false false

  • Q : Explain Variable declaration Variable

    Variable declaration: It is the association of a variable with a specific type. It is significant to make a distinction among the declaration of variables of primitive types and such of class types. The variable of primitive type performs as a contain

  • Q : Describe Data type Data type : It is a

    Data type: It is a specifier to build memory block of some particular size and kind. C++ provides two kinds of data types: A) Fundamental type: That is not composed

  • Q : Explain Decrement operator Decrement

    Decrement operator: It is an operator (--) which adds one to its operand. This has two forms: pre-decrement (--x) and post-decrement (x--). In its pre-decrement form, the outcome of the expression is the value of its argument subsequent to the decreme

  • Q : Explain State State : The objects are

    State: The objects are said to possess state. The present state of an object is symbolized by the joint values of its attributes. Protecting the state of an object from unsuitable inspection or modification is a significant aspect of class design and

  • Q : What is Central Processing Unit Central

    Central Processing Unit: The Central Processing Unit (that is, CPU) is the heart of a computer as it is the portion that includes the computer's capability to follow instructions. Each kind of CPU has its own instruction set.

  • Q : What is an Internet Service Provider

    Internet Service Provider: It is an Internet Service Provider (abbreviated as ISP) gives connections to the Internet for users who do not contain their own network. The ISP gives such user with their own IP address which enables them to interact with

  • Q : Define Bootstrap classes Bootstrap

    Bootstrap classes: The classes which make up the Java Platform Core Application Programming Interface (API), like those found in the java.lang, java.io and java.io packages.

©TutorsGlobe All rights reserved 2022-2023.