delete语句的条件是not in +数组,如何写,谢谢!

tonghx 2009-09-01 03:26:27
我要删除表中某个字段值不在数组中的元素,请问sql语句怎么写,谢谢
DNS 是一个字符串数组
DNS.EXTEND;
DNS(1):='yy';
v_SQL:='DELETE FROM USER_INFO WHERE USER_DN NOT IN :1';
EXECUTE IMMEDIATE v_SQL USING DNS;
...全文
254 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
sxx_tt 2009-09-02
  • 打赏
  • 举报
回复
[Quote=引用 3 楼 jiaruimin11 的回复:]
请问 2楼c.extend(cn-1)是什么意思?
[/Quote]

是数组扩展为结果集的大小
jiaruimin11 2009-09-01
  • 打赏
  • 举报
回复
请问 2楼c.extend(cn-1)是什么意思?
sxx_tt 2009-09-01
  • 打赏
  • 举报
回复
declare
type array_type is varray(20) of source_table.col1%type;
c array_type := array_type(null);--c中为目标表某个字段数据集合
b array_type := array_type(null);--b中为要检索的数组,b中可以是给定的一个集合,也可以是某张表中的某个字段值的集合
cn number;
nm number;
k number := 0;
begin
select count(*) into cn from source_table;
c.extend(cn-1);
dbms_output.put_line('************c.count='||c.count);
select col1 bulk collect into c from source_table order by col1;--col1为要删除的某个字段
--当b为某个表某个字段的集合时
select count(*) into cn from recrd_table;
b.extend(cn-1);
dbms_output.put_line('************b.count='||b.count);
select col2 bulk collect into b from recrd_table order by col2;--col2为某表中某字段
dbms_output.put_line('******------------------******');
/*
当b为给定的集合时,直接在声明部分把给定的值列出即可,就不需要"当b为某个表某个字段的集合时"这部分处理了
*/
for i in 1..c.count loop
k := 0;
for j in 1..b.count loop
if c(i) = b(j) then
dbms_output.put_line('****find the record,neednot delete********');
k := 1;
exit;
end if;
end loop;
if k = 0 then
dbms_output.put_line('---delete the record where col1 is equals to '||c(i));
delete from source_table where col1 = c(i);
end if;
end loop;
end ;


inthirties 2009-09-01
  • 打赏
  • 举报
回复
用临时表,或者循环拼出sql

17,086

社区成员

发帖
与我相关
我的任务
社区描述
Oracle开发相关技术讨论
社区管理员
  • 开发
  • Lucifer三思而后行
  • 卖水果的net
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

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