63 thumbs up

Ordinary People Discovering Extraordinary Abilities

Not So Smart Builder

Insert new row to select statement that performs a join in Oracle

Can I insert record into a select statement which performs a join between 2 tables in Oracle? I mean that the insert will be into each table.

  • 2956 views
Share Send to a friend Watch Report
 
 

Posted Answers

Order by
 
515 thumbs up

They're coming to take me away, Ha-haaa!

Advanced .NET Debugging Blog

My personal blog

If you are referring to the ability to perform a certain select and put its result into a temporary or fixed table, you can use the SELECT INTO syntax (look here for some information from Oracle's help).

If you are referring the ability to update two different tables using the same INSERT statement, technically INSERT statement can only insert data into one table. If you wish to insert data into more than one table, you'll have to use a stored procedure that will receive your parameters and will issue two INSERT statements for you. 

Does one of the two issues I've written above answer your question? 


Posted 2 years ago ( permalink )
In reply to dudushmaya's question
Rated as
#2 out of 3
0
2

Helpful?

line
line
line



 

No

 You can't do insert to 2 tables in one statement even with a join.


Posted 2 years ago ( permalink )
In reply to dudushmaya's question
talh was invited by Yedda to answer this question.

Rated as
#3 out of 3
0
0

Helpful?

line
line
line



 
4 thumbs up

Oracle 10gR2 allows multi-table inserts.  Looks like you can insert the same row (from a query) into multiple tables.

From the online documentation:

multi_table_insert

In a multitable insert, you insert computed rows derived from the rows returned from the evaluation of a subquery into one or more tables.

Table aliases are not defined by the select list of the subquery. Therefore, they are not visible in the clauses dependent on the select list. For example, this can happen when trying to refer to an object column in an expression. To use an expression with a table alias, you must put the expression into the select list with a column alias, and then refer to the column alias in the VALUES clause or WHEN condition of the multitable insert

ALL into_clause

Specify ALL followed by multiple insert_into_clauses to perform an unconditional multitable insert. Oracle Database executes each insert_into_clause once for each row returned by the subquery.

conditional_insert_clause

Specify the conditional_insert_clause to perform a conditional multitable insert. Oracle Database filters each insert_into_clause through the corresponding WHEN condition, which determines whether that insert_into_clause is executed. Each expression in the WHEN condition must refer to columns returned by the select list of the subquery. A single multitable insert statement can contain up to 127 WHEN clauses.

ALL If you specify ALL, the default value, then the database evaluates each WHEN clause regardless of the results of the evaluation of any other WHEN clause. For each WHEN clause whose condition evaluates to true, the database executes the corresponding INTO clause list.

FIRST If you specify FIRST, then the database evaluates each WHEN clause in the order in which it appears in the statement. For the first WHEN clause that evaluates to true, the database executes the corresponding INTO clause and skips subsequent WHEN clauses for the given row.

ELSE clause For a given row, if no WHEN clause evaluates to true, then:


  • If you have specified an ELSE clause, then the database executes the INTO clause list associated with the ELSE clause.

  • If you did not specify an else clause, then the database takes no action for that row.

Posted 2 years ago ( permalink )
In reply to dudushmaya's question
Rated as
Best Answer
0
4

Helpful?

line
line
line



Sign in to participate

Got an answer for dudushmaya? Would you like to comment on the posted answers, or vote for the one which you think is the best?

Sign up for a free account, or sign in (if you're already a member).

Explore Related Questions

Other people asked questions on similar topics, check out the answers they received:


How do I protect my self from sql injuction ...

How do I protect my self and my site from sql injuction?
Submitted by del2 1 year ago
  • viewed 586 times

Last answer posted 1 year ago by leonid


Explore Related Posts in Forums

  • MERGE SQL Statement

    ... as it is in Oracle * DB2 allows a SIGNAL statement, similar to RAISE * ELSE IGNORE is an optional syntax * UPDATE ... ELSE INSERT ... * MERGE with an additional error logging clause The Teradata and Oracle - more...

  • Straight SQL always put perform PL/SQL?

    ... to be updated, Oracle will pick full table scan of table test(a huge table). While in PL/SQL, "UPDATE TEST ://tkyte.blogspot.com/2006/10/slow-by-slow.html In there Tom Kytes says: * You should do it in a single SQL statement - more...

» More...

Powered by:

Omgili
Feed - Subscribe to changes to this Q&A Blog
Copyright © 2006-2008, Yedda Inc. and respective copyright owners · CC License