Hello:
I've 1st set the following session level variable:
ALTER SESSION SET NLS_DATE_FORMAT = 'MM/DD/YYYY hh24:mi';
After this I wrote and sucessfully compiled this procedure:
create or replace procedure AddRental (
p_custname IN rental.custname%TYPE,
p_item_number IN rental.item_number%TYPE,
p_out_date IN rental.out_date%TYPE,
p_fee IN rental.fee%TYPE) AS
/*Defined all params above with type from table rental. Note the exclusion of in_date as this param
is not necessary...going on the premise that the business won't know when the customer will
actually return the rental.*/
BEGIN
INSERT INTO RENTAL (rental#, custname, item_number, out_date, due_date, in_date, fee)
VALUES (RentalSeq.NEXTVAL, p_custname, p_item_number, to_date(p_out_date, 'MM/DD/YYYY hh24:mi'),
next_business_date(to_date(p_out_date, 'MM/DD/YYYY')), NULL, p_fee);
DBMS_OUTPUT.PUT_LINE('Transaction occured on: ' || to_char(p_out_date, 'DAY') || ' ' || to_date(p_out_date, 'MM/DD/YYYY'));
END AddRental;
Where next_business_date is as such:
create or replace function next_business_date (D IN DATE)
RETURN DATE IS
--Function takes a date and returns the next business day.
--Declare variable to store result
v_bizdate DATE;
--Declare a variable (in CHAR format) to store passed value for string comparison
v_storedate CHAR(3);
--Begin body of function
BEGIN
--Convert and store passed value in CHAR format into v_storedate
SELECT to_char(D, 'DY')
INTO v_storedate
FROM dual;
--Take the date and check to see if it is a business day or day on the weekend.
--Test for Friday and add 3 days if this is so.
IF v_storedate = 'FRI' THEN
v_bizdate := D + 3;
--Test for Saturday and 2 days if this is so.
ELSIF v_storedate = 'SAT' THEN
v_bizdate := D + 2;
--If it not Friday or Saturday add 1 day.
ELSE
v_bizdate := D + 1;
END IF;
--Return the next business day.
RETURN v_bizdate;
END next_business_date;
And this is what I get when I execute the procedure:
[CRC] SQL> exec AddRental('Clinton', 25, '04/03/2003 14:00', 3.50);
BEGIN AddRental('Clinton', 25, '04/03/2003 14:00', 3.50); END;
*
ERROR at line 1:
ORA-01830: date format picture ends before converting entire input string
ORA-06512: at "SCM24.ADDRENTAL", line 13
ORA-06512: at line 1
Am I wrong in the proc call, or the procedure body?
I've 1st set the following session level variable:
ALTER SESSION SET NLS_DATE_FORMAT = 'MM/DD/YYYY hh24:mi';
After this I wrote and sucessfully compiled this procedure:
create or replace procedure AddRental (
p_custname IN rental.custname%TYPE,
p_item_number IN rental.item_number%TYPE,
p_out_date IN rental.out_date%TYPE,
p_fee IN rental.fee%TYPE) AS
/*Defined all params above with type from table rental. Note the exclusion of in_date as this param
is not necessary...going on the premise that the business won't know when the customer will
actually return the rental.*/
BEGIN
INSERT INTO RENTAL (rental#, custname, item_number, out_date, due_date, in_date, fee)
VALUES (RentalSeq.NEXTVAL, p_custname, p_item_number, to_date(p_out_date, 'MM/DD/YYYY hh24:mi'),
next_business_date(to_date(p_out_date, 'MM/DD/YYYY')), NULL, p_fee);
DBMS_OUTPUT.PUT_LINE('Transaction occured on: ' || to_char(p_out_date, 'DAY') || ' ' || to_date(p_out_date, 'MM/DD/YYYY'));
END AddRental;
Where next_business_date is as such:
create or replace function next_business_date (D IN DATE)
RETURN DATE IS
--Function takes a date and returns the next business day.
--Declare variable to store result
v_bizdate DATE;
--Declare a variable (in CHAR format) to store passed value for string comparison
v_storedate CHAR(3);
--Begin body of function
BEGIN
--Convert and store passed value in CHAR format into v_storedate
SELECT to_char(D, 'DY')
INTO v_storedate
FROM dual;
--Take the date and check to see if it is a business day or day on the weekend.
--Test for Friday and add 3 days if this is so.
IF v_storedate = 'FRI' THEN
v_bizdate := D + 3;
--Test for Saturday and 2 days if this is so.
ELSIF v_storedate = 'SAT' THEN
v_bizdate := D + 2;
--If it not Friday or Saturday add 1 day.
ELSE
v_bizdate := D + 1;
END IF;
--Return the next business day.
RETURN v_bizdate;
END next_business_date;
And this is what I get when I execute the procedure:
[CRC] SQL> exec AddRental('Clinton', 25, '04/03/2003 14:00', 3.50);
BEGIN AddRental('Clinton', 25, '04/03/2003 14:00', 3.50); END;
*
ERROR at line 1:
ORA-01830: date format picture ends before converting entire input string
ORA-06512: at "SCM24.ADDRENTAL", line 13
ORA-06512: at line 1
Am I wrong in the proc call, or the procedure body?