Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 651
  • Last Modified:

oracle: insert row from main table TO client table

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
enrique_aeo
Asked:
enrique_aeo
  • 4
  • 3
  • 3
  • +2
4 Solutions
 
awking00Commented:
Can you do a describe on the tables?
0
 
enrique_aeoAuthor Commented:
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
 
johnsoneSenior Oracle DBACommented:
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
NEW Veeam Backup for Microsoft Office 365 1.5

With Office 365, it’s your data and your responsibility to protect it. NEW Veeam Backup for Microsoft Office 365 eliminates the risk of losing access to your Office 365 data.

 
enrique_aeoAuthor Commented:
my customer table already has data, I only need to insert the missing
0
 
Mark GeerlingsDatabase AdministratorCommented:
What exactly is missing, and in which table?
0
 
johnsoneSenior Oracle DBACommented:
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
 
slightwv (䄆 Netminder) Commented:
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
 
awking00Commented:
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
 
enrique_aeoAuthor Commented:
missing = records that are not in my customer table
0
 
Mark GeerlingsDatabase AdministratorCommented:
OK, so which table do they exist in, and which column values do you compare to determine they are missing?
0
 
awking00Commented:
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
 
enrique_aeoAuthor Commented:
I insert from main table to customer
 customer has less than 20rows. in the main  table there are 325 customers
0
 
slightwv (䄆 Netminder) Commented:
I believe any of the latest posts will do what you want.  What part of them are you not understanding?
0
 
Mark GeerlingsDatabase AdministratorCommented:
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

Veeam Task Manager for Hyper-V

Task Manager for Hyper-V provides critical information that allows you to monitor Hyper-V performance by displaying real-time views of CPU and memory at the individual VM-level, so you can quickly identify which VMs are using host resources.

  • 4
  • 3
  • 3
  • +2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now