Oracle FAQ | Your Portal to the Oracle Knowledge Grid |
![]() |
![]() |
Home -> Community -> Usenet -> c.d.o.misc -> Re: Inserting Records Into a table
B. Williams wrote:
> "DA Morgan" <damorgan_at_psoug.org> wrote in message
> news:1157647831.249454_at_bubbleator.drizzle.com...
> > B. Williams wrote:
> >> I have created a table with two columns and one of the columns is the
> >> month and the other is the date. I want to use a pl/sql program to insert
> >> the months and dates into the table using a loop instead of using a bunch
> >> of insert statements.Will someone assist me with this? If I can get some
> >> help with January, I can figure the rest of the months out.
> >>
> >> Thanks
> >
> > Why two columns to do one column's work?
> >
> > SELECT SYSDATE, TO_CHAR(SYSDATE, 'MON'), TO_CHAR(SYSDATE, 'MM'),
> > TO_CHAR(SYSDATE, 'MONTH')
> > FROM dual;
> >
> > And using PL/SQL to do this is even more backwards.
> >
> > But assuming this is just a self-education exercise:
> >
> > CREATE TABLE t (
> > datecol DATE);
> >
> > BEGIN
> > FOR i IN 1..10 LOOP
> > INSERT INTO t
> > (datecol)
> > VALUES(SYSDATE+i);
> > END LOOP;
> > COMMIT;
> > END;
> > /
> >
> > SELECT * FROM t;
> > --
> > Daniel Morgan
> > University of Washington
> > Puget Sound Oracle Users Group
>
>
> YEAR_MONTH YEAR_DAY
> January 1
> January 2
> ...
> January 30
> January 31
> >
>
>
>> varray_name(11) := 'November';
> varray_name(1) := 'January';
> varray_name(2) := 'February';
> varray_name(3) := 'March';
> varray_name(4) := 'April';
> varray_name(5) := 'May';
> varray_name(6) := 'June';
> varray_name(7) := 'July';
> varray_name(8) := 'August';
> varray_name(9) := 'September';
> varray_name(10) := 'October';
>
>
>
>
You are on the right path. Exactly what confuses you? All you need at this point is another loop to scan thru the days, inserting each pair (month,date). I'll refrain from further hints until your next post. So try the next step and see what you get. Come back if you need more help, or if you solve it. (It is nice when the discuaaion loop can be closed.)
Ed Received on Thu Sep 07 2006 - 15:20:18 CDT
![]() |
![]() |