--%>

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 : Explain why java is so important for

    The internet aided java to the forefront of programming. And java consequently has had a deep effect on the internet. The reason for this is highly simple: java uses the universe of objects that can travel freely in cyber space. In a network, two broad categories of

  • Q : Define Homology Modeling In Structural

    Homology Modelling is a process in which models are generated. The generated models may be conceptual or graphical or/and mathematical.So, we have different methods, tools and techniques for all kinds of modeling.Modelling methods are broadly classifi

  • Q : Components of ASP.NET AJAX architecture

    Name the components of ASP.NET AJAX architecture?

  • Q : Static and dynamic modeling in

    Illustrate in brief the term static and dynamic modeling in programming?

  • Q : Describe object-oriented programming

    Briefly describe object-oriented programming (OOP)?

  • Q : Write a program that prints out 20

    Write a program that prints out 20 random cards form a standard deck of 52 cards. Make sure the program prints out different sets of cards from one run to the next.

  • Q : Networking Homework Assignment : A

    Homework Assignment : A Barbershop Problem Due: November 20, 2012 In this assignment, you are asked to write a multithreading problem to simulate the barbershop problem, which is a classical synchronization problem. The problem is taken from William Stallings's Operating Systems: Internals and D

  • Q : ArrayLists I. The Assignment The

    I. The Assignment The Bashemin Parking Garage contains a single lane that can hold up to ten cars.  Arriving cars enter the garage at the rear and are parked in the empty space nearest to the front.  Departing cars exit only from the front.  If a cu

  • Q : Explain SQA personnel regarding

    Do you think that the role of SQA personnel regarding inspections or testing?

  • Q : Differentiate overriding and

    Differentiate overriding and overloading method?