j**n 发帖数: 551 | 1 请问如何实现:
if a row is exist, then update it.
otherwise, insert a new row.
procedure(in argu1, in argu2)
if (select * from table1 where column1=argu1) exist // how to implement
this???
then (update table set column2=argu2 where column1=argu1)
else
insert into table set column1=argu1, column2=argu2.
多谢。 | c*****d 发帖数: 6045 | 2 在oracle里可以这样做
declare
row_cnt number;
begin
select count(*) into row_cnt from table1 where column1=argu1;
if ( row_cnt = 0 )
then
...
else
...
end if;
end; | I******e 发帖数: 101 | 3 Oracle has upsert command, like this:
MERGE INTO emp e1 USING emp_load e2 ON (e2.empno = e1.empno)
WHEN MATCHED THEN
update set e1.sal = e2.sal
WHEN NOT MATCHED THEN
insert (empno, ename, job, mgr, hiredate, sal, comm, deptno)
values (e2.empno, e2.ename, e2.job, e2.mgr, e2.hiredate, e2.sal, e2.comm,
e2.deptno); | w*r 发帖数: 2421 | 4 ever heard of ANSI upsert?
【在 c*****d 的大作中提到】 : 在oracle里可以这样做 : declare : row_cnt number; : begin : select count(*) into row_cnt from table1 where column1=argu1; : if ( row_cnt = 0 ) : then : ... : else : ...
|
|