boards

本页内容为未名空间相应帖子的节选和存档,一周内的贴子最多显示50字,超过一周显示500字 访问原贴
Database版 - 如何判断一行是否存在的问题。
相关主题
query estimation shows cost 900%?
Deadlock on merge (oracle)
How to merge tables in SQL Server 2000?
How to get other columns after UNION?
Merge table with one single query?
Rookie's question again
urgent help! insert value into table
How to handle inserting value to Identity column in sql server 2005
请教一个问题
How to lock tabel with LINQ to SQL (转载)
相关话题的讨论汇总
话题: argu1话题: column1话题: argu2话题: row话题: column2
进入Database版参与讨论
1 (共1页)
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
: ...

1 (共1页)
进入Database版参与讨论
相关主题
How to lock tabel with LINQ to SQL (转载)
SQL 查询已经解决.谢谢Modeler,mirthc,cheungche
Common Table Expression 问题
A Query question
紧急求助, 关于SQL Server
SQL add some columns into a table from another table (转载
error of executing SQL query of string concatenation (转载
error of sql query in MS Access database (转载)
咋样选一个表中在另一个表中不含有的记录
Question for SQL statment
相关话题的讨论汇总
话题: argu1话题: column1话题: argu2话题: row话题: column2