Oracle FAQ | Your Portal to the Oracle Knowledge Grid |
Home -> Community -> Usenet -> c.d.o.misc -> Re: pl/sql help.....again
Originally posted by Clint
> hello,
>
> I have created a series of tables.......as part of that I am
> trying to
> create a pl/sql script...that will take some information from one
> table....manipulate it and insert it into another table....
>
> The calculation always equals zero...what am i doing wrong?
>
> here is my pl/sql script...
>
> DECLARE
> CURSOR c_MILEAGE_CAL IS
> SELECT EMPLO_ID, NUM_MILES, MIL_ALLOWANCE, ENTRY_DATE, DESCR
> FROM MILE_LOG;
> V_EMPLOID MILE_LOG.EMPLO_ID%TYPE :=20029;
> V_NUM_MILES MILE_LOG.NUM_MILES%TYPE;
> V_CENTSPERMILE MILE_LOG.MIL_ALLOWANCE%TYPE;
> V_DATE DATE;
> V_DESCR MILE_LOG.DESCR%TYPE;
> V_REFUND NUMBER(6);
> BEGIN
> OPEN c_MILEAGE_CAL;
> FETCH c_MILEAGE_CAL INTO
> V_EMPLOID, V_NUM_MILES, V_CENTSPERMILE, V_DATE, V_DESCR;
>
> /* I just want to calculate this simple equation*/
> V_REFUND := V_NUM_MILES * V_CENTSPERMILE;
>
> INSERT INTO EXPENSE_LOG
> VALUES(EXPLOG_COUNT_SEQ.NEXTVAL,V_EMPLOID,V_EMPLOID
> ,V_REFUND,V_DATE,
> V_DESCR, V_NUM_MILES );
> CLOSE c_MILEAGE_CAL;
> COMMIT;
> END;
If it is inserting a zero, then either or both of v_num_miles and
v_centspermile must be zero. If either were NULL the result would be
NULL. I can't see a logical error in your code that would give a zero
for any other reason.
Your code can be simplified to:
BEGIN
INSERT INTO EXPENSE_LOG
(...) -- Specify column list here
SELECT EXPLOG_COUNT_SEQ.NEXTVAL, EMPLO_ID, EMPLO_ID,
NUM_MILES*MIL_ALLOWANCE, ENTRY_DATE, DESCR, NUM_MILES
FROM MILE_LOG;
COMMIT;
END;
(You should always specify the column list in an INSERT statement).
-- Posted via http://dbforums.comReceived on Tue Apr 01 2003 - 08:04:21 CST