--%>

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 : Describe the term Context Switch

    Describe the term Context Switch.

  • Q : Explain For loop For loop : This is one

    For loop: This is one of the Java's three control structures employed for looping. The other two are while loop and do loop. A for loop includes of a loop header and a loop body. The header comprises of three expressions separated by two semicolons an

  • Q : Security Manager on Applets Write down

    Write down some of the restrictions imposed by using a Security Manager on Applets?

  • Q : What is Pop-up menu Pop-up menu : A

    Pop-up menu: A menu of actions which is generally not visible on the screen till a mouse button is clicked. The Popup menus assist to keep a user interface from becoming cluttered.

  • Q : Explain the applications of testing

    Explain the applications of testing life cycle.

  • Q : Define the term XSL-FO Define the term

    Define the term XSL-FO. Answr: A sub-element of XSL used for explaining font sizes, how information flows from one page to other and page layouts.

  • Q : Explain Call-by-value Call-by-value:

    Call-by-value: The semantics of passing an argument to a method in which a copy of actual argument value is taken and positioned in a separate memory location, symbolized by the corresponding formal argument. As an outcome, assignment to the formal ar

  • Q : Illustrates XML is an important

    Illustrates XML is an important development.

  • Q : Explain Command-line argument

    Command-line argument: The arguments passed to a program whenever it is run. The Java program receives such in the single formal argument to its major method: public static void main(String[] args)

  • Q : Define Passing by value Passing by

    Passing by value: In this process separate memory builds for formal arguments and when any modifications done on formal variables, it will not influence the real variables. Therefore actual variables are preserved in this situation.