Solved

oracle: insert row from main table TO client table

Posted on 2011-02-16
14
623 Views
Last Modified: 2012-05-11
Good afternoon, I have a Main table with 225 columns.
 I have another table with 6 columns Client has 17 records.
 I need complete information in the Customer table, this information is in the Main table (also with 6 columns).
 My question is:
 as I can insert into the Customer table records missing?
0
Comment
Question by:enrique_aeo
  • 4
  • 3
  • 3
  • +2
14 Comments
 
LVL 31

Expert Comment

by:awking00
ID: 34909095
Can you do a describe on the tables?
0
 

Author Comment

by:enrique_aeo
ID: 34909264
Main table with 225 columns
but i need only this
RazonSocial
NumeroDocumento
CodTipoBanca
CodGrupo
CodCalificacionSBS
CodFeve
Rating
CodSegmentacion
CodEjecutivoNegocios
DesEjecutivoNegocios
LineaCredTienda
to insert in my customers table
0
 
LVL 34

Expert Comment

by:johnsone
ID: 34909277
Are you looking for a statement like this:

INSERT INTO CUSTOMER
SELECT COL1, COL2, COL3, COL4, COL5, COL6
FROM MAIN
WHERE...

That should do what you want, you just need to supply all the proper column names and where clause.
0
 

Author Comment

by:enrique_aeo
ID: 34909338
my customer table already has data, I only need to insert the missing
0
 
LVL 34

Expert Comment

by:Mark Geerlings
ID: 34909614
What exactly is missing, and in which table?
0
 
LVL 34

Assisted Solution

by:johnsone
johnsone earned 125 total points
ID: 34909752
The "what is missing" part would be the where clause.  How do you define "missing"?


INSERT INTO CUSTOMER C1
SELECT COL1, COL2, COL3, COL4, COL5, COL6
FROM MAIN M
WHERE NOT EXISTS (SELECT NULL FROM CUSTOMER C2 WHERE C1.COL1=C2.COL1 AND
C1.COL2=C2.COL2 AND C1.COL3=C2.COL3 AND C1.COL4 = C2.COL4 AND
C1.COL5 = C2.COL5 AND C1.COL6=C2.COL6);

However, I have no idea how you define "missing".
0
 
LVL 76

Assisted Solution

by:slightwv (䄆 Netminder)
slightwv (䄆 Netminder) earned 125 total points
ID: 34909809
I'm not sure about 'missing' either but as an alternative to the 'not exits':

insert into customer(col1, col2, col3)
select col1,col2,col3 from main
minus
select col1,col2,col3 from customer;
0
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.

 
LVL 31

Accepted Solution

by:
awking00 earned 250 total points
ID: 34909856
merge into customer c
using main m
on (c.id = m.id)  ==> use whatever is needed to determine a match
when not matched then
insert (c.col1, c.col2, c.col3, c.col4, c.col5, c.col6)
values(m.col1, m.col2, m.col3, m.col4, m.col5, m.col6);
0
 

Author Comment

by:enrique_aeo
ID: 34909962
missing = records that are not in my customer table
0
 
LVL 34

Expert Comment

by:Mark Geerlings
ID: 34909988
OK, so which table do they exist in, and which column values do you compare to determine they are missing?
0
 
LVL 31

Assisted Solution

by:awking00
awking00 earned 250 total points
ID: 34910001
That's precisely what the merge statement I showed is doing - inserting records from the main table where they don't already exist in the customer table.
0
 

Author Comment

by:enrique_aeo
ID: 34910026
I insert from main table to customer
 customer has less than 20rows. in the main  table there are 325 customers
0
 
LVL 76

Expert Comment

by:slightwv (䄆 Netminder)
ID: 34910049
I believe any of the latest posts will do what you want.  What part of them are you not understanding?
0
 
LVL 34

Expert Comment

by:Mark Geerlings
ID: 34910058
Then the examples from johnsone and slightwv should be very close to what you need.  We just don't know exactly which column(s) of those tables have to be compared to know if the record should be added, or not.
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

Suggested Solutions

Title # Comments Views Activity
Delphi selector screen 2 57
Oracle Database Upgrade 13 41
Parametric query in oracle 6 37
Outer Query not returning data - SQL HELP 16 39
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 …
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 set up a shell script to accept a positional parameter when called, pass that to a SQL script, accept the output from the statement back and then manipulate it in the Shell.
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…

708 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

15 Experts available now in Live!

Get 1:1 Help Now