Solved

adding values

Posted on 2014-02-08
5
193 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
  • 3
  • 2
5 Comments
 
LVL 142

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 142

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 142

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

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

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

Suggested Solutions

Working with Network Access Control Lists in Oracle 11g (part 1) Part 2: http://www.e-e.com/A_9074.html So, you upgraded to a shiny new 11g database and all of a sudden every program that used UTL_MAIL, UTL_SMTP, UTL_TCP, UTL_HTTP or any oth…
Using SQL Scripts we can save all the SQL queries as files that we use very frequently on our database later point of time. This is one of the feature present under SQL Workshop in Oracle Application Express.
This video shows how to recover a database from a user managed backup
This video shows how to configure and send email from and Oracle database using both UTL_SMTP and UTL_MAIL, as well as comparing UTL_SMTP to a manual SMTP conversation with a mail server.

867 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

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now