开发者

how to convert the changes that I have done in a resultset to sql queries in java?

开发者 https://www.devze.com 2023-02-28 22:20 出处:网络
I am comparing 2 resultsets, and 开发者_运维百科I have to update one resultset according to the data in another. I can do this easily using updateRow (or insertrow, if required). But I also need to ge

I am comparing 2 resultsets, and 开发者_运维百科I have to update one resultset according to the data in another. I can do this easily using updateRow (or insertrow, if required). But I also need to generate sql query (preferably with oracle syntax) and add into an sql file, which gives me the option of updating that later. Can anyone tell me an elegant way of doing this?


Not exactly sure what you are looking to do, but I believe you are looking to update one table with data from another, or insert missing data into the first table when it is in the second. The easiest way to do this would be to use a merge:

merge into t1
using t2
on (t2.id = t1.id)
when matched
then
    update
    set t1.col1 = t2.col1,
        t1.col2 = t2.col2,
        t1.col3 = t2.col3
when not matched
then 
    insert
    (t1.id, t1.col1, t1.col2, t1.col3)
    values
    (t2.id, t2.col1, t2.col2, t2.col3);

It should be noted that t2 can be replaced with a select statement, in case your new data isn't already stored in a table in the correct format.

If this is not what you are looking for, can you please clarify what you mean (an example of current data and desired output would be ideal).

0

精彩评论

暂无评论...
验证码 换一张
取 消