同一資料庫中兩個表中複製資料

2021-05-24 23:52:20 字數 1300 閱讀 7781

declare

cursor mcb_c is select * from ems_custom_broker;

mcb mcb_c%rowtype;

mcb_id number(10);

begin

begin

/*應先在id_generator表中新增id key的記錄*/

select id_value into mcb_id from id_generator where id_key='customs_broker_id';

exception

when no_data_found then

mcb_id := 1;

insert into id_generator(id_key, id_value) values('customs_broker_id', mcb_id);

commit;             

end;

begin

open mcb_c;

loop

fetch mcb_c into mcb;

exit when mcb_c%notfound;

insert into mems_customs_broker(id, code, name,

is_in_black_list, owed_payment_bill_count,

created_by, created_time,

lastupdated_by, lastupdated_time, version)

values (mcb_id, mcb.custom_code, mcb.custom_name,

case when mcb.black_status = 'y' then 1 else 0 end, 0,

mcb.create_by_actor, cast(mcb.create_datetime as timestamp),

mcb.update_by_actor, cast(mcb.update_datetime as timestamp), 0); 

/*重設customs_broker主鍵*/

mcb_id := mcb_id + 1;

end loop;

close mcb_c;

update id_generator set id_value = mcb_id where id_key='customs_broker_id_1';

dbms_output.put_line('import success');

commit;

end;

end;

MySQL 兩個資料庫表中合併資料

如果有 t1 和 t2 兩個資料庫 它們兩個對應的字段是相同的。如何將 t2 的資料插入到t1中去呢?insert into t1 select from t2 insert into domestic auction artron 2018 detail info 1 4 all select f...

資料庫兩表複製語句

1.insert into select語句 語句形式為 insert into table2 field1,field2,select value1,value2,from table1 要求目標表table2必須存在,由於目標表table2已經存在,所以我們除了插入源表table1的字段外,還可...

資料庫組合兩個表 MySQ

這個是乙個資料庫的題,於力扣 題目 表1 person 列名 型別 personid int firstname varchar lastname varchar personid是上表主鍵 表2 address 列名 型別 addressid int personid int city varch...