Link to home
Start Free TrialLog in
Avatar of NiceMan331
NiceMan331

asked on

adding values

i have a table

month_close
year  number
month number




how to add all years in the statement

declare
y = 2015;
x = 1;
begin
loop 
y <= 2100;
loop
x <= 12;
insert into month_close (year, month, ser_start, close_flag) values (y,x,0,0);
end loop;
end loop;
end;

Open in new window


any adjustment for the above code ?
Avatar of Guy Hengel [angelIII / a3]
Guy Hengel [angelIII / a3]
Flag of Luxembourg image

pl/sql code fixed:
declare
  _year as number;
  _month as number; 
begin
  _year := 2015;
  while _year <= 2100 
  loop 
     _month := 1;
     while _month <= 12
     loop
        insert into month_close (year, month, ser_start, close_flag) values (_year,_month,0,0);
   end loop;
  end loop;
end;  

Open in new window


you could do all of this without pl/sql, btw ...
ASKER CERTIFIED SOLUTION
Avatar of Guy Hengel [angelIII / a3]
Guy Hengel [angelIII / a3]
Flag of Luxembourg image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of NiceMan331
NiceMan331

ASKER

Error report:
ORA-06550: line 2, column 3:
PLS-00103: Encountered the symbol "_" when expecting one of the following:

   begin function package pragma procedure subtype type use
   <an identifier> <a double-quoted delimited-identifier> form
   current cursor
06550. 00000 -  "line %s, column %s:\n%s"
*Cause:    Usually a PL/SQL compilation error.
*Action:
sorry, my value.
replace _year, _month, etc by v_year, v_month etc ...
great
thanx