--%>

Identify Customers in SQL

The company wish to provide an incentive of free shipping to such customers who have not returned for 2 months. Build a procedure named PROMO_SHIP_SP which determines these customers are and then updates the BB_PROMOLIST table accordingly. The procedure employs the below information:
 
1. Date cutoff = Any customers who do not shopped on the site as this date must be involved as incentive
participants. Utilize the basket creation date to reflect the shopper activity dates.

2. Month = Three-character month (like APR) which must be added to the promotion table to point out which
month the free shipping is obtainable.

3. Year = Four-digit year pointing the year the promotion is efficient

4. PROMO_FLAG = 1 symbolizing free shipping).
 
The BB_PROMOLIST table too has a USED column, that includes a default value of “N” and is updated to a “Y” whenever the shopper employs the promotion. Test the procedure with a cutoff date of 15-FEB-03. Allocate the free shipping for the month of APR and the year of 2003.

E

Expert

Verified

create or replace procedure "PROMO_SHIP_SP"(cutoff date)
is
TMON VARCHAR2(3);
TYEAR VARCHAR2(4);
PFLAG VARCHAR2(2);
TUSED VARCHAR2(1);
TID NUMBER;
begin
FOR rset IN (SELECT * FROM BB_SHOPPER where DTENTERED<cutoff)
LOOP
   SELECT count(*) INTO TID FROM BB_PROMOLIST WHERE IDSHOPPER =rset.IDSHOPPER;
   TUSED :='N';
   PFLAG :='0';
  
   IF TID <> 0 THEN      
       TMON :=TO_CHAR (TO_DATE(rset.DTENTERED, 'DD-MM-YYYY'),'MON');
       TYEAR :=TO_CHAR (TO_DATE(rset.DTENTERED, 'DD-MM-YYYY'),'YYYY');
       IF TMON='APR' and TYEAR='2003' THEN
              PFLAG :='1';
       END IF;
       UPDATE BB_PROMOLIST SET MONTH=TMON,YEAR=TYEAR,PROMO_FLAG=PFLAG,USED=TUSED WHERE IDSHOPPER=rset.IDSHOPPER;
   END IF;
END LOOP;

EXCEPTION
WHEN OTHERS THEN
   raise_application_error(-20001,'An error was encountered - '||SQLCODE||' -ERROR- '||SQLERRM);
end;

   Related Questions in Programming Languages

  • 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 Throws clause Throws clause :

    Throws clause: It is a clause in a method header pointing that one or additional exceptions will be propagated from this technique. For example:    public int find(String s) throws NotFoundExc

  • Q : Define Java virtual machine or JVM

    Define Java virtual machine (JVM): A Java Virtual Machine (JVM) is an abstract computing machine, or virtual machine (set of computer software programs and data structures) which is a platform-independent execution environment that converts Java bytec

  • Q : Explain the difference between the

    Explain the difference between the Interpreter and Compiler?

  • Q : What is the way to use XForms What is

    What is the way to use XForms?

  • Q : Define the term Blank final variable

    Blank final variable: A final variable which is not initialized as portion of its declaration. This variable should be initialized in either an instance initialization block or every of the constructors for its class before it is employed. A static bl

  • Q : What are the difference between XSLT

    What are the difference between XSLT and XPath?

  • Q : What do you mean by java AWT What do

    What do you mean by the term java AWT? Describe in brief.

  • Q : Explain the reason to not carry on

    Explain the reason to not carry on extending HTML.

  • Q : Explain Right shift operator Right

    Right shift operator: Right shift operator (>>) is the bit manipulation operator. It shifts the bits in its left operand zero (0) or many places to the right, according to the value of its accurate operand. The most important bit from before the