Solved

adding values

Posted on 2014-02-08
5
192 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]
Comment Utility
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
Comment Utility
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
Comment Utility
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]
Comment Utility
sorry, my value.
replace _year, _month, etc by v_year, v_month etc ...
0
 

Author Comment

by:NiceMan331
Comment Utility
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.

Join & Write a Comment

This article started out as an Experts-Exchange question, which then grew into a quick tip to go along with an IOUG presentation for the Collaborate confernce and then later grew again into a full blown article with expanded functionality and legacy…
Subquery in Oracle: Sub queries are one of advance queries in oracle. Types of advance queries: •      Sub Queries •      Hierarchical Queries •      Set Operators Sub queries are know as the query called from another query or another subquery. It can …
This video shows how to copy a database user from one database to another user DBMS_METADATA.  It also shows how to copy a user's permissions and discusses password hash differences between Oracle 10g and 11g.
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…

743 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

19 Experts available now in Live!

Get 1:1 Help Now