由买买提看人间百态

boards

本页内容为未名空间相应帖子的节选和存档,一周内的贴子最多显示50字,超过一周显示500字 访问原贴
Database版 - 如何判断一行是否存在的问题。
相关主题
query estimation shows cost 900%?请教一个问题
Deadlock on merge (oracle)How to lock tabel with LINQ to SQL (转载)
How to merge tables in SQL Server 2000?SQL 查询已经解决.谢谢Modeler,mirthc,cheungche
How to get other columns after UNION?Common Table Expression 问题
Merge table with one single query?A Query question
Rookie's question again紧急求助, 关于SQL Server
urgent help! insert value into tableSQL add some columns into a table from another table (转载
How to handle inserting value to Identity column in sql server 2005error of executing SQL query of string concatenation (转载
相关话题的讨论汇总
话题: 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版参与讨论
相关主题
error of executing SQL query of string concatenation (转载Merge table with one single query?
error of sql query in MS Access database (转载)Rookie's question again
咋样选一个表中在另一个表中不含有的记录urgent help! insert value into table
Question for SQL statmentHow to handle inserting value to Identity column in sql server 2005
query estimation shows cost 900%?请教一个问题
Deadlock on merge (oracle)How to lock tabel with LINQ to SQL (转载)
How to merge tables in SQL Server 2000?SQL 查询已经解决.谢谢Modeler,mirthc,cheungche
How to get other columns after UNION?Common Table Expression 问题
相关话题的讨论汇总
话题: argu1话题: column1话题: argu2话题: row话题: column2