问题是这样的有张表test数据是这样的:
yhbh dhbh dhhm scode para
15558068809 15558068809 86063900 p A
15556061781 15556061781 86061781 p A
7XS00330402 7XS00330402 82451053 p
其中scode表示一种功能,该功能必需和另外一个功能X同时存在,所以要更新表,是表成为下面的形式:yhbh dhbh dhhm scode para
15558068809 15558068809 86063900 p A
15558068809 15558068809 86063900 X
15556061781 15556061781 86061781 p A
15556061781 15556061781 86061781 X
7XS00330402 7XS00330402 82451053 p
7XS00330402 7XS00330402 82451053 X 怎样才能实现,请帮忙看看?最好具体点,有代码可运行演示,谢谢!请做过类似处理的朋友帮个忙,看看!
yhbh dhbh dhhm scode para
15558068809 15558068809 86063900 p A
15556061781 15556061781 86061781 p A
7XS00330402 7XS00330402 82451053 p
其中scode表示一种功能,该功能必需和另外一个功能X同时存在,所以要更新表,是表成为下面的形式:yhbh dhbh dhhm scode para
15558068809 15558068809 86063900 p A
15558068809 15558068809 86063900 X
15556061781 15556061781 86061781 p A
15556061781 15556061781 86061781 X
7XS00330402 7XS00330402 82451053 p
7XS00330402 7XS00330402 82451053 X 怎样才能实现,请帮忙看看?最好具体点,有代码可运行演示,谢谢!请做过类似处理的朋友帮个忙,看看!
insert into test
select yhbh,dhbh,dhhm ,'x',null
from test
where scode='p'
union
select yhbh,dhbh,dhhm,'X',para from tab
你那种方法是不行的,你选的是多值啦!
create or replace procedure add_userxy is
v_errmsg Varchar2(300);i number:=0;
cnt number:=0;row_test test%rowtype;
cursor test_cur is select * from test;
begin
open test_cur;
loop
i:=i+1;
fetch test_cur into row_test;
exit when test_cur%notfound;
begin
select count(*) into cnt from userxy where dhhm = row_test.dhhm;
if cnt = 1 then
insert into userxy
(yhbh,
dhbh,
dhhm,
scode,
para,
,
type,
secondhm,
boundhm1,
boundhm2
)
values
(row_test.yhbh,
row_test.dhbh,
row_test.dhhm,
'X',
row_test.para,
row_test.,
row_test.type,
row_test.secondhm,
row_test.boundhm1,
row_test.boundhm2
);
end if;
commit;
Exception
When Others Then
v_errmsg :=Sqlerrm;
Insert Into userxy_err (dhhm,err_msg) Values (row_test.dhhm,v_errmsg);
Commit;
End ;
end loop;
close test_cur;
end add_userxy;
谢谢各位的帮助