Solved

adding values

Posted on 2014-02-08
5
196 Views
Last Modified: 2014-02-09
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 ?
0
Comment
Question by:NiceMan331
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
5 Comments
 
LVL 143

Expert Comment

by:Guy Hengel [angelIII / a3]
ID: 39845194
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 ...
0
 
LVL 143

Accepted Solution

by:
Guy Hengel [angelIII / a3] earned 500 total points
ID: 39845195
using 1 single insert:
insert into month_close (year, month, ser_start, close_flag)
with _years as ( select 2014 + level value from dual connect by 2014 + level <= 2100 )
, _months as ( select level value from dual connect by level <= 12)
select _years.value, _months.value, 0, 0
  from _years , _months 

Open in new window

0
 

Author Comment

by:NiceMan331
ID: 39845203
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:
0
 
LVL 143

Expert Comment

by:Guy Hengel [angelIII / a3]
ID: 39845205
sorry, my value.
replace _year, _month, etc by v_year, v_month etc ...
0
 

Author Comment

by:NiceMan331
ID: 39845209
great
thanx
0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Note: this article covers simple compression. Oracle introduced in version 11g release 2 a new feature called Advanced Compression which is not covered here. General principle of Oracle compression Oracle compression is a way of reducing the d…
This post first appeared at Oracleinaction  (http://oracleinaction.com/undo-and-redo-in-oracle/)by Anju Garg (Myself). I  will demonstrate that undo for DML’s is stored both in undo tablespace and online redo logs. Then, we will analyze the reaso…
This video shows, step by step, how to configure Oracle Heterogeneous Services via the Generic Gateway Agent in order to make a connection from an Oracle session and access a remote SQL Server database table.
This video shows syntax for various backup options while discussing how the different basic backup types work.  It explains how to take full backups, incremental level 0 backups, incremental level 1 backups in both differential and cumulative mode a…

738 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question