oracle - how to Move data from one table to another c# -
i have 2 table named test1
, test2
want move data test1 test2 in way if condition matches update data else insert in database.i have done oracle query posted down.i have achieve 2 more tasks
**1>i have move operation in console c# application
2>i have remove leading blank spaces entries t2_fname , account_number** how can achieve task need ado.net c# code if how it
merge test2 using test1 b on (a.t2_name = b.t1_name) when matched update set a.t2_fname = b.t1_fname, a.account_number = b.account_no, when not matched insert (t2_slno,t2_name,t2_fname,account_number) values (t2_node_seq.nextval, b.t1_name,b.t1_fname,b.account_no);
you can create console application , use ado.net execute query
use
trim
function in oracle remove leading blank spaces.
here code (not tested don't have oracle db)
using system; using system.data; using system.data.oracleclient; namespace testapp { class program { static void main() { string connectionstring = "data source=thisoracleserver;integrated security=yes;"; string querystring = @"merge test2 using test1 b on (a.t2_name = b.t1_name) when matched update set a.t2_fname = trim(b.t1_fname), a.account_number = trim(b.account_no), when not matched insert (t2_slno,t2_name,t2_fname,account_number) values (t2_node_seq.nextval, b.t1_name,trim(b.t1_fname),trim(b.account_no));"; using (oracleconnection connection = new oracleconnection(connectionstring)) { using (oraclecommand command = connection.createcommand()) { command.commandtext = querystring; try { connection.open(); command.executescalar(); } catch (exception ex) { //log exception here; throw; } } } } } }
references
Comments
Post a Comment