Skip to Main Content

SQL & PL/SQL

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

PL/ SQL homework question.

575745May 3 2007 — edited May 3 2007
I turn here because I have a bad teacher and I don't want to drop her course but I need help with trying to get a procedure to work. Be patient I will post the assignment first. Then I will post the code I created and the subsequent error that I get. Your help would be greatly appreciated. WARNING: It will be a long post.


Assignment:

The company wants to offer an incentive of free shipping to those customers who have not returned for two months. Create a procedure named PROMO_SHIP_SP that determines who these customers are and then updates the BB_PROMOLIST table accordingly. The procedure uses the following information:

1. Date cutoff = Any customers who have not shopped on the site since this date should be included as incentive participants. use the basket created date to reflect shopper activity dates.
2.) Month = Three-Character month (Such as APR) that should be added to the promotion table to indicate which month the free shipping is available.
3.) Year = Four digit year indicating the year the promotion is effective.
4.) PROMO_FLAG = 1 (representing free shipping).

The BB_PROMOLIST table also has a USED column, which contains a default value of 'N' and is updated to a 'Y' when the shopper uses the promotion. Test the procedure with a cutoff date of 15-FEB-03. Assign the free shipping for the month of APR and the year 2003.

****************************************************************************************************
Here is what I wrote based on the instructions:

create or replace procedure promo_ship1_sp
(--p_day in DATE,
p_mth in DATE,
p_yr in DATE)

IS

CURSOR cur_ship IS
SELECT idshopper, MAX(dtcreated) dt
from bb_basket
WHERE dtcreated < '15-FEB-03' -- AND
-- TO_CHAR(dtCreated, 'DD') = p_day
AND TO_CHAR(dtCreated, 'MON') = p_mth
AND TO_CHAR(dtcreated, 'YY') = p_yr


and orderplaced = 1

group by dtcreated;

promo_flag number; --(1);

v_cutoff DATE;


BEGIN
FOR rec_ship in cur_ship LOOP
IF rec_ship.dt < v_cutoff then
promo_flag := 1;
--END IF;

v_cutoff := to_char('15-FEB-03');

ELSIF rec_ship.dt > v_cutoff then
DBMS_OUTPUT.PUT_LINE('Dont qualify for shipping.');
END IF;
DBMS_OUTPUT.PUT_LINE(rec_ship.idshopper||' cart creation = '|| rec_ship.dt ||'
flag status = '|| promo_flag);





/* IF promo_flag IS NOT NULL THEN
insert into bb_promolist
VALUES (rec_ship.idshopper, p_mth, p_year, promo_flag, 'Y', 'APR-03');

-- END IF;

promo_flag := NULL; */



END LOOP;

--commit;



END;



ERROR I get from execution:

Procedure created.

SQL> execute promo_ship1_sp('FEB', '03');
BEGIN promo_ship1_sp('FEB', '03'); END;


ERROR at line 1:
ORA-01858: a non-numeric character was found where a numeric was expected
ORA-06512: at line 1


SQL> execute promo_ship1_sp('03', 'FEB');
BEGIN promo_ship1_sp('03', 'FEB'); END;


ERROR at line 1:
ORA-01840: input value not long enough for date format
ORA-06512: at line 1


SQL> execute promo_ship1_sp('2003', 'FEB');
BEGIN promo_ship1_sp('2003', 'FEB'); END;


ERROR at line 1:
ORA-01861: literal does not match format string
ORA-06512: at line 1
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on May 31 2007
Added on May 3 2007
13 comments
1,505 views