Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Wanet Telecoms Ltd on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Hi Iam new to oracle.How to inse

Status
Not open for further replies.

cyno

Programmer
Oct 1, 2003
90
US
Hi

Iam new to oracle.How to insert data in one table based on the status in the other table.The insert statement i use in sql server is not working in oracle.Any help is appreciated.

Cyno
 
Cyno,

Please post the pertinent columns from Tables A and B, along with your code from SQL Server, and a functional narrative that tells (in plain English) precisely what you want to do.

[santa]Mufasa
(aka Dave of Sandy, Utah, USA @ 23:51 (09Dec03) GMT, 16:51 (09Dec03) Mountain Time)
 
inssert into table a
select * from table B b,table C c where b.id=c.id;

The above query will retrieve the data based on the id's in
tables B and C and inserts all data from table B into A which satisfies the condition.

 
Cyno,

As written, your code won't work in either Oracle or SQL Server for at least a couple of reasons:

1) "inssert" must be spelled "insert" [smile].
2) The words "table" in your code are extraneous.

This code works:

insert into a
select * from B b, C c where b.id=c.id;

2 rows created.

[santa]Mufasa
(aka Dave of Sandy, Utah, USA @ 01:31 (10Dec03) GMT, 18:31 (09Dec03) Mountain Time)
 
Mufasa

If i run the above code iam getting the following error

INSERT statement's subquery yields wrong number of columns.

The table strucure for A and B are same.I want to insert data from table B into to table A based on some conditons in tables b and c.
 
Cyno,

My presumption from your code was that you needed all columns from both B and C in A. Although that seemed a bit strange to me, I presumed that you knew what you needed. If A and B have the same structure, then your code, as written certainly will not work (since if B has 8 columns and C has 12 columns, "SELECT * from B b, C c where b.id=c.id;" means that you had better have 20 columns in A.

You can specify just B columns by qualifying the "*" as:
"SELECT B.* from B b, C c where b.id=c.id;"

Let us know how that works,

[santa]Mufasa
(aka Dave of Sandy, Utah, USA @ 20:35 (11Dec03) GMT, 13:35 (11Dec03) Mountain Time)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top