I'm writing a script that will take the data in one table, and use a cursor to copy that data to another table. The reason I'm using a cursor is so that I can stagger the dates in a particular field, for testing purposes. I wrote a procedure that will manipulate the data in this table based on the date, so I'm just creating a good amount of data with staggered dates.
DECLARE
my_row CUSTOMER%ROWTYPE;
CURSOR my_cursor IS
SELECT * FROM CUSTOMER;
counter NUMBER;
BEGIN
counter := 0;
FOR my_row IN my_cursor LOOP
INSERT INTO CUSTOMER_HISTORY
(CUST_NAME, CUST_CITY, CUST_STATE, CREATE_DATE, ...)
VALUES
(my_row.CUST_NAME, my_row.CUST_CITY, my_row.CUST_STATE, TRUNC(SYSDATE - counter), ...);
counter := counter + 1;
IF (counter > 15) THEN
counter := 0;
END IF;
END LOOP;
END;
Now, this code does work, and it does what I need it to do. However, what I'd like to know is if there is an easier way. I have to do this with 3 other tables, and some of these tables have 30+ columns, and I'm hoping there's an easier way to copy all of the rows, while changing one column. If not, it's not a huge deal, but that's a lot of column names to copy.
Thanks
Edited by: jjmiller on Jul 14, 2010 1:34 PM