oracle数据库杂记(典型例子、常用)
1.-----------------左连接(m表中的记录是一定存在的,在a表中可能没有)---------
select * from mmm m,aaa a where m.member_id = a.member_id(+) and m.member_id = 'xxmguandao01'
select * from mmm m left join aaa a on m.member_id = a.member_id where m.member_id = 'xxmguandao01'
2,
从一个数据库中复制表到里一个数据据
create public database link BB_DEV_DEV
connect to 用户名
identified by 123
using '数据库连接池';
************从一个库中向另一个数据库中同步数据************************************
create table cc as select * from bb@BB_DEV;
3.(分区)分组完成后取当前组中的第二条记录
select cc.*
from (select row_number() over(partition by memo order by gmt_create desc) rno, c.*
from abc c)cc
where rno = 2
数据库中没1000条提交一次
declare
n_count integer := 0;
cursor cur_1 is select * from 源表;
begin
for icur_1 in cur_1 loop
insert into 目标表 values (icur_1.COL1,icur_1.COL2, ……icur_1.COLN);
n_count := n_count + 1;
if n_count >= 1000 then
commit;
n_count := 0;
end if;
end loop;
commit;
exception
when others then
rollback;
end;
/