c#代码:我有两个oracle数据库,一个是远程的,我从我的本地oracle数据库中的表中选择值:查询返回8列:我想在具有不同列名的远程oracle表中写入数据属性:我还想确保只插入新的行值:我的远程数据库的表结构与我的选择查询返回的列不同。
来自不同表查询的select语句返回以下内容:columns:customer_name,customer_id,customer_dep_number,mobile_number,payment_amount,vehicle_model,collection_point,transaction_date
远程表的结构如下: TABLE vehicle_bought
BUYER_ID NUMBER NOT NULL,
BUYER_NAME VARCHAR2(100 BYTE)NOT NULL,
BUYER_NAT_ID VARCHAR2(25 BYTE)默认'N / A'非空,
BUYER_VEHICLE_DESCRIPTION VARCHAR2(2000 BYTE)NOT NULL,
BUYER_STATUS VARCHAR2(1 BYTE)默认'U' NOT NULL,
VEHICLE_AMOUNT NUMBER NOT NULL,
CREATED_BY NUMBER,
TRANS_CREATION_DATE DATE,
LAST_UPDATED_BY NUMBER,
LAST_UPDATE_DATE DATE,
RECEIPT_CREATED VARCHAR2(1 BYTE)DEFAULT'N',
MOBILE_NUM VARCHAR2(50 BYTE),
VEHICLE_COLLECTION_POINT VARCHAR2(100 BYTE),
RMA_FLAG VARCHAR2(1 BYTE)DEFAULT'N',
)
我想要阅读和插入的字段如下: customer_name = BUYER_NAME, customer_id = BUYER_ID
customer_dep_number = BUYER_NAT_ID
mobile_number = MOBILE_NUM
payment_amount = VEHICLE_AMOUNT
vehicle_model = BUYER_VEHICLE_DESCRIPTION
collection_point = VEHICLE_COLLECTION_POINT
transaction_date = TRANS_CREATION_DATE
非常紧急的语言c#please:纪念品答应给予任何帮助。
答案 0 :(得分:1)
快速而肮脏的解决方案:
从远程数据库(即
)跨数据库链接运行插入INSERT INTO desttable (customer_name,
customer_id,
customer_dep_number,
mobile_number, ...)
SELECT s.buyer_name,
s.buyer_id,
s.buyer_nat_id,
s.mobile_num,
...
FROM sourcetable@dblink s
WHERE NOT EXISTS (
SELECT null FROM desttable
WHERE desttable.buyer_id = s.buyer_id
);
替代方案:更好的解决方案可能会使用MERGE