Oracle FAQ Your Portal to the Oracle Knowledge Grid
HOME | ASK QUESTION | ADD INFO | SEARCH | E-MAIL US
 

Home -> Community -> Usenet -> c.d.o.misc -> Re: Inserting Records Into a table

Re: Inserting Records Into a table

From: Ed Prochak <edprochak_at_gmail.com>
Date: 8 Sep 2006 11:11:32 -0700
Message-ID: <1157739092.189273.46340@m73g2000cwd.googlegroups.com>

B. Williams wrote:
> "B. Williams" <willdrama_at_hotmail.com> wrote in message
> news:yV0Mg.10111$JR5.8533_at_dukeread11...
> >
> > "Ed Prochak" <edprochak_at_gmail.com> wrote in message
> > news:1157660418.704290.80130_at_h48g2000cwc.googlegroups.com...
> >>

[]
> > I can get the loop to isert the months into the table using the following
> > code.
> >
> > FOR i IN 1..12 LOOP
> > INSERT INTO yeardates
> > (year_month)
> > VALUES(varray_name(i));
> > END LOOP;
> >
> > I can also get the loop to insert the date using a similiar loop
> >
> > FOR j IN 1..31 LOOP
> > INSERT INTO yeardates
> > (year_day)
> > VALUES(varray_date(j));
> > My problem is that I can't figure out how to get my output to display the
> > (month day) format and even more confusing is that I can't figure out
> > how to have January display 31 dates while having February displays only
> > 28 and so on.
> >
> > I need to make a loop for each month that will display that month along
> > with the days of that month.
> >
> > Can you assist me with that.
> >
> >
> >
> > This is the code I have so far.

>

> set serveroutput on size 1000000
> CREATE TABLE yeardates (year_month varchar2(20) ,year_day integer);
>

> Declare
> Type name_varray is varray(12) of varchar2(20);
> varray_name name_varray :=
> name_varray(null,null,null,null,null,null,null,null,null,null,null,null);
>

> Type date_varray is varray(31) of integer;
> varray_date date_varray :=
> date_varray(1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31);
>

> v_counter BINARY_INTEGER := 0;
>

> BEGIN
>

> 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';
> varray_name(11) := 'November';
> varray_name(12) := 'December';
>

> dbms_output.put_line( 'YEAR_MONTH' || ' ' ||'YEAY_DAY');
>
> FOR i IN 1..12 LOOP
> INSERT INTO yeardates
> (year_month)
> VALUES(varray_name(i));
> >
> FOR j IN 1..31 LOOP
> INSERT INTO yeardates
> (year_day)
> VALUES(varray_date(j));
> dbms_output.put_line( varray_name(i) || ' ' ||varray_date(j));
> v_counter := v_counter + 1;
>

> END LOOP;
> END LOOP;
> dbms_output.put_line('Total number of ' || v_counter ||' records were
> inserted.');
>
>

> END;
> /

>
> >

Hey you got it!!!!

Just ignore my other post, I obviously did not see this reply before I wrote it. Now you just need some code to handle the different month lengths (30days hath September...)

Good job.

Ed
as he slinks back into a corner,
vowing never to reply until reading all messages in a thread! 8^) Received on Fri Sep 08 2006 - 13:11:32 CDT

Original text of this message

HOME | ASK QUESTION | ADD INFO | SEARCH | E-MAIL US