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 : Define Assembler Assembler : The

    Assembler: The program employed to translate a program which is written in assembly language into the binary form of a specific instruction set.

  • Q : Define Single line comment Single line

    Single line comment: A comment is in the form:     // this line will be avoided by the compiler.

  • 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.

  • Q : Define Protocol Protocol : It is a set

    Protocol: It is a set of rules for interaction between two processes. The protocol is generally specified in a Uniform Resource Locator (abbreviated as URL) to point out how a specific resource must be transferred from a Web server to the requesting c

  • Q : Explain UpdatePanel control Briefly

    Briefly explain about the UpdatePanel control.

  • Q : Describe the term Context Switch

    Describe the term Context Switch.

  • Q : Define Unconditional Jumps

    Unconditional Jumps: Jumps which are not strictly upwards in the block hierarchy can require extensive control-flow manipulation, including creation of redundant code, and should be avoided if possible. Such jumps add considerable modeling overhead fo

  • Q : Situations where AJAX must not be used

    Explain the situations in which the AJAX must not be used.

  • Q : Throughout system testing the

    Someone complains that throughout system testing the application frequently crashes. What probable process problem does which indicate?

  • Q : What is Super class Super class: It is

    Super class: It is a class which is extended by one or more sub classes. All Java classes encompass the Object class as a super-class.

©TutorsGlobe All rights reserved 2022-2023.