Domanda

I am using toad for oracle and I want to grab data from multiple tables and insert them into a new table.

Here is my script:

insert into mydb.testTable2 (FAO, Company, Cost_Center, Description)
select (select FAO from bigdb.wtags),
       (select DESCRIPTOR from bigdb.wtags),
       (select cost_center from bigdb.MASTERFILE),
       ''
from bigdb.wtags join bigdb.masterfile on bigdb.wtags.fao = bigdb.MASTERFILE.workday_number

I get the error:

table or view does not exist

I have been reading up on sql on www.w3schools.com and it says the insert into statement is used for creating new tables. Can I not create a new table using multiple data sources?

Also, can I combine the 2 select statements that grab from the same table into 1 line? I tried but it gave me an error: too many values and missing expression. Could that be due to another error?

È stato utile?

Soluzione

table or view does not exist means that a table or view that you've specified in your SQL does not exist in the database (or it exists, but you don't have permission to access it).

That means that one of the following does not exist:

  • mydb.testTable2
  • bigdb.wtags
  • bigdb.MASTERFILE

Aside from that, your query structure doesn't really make sense. As it is written, you are querying bigdb.wtags and bigdb.masterfile, but not using any of the results -- you are instead trying to insert from three other separate queries. I suspect you're trying to do something like:

insert into mydb.testTable2 (FAO, Company, Cost_Center, Description)
select bigdb.wtags.FAO,
       bigdb.wtags.DESCRIPTOR,
       bigdb.MASTERFILE.cost_center,
       null
  from bigdb.wtags 
       join bigdb.masterfile 
           on bigdb.wtags.fao = bigdb.MASTERFILE.workday_number

If you want to create a table as part of the insert, the syntax is slightly different:

create table mydb.testTable2 as
select bigdb.wtags.FAO,
       bigdb.wtags.DESCRIPTOR,
       bigdb.MASTERFILE.cost_center,
       null description
  from bigdb.wtags 
       join bigdb.masterfile 
           on bigdb.wtags.fao = bigdb.MASTERFILE.workday_number
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top