How to apply media query in table?

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

Was this solution helpful to you?

Just Added Q & A:

Find solution

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.