关于SQL 插入数据 写一个IF语句
--insertinto"Customer"(Customer_name)values('张三')--insertinto"Customer"(Customer_name...
--insert into "Customer" (Customer_name) values ('张三')
--insert into "Customer" (Customer_name) values ('李四')
等等.....
同时运行很多这样的数据, 我想在插入前 判断,如果原表有则UPDATE,没有则 insert.
我要批量处理的,单个我知道. 展开
--insert into "Customer" (Customer_name) values ('李四')
等等.....
同时运行很多这样的数据, 我想在插入前 判断,如果原表有则UPDATE,没有则 insert.
我要批量处理的,单个我知道. 展开
3个回答
展开全部
if exits (select * from Customer where Customer_name='张三')
begin
update Customer
set Customer_name='张三'
where
end
else
insert into "Customer" (Customer_name) values ('张三')
begin
update Customer
set Customer_name='张三'
where
end
else
insert into "Customer" (Customer_name) values ('张三')
更多追问追答
追问
这个指定值的我也会, 我的意思 这个判定语句不需要输入 VALUES('') 自动检测我
--insert into "Customer" (Customer_name) values ('张三')
--insert into "Customer" (Customer_name) values ('李四')
里面有没有相同的数据
追答
这样的话你就要用促发器了
create trigger triggername on Customer
for insert
as
if exists (select t1.* from Customer t1,inserted t2 where t1.Customer_name=t2.Customer_name)
begin
update t1
set t1.Customer_name=t2.Customer_name
from Customer t1,inserted t2
where
end
else
insert into "Customer" (Customer_name)
select Customer_name from inserted
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
declare
v_num number :=0;
begin
select count(*) into v_num from Customer where xxx(条件);
if v_num>0 then
update......
else
insert......
end if;
commit;
end;
v_num number :=0;
begin
select count(*) into v_num from Customer where xxx(条件);
if v_num>0 then
update......
else
insert......
end if;
commit;
end;
追问
谢谢!
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
使用merge试试
追问
用组合写? 好试试吧,就算行,效率也很差吧
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询