Solved

ORACLE - PL/SQL traverse a set of data, to insert the data into another table

Posted on 2011-02-14
5
641 Views
Last Modified: 2012-05-11
Good afternoon, I have a PRODUCTS table in oracle with more than 10000 records. In a new design this table has been divided into 6 tables.
What I need is to get the data from the PRODUCTS table and insert new records in these 5 tables.
 I understand that I do a select on this table with some filters in the where, my question is, as it runs a data set in oracle to insert each row in the corresponding table
0
Comment
Question by:enrique_aeo
  • 2
  • 2
5 Comments
 
LVL 77

Assisted Solution

by:slightwv (䄆 Netminder)
slightwv (䄆 Netminder) earned 166 total points
ID: 34891822
10,000 isn't a lot of data.  Can you do a simple: insert into new_table1 (select columns from old_table);

for each of the new tables?
0
 

Author Comment

by:enrique_aeo
ID: 34891904
hahaha, I sincerely hope that is so, you are awesome, I look a little more the subject and I confirm. Thanks
0
 
LVL 35

Accepted Solution

by:
Mark Geerlings earned 334 total points
ID: 34891916
You could use either one (or multiple)  PL\SQL procedures (or anonymous PL\SQL blocks) for this task, or you could (more efficiently) simply use separate SQL insert commands for each of these new tables.

The SQL insert statements could look like this:

insert into new_table1
select * from old_table
where [conditions for new_table1]

insert into new_table2
select * from old_table
where [conditions for new_table2]

etc.

If you are concered with performance, you can make those inserts significantly faster by first setting each of the new tables to "nologging" like this:
alter table [new_table1] nologging;
alter table [new_table2] nologging;
etc.

Then change your insert statements to look like this:

insert /*+APPEND */ into new_table1
select * from old_table
where [conditions for new_table1]

insert /*+APPEND */ into new_table2
select * from old_table
where [conditions for new_table2]

If you use the "nologging" option, you will want to take a backup of the new tables after you load them.
0
 

Author Comment

by:enrique_aeo
ID: 34891947
ok, I know why I do it row by row, for example in the table is a column coduser products, but in the new table name to be written, in order to do this I have a function in which you step and I returned coduser name
0
 
LVL 35

Assisted Solution

by:Mark Geerlings
Mark Geerlings earned 334 total points
ID: 34892100
OK, but you could call that function either inside a PL\SQL procedure (or anonymouse block) as you process each row, or the SQL insert statements could call this function for each row as well.  The syntax for that would look more like this:

insert into new_table1
 (column1, column2, column3, etc.)
select column1, column2, function (parameters...), etc.

Remember, whatever can be done with SQL statements wil be more efficient than using those same SQL statements inside PL\SQL.
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Introduction A previously published article on Experts Exchange ("Joins in Oracle", http://www.experts-exchange.com/Database/Oracle/A_8249-Joins-in-Oracle.html) makes a statement about "Oracle proprietary" joins and mixes the join syntax with gen…
Configuring and using Oracle Database Gateway for ODBC Introduction First, a brief summary of what a Database Gateway is.  A Gateway is a set of driver agents and configurations that allow an Oracle database to communicate with other platforms…
This video explains at a high level with the mandatory Oracle Memory processes are as well as touching on some of the more common optional ones.
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.

735 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