Doubt in Oracle, i need to insert data into a table by selecting which query to run...?
-
I have to insert data into a table (lets call it as Table 1) by querying to get data from another table (let this be table 2). The stuffs to be done are 1. If the query condition on table 2 fails, i should run another query to insert the data into table 1. 2. If the query condition on table 2 succeeds, i should not run the other query. Which is the best way to implement this?
-
Answer:
you cannot use "Insert into table as select..." as you will not know if your select(query2) will return any rows. I suggest create a cursor for query2 so that you can test if your query2 can produce rows or not. Example algorithm: Declare cursor c_curs as select field1, field2 from table1 where condition.... c_rec c_curs%type; i integer:=0; Begin open c_curs; loop fetch c_curs into c_rec; i := i + 1; exit when c_curs%notfound; end loop; close c_curs; if i >=1 then ..... found some records.. run the other query else ..... no records found. do whatever is needed.. end if; End;
hvikrama... at Yahoo! Answers Visit the source
Related Q & A:
- How to insert data from one table to another?Best solution by Stack Overflow
- What do I need to do to become a doctor?Best solution by Yahoo! Answers
- What do I need to do to become a police officer in New Jersey?Best solution by Yahoo! Answers
- I need the average cost for a sweet sixteen for a boy.Best solution by Yahoo! Answers
- I need some help about travelling to Roland Garros stadium, which metro to take?Best solution by Yahoo! Answers
Just Added Q & A:
- How many active mobile subscribers are there in China?Best solution by Quora
- How to find the right vacation?Best solution by bookit.com
- How To Make Your Own Primer?Best solution by thekrazycouponlady.com
- How do you get the domain & range?Best solution by ChaCha
- How do you open pop up blockers?Best solution by Yahoo! Answers
For every problem there is a solution! Proved by Solucija.
-
Got an issue and looking for advice?
-
Ask Solucija to search every corner of the Web for help.
-
Get workable solutions and helpful tips in a moment.
Just ask Solucija about an issue you face and immediately get a list of ready solutions, answers and tips from other Internet users. We always provide the most suitable and complete answer to your question at the top, along with a few good alternatives below.