小问题~!!快来~!条件删除的sql命令

hxy1982 2003-08-18 04:43:54
在吗,有2张表:a,b
操作:删除a表中time字段和b的time字段相等并且a的id字段和b的id字段相同的记录~!
delete from a where time=b.time and id=b.id 是错的?
该怎么写??快哦谢谢先
...全文
94 8 打赏 收藏 转发到动态 举报
写回复
用AI写文章
8 条回复
切换为时间正序
请发表友善的回复…
发表回复
beckhambobo 2003-08-19
  • 打赏
  • 举报
回复
create function is_int(p_time in varchar2)
return number
as
num number;
n number:=0;
begin
loop
n:=n+1;
for i in 0..9 loop
mum:=i;
if substr(p_time,1,n)=to_char(i) then
exit;
end if;
end loop;
if num=9 then
return 0;
end if;
exit when n=length(p_time);
end loop;
return 1;
end;
/
beckhambobo 2003-08-19
  • 打赏
  • 举报
回复
create function is_int(p_time in varchar2)
return number
as
num number;
n number:=0;
begin
num:=length(p_time);
loop
n:=n+1;
for i in 0..9 loop
if instr(substr(p_time,1,n),i)=0 then
return 0;
end if;
end loop;
exit when n=num;
end loop;
return 1;
end;
/

delete from a where exists(select 1 from b where id=a.id and time=a.time) and is_int(time)=0
akinggom 2003-08-18
  • 打赏
  • 举报
回复
亏了,被老beckham给枪先了!555555555555555~~~:)

delete from a where exists(select 1 from b where id=a.id and time=a.time)

向这样的条件删除语句,由于用到了全表扫描,速度会比较慢,当对一个不大的表,还可以运行运行,但当这个表很大的时候,建议最好还是写procedure.

比如说
先定义一个游标
declear
cursor vdeal_result is
select a.id from a,b where a.id=a.id and b.time=a.time
然后在进行循环的delete操作
delete from a where id = vdeal_result
虽然这样麻烦一些,但可以提高一些时间效率
beckhambobo 2003-08-18
  • 打赏
  • 举报
回复
delete from a where exists(select 1 from b where id=a.id and time=a.time)
  • 打赏
  • 举报
回复
gz
hxy1982 2003-08-18
  • 打赏
  • 举报
回复
还是a表,我要删除 time里有英文字符的记录 谢谢撒,紧急
olivertree 2003-08-18
  • 打赏
  • 举报
回复
delete from 后面只能有一张表一般。
olivertree 2003-08-18
  • 打赏
  • 举报
回复
delete from a where a.id in
(select id from b where a.time=b.time)


此处得保证a,b的时间格式一致才行。

17,377

社区成员

发帖
与我相关
我的任务
社区描述
Oracle 基础和管理
社区管理员
  • 基础和管理社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧