This week's book giveaways are in the Refactoring and Agile forums.
We're giving away four copies each of Re-engineering Legacy Software and Docker in Action and have the authors on-line!
See this thread and this one for details.
Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Insert Query using select statement

 
Skanda Raman
Ranch Hand
Posts: 205
Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Actually i have a requirement to insert into table by selecting two columns from other table and one hard coded value is given in the query.


Here i want firstname and lastname from user table into tstore table and just id is different and hence i have hardcoded as 219 (i will loop this count so that i get different number each time using java).

Initially before putting the code to java, my sql console gives me the error as syntax error.

I am using oracle10g database.

please let me know if am doing wrong
 
Vijitha Kumara
Bartender
Posts: 3913
9
Chrome Fedora Hibernate
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
See weather INSERT INTO... SELECT helps. Syntax may be the same for Oracle too.
 
Skanda Raman
Ranch Hand
Posts: 205
Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks. The link was great.

But here i have two values to be inserted from the select statement and only one value to be given from me. Some thing like this.

insert into tstore (firstname,lastname,id)
(select firstname,lastname from user where userid='eshwar'),219

The firstname and lastname to be inserted comes from select statement and id is the number i am giving.

This gives me an error
 
Vijitha Kumara
Bartender
Posts: 3913
9
Chrome Fedora Hibernate
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Eshwar Prasad wrote:insert into tstore (firstname,lastname,id)
(select firstname,lastname from user where userid='eshwar'),219

Is this work ?
 
Skanda Raman
Ranch Hand
Posts: 205
Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Many Thanks. It worked.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic