我现在有一个需求:在数据库端对两个表进行操作,从第一张表中取数据插入第二场表,第二张表有主键,主键冲突不能成功插入,要求返回插入成功的结果集给C程序。存储过程如何写? 用OCI如何调用这个存储过程接受到返回的结果集?
解决方案 »
- 菜鸟新手刚接触LINUX和ORACLE,求解答
- 题: 比Google还牛X的面试问题
- 可能与TRIIGER有关的一个数据库问题
- emagent.exe进程句柄资源占用过高
- 同一事务中,insert后select不想取出数据,如何做?
- Oracle Internet Directory ( oracle ldap ) 高手请进
- 请问:执行DDL语句时,回滚段和临时段,回滚表空间和临时表空间,都起什么样的作用?在什么时候起作用?
- oracle8i入门问题!!请高手解决。
- 怎么看一个角色的创建者是谁?
- java通过jdbc使用oracle的一个错误,高手请进
- oracle 周的计算问题
- 有没有方法使得表在做update和delete后不提升水位?
结果集
select id,...... from table1 where id in (select id from table1 minus select id from table2)
插入语句
insert into table2(id,......)
select id,...... from table1 where id in (select id from table1 minus select id from table2)
MERGE [hint] INTO [schema .] table [t_alias] USING [schema .]
{ table | view | subquery } [t_alias] ON ( condition )
WHEN MATCHED THEN merge_update_clause
WHEN NOT MATCHED THEN merge_insert_clause;
这样就可以查如表二了;
至于删除表一中 已经取出的纪录,可以换一个思路,将表一和表二 minus 然后将结果 插入另外一个表中,然后将表一drop,将minus后的表rename为表一,孩子也也可以达到你的目的;
不知道是否解决了你的问题
--大概可以这样写,i就是insert到tabB表的记录数
create or replace procedure insertToB is
i integer := 0;
cursor cur_id is
select a.id
from tabA a
where not exists (select 1 from tabB b where a.id = b.id)
order by a.id;
begin
for line in cur_id loop
insert into tabB values (line.id);
delete tabA where id = line.id;
i := i + 1;
end loop;
end insertToB;